adguardHomeJoiner/test.ts

65 lines
No EOL
2.6 KiB
TypeScript

const filterList = [
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/native.amazon.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/native.apple.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/native.huawei.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/native.winoffice.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/native.samsung.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/native.tiktok.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/native.tiktok.extended.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/native.lgwebos.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/native.vivo.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/native.oppo-realme.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/native.xiaomi.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/fake.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/popupads.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/tif.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/tif-ips.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/pro.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/dyndns.txt",
"https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@main/adblock/hoster.txt",
"https://big.oisd.nl"
]
const cacheFetchWorker = new Worker("./cacheFetch.ts");
const cacheFetch = async (url: string): Promise<string> => {
return new Promise((resolve, reject) => {
cacheFetchWorker.onmessage = (event) => {
resolve(event.data);
}
cacheFetchWorker.onerror = (event) => {
reject(event.error);
}
cacheFetchWorker.postMessage(url);
})
}
/*
const fetchedLists = await Promise.all(
filterList.map((filter) =>
cacheFetch(filter).then((data) =>
data
.replace(/\[Adblock Plus\]/g, "") // Remove header
.replace(/^!.*$/gm, "") // Remove comments
.trim()
.split("\n")
)
)
);*/
const fetchedLists = await Promise.all(
filterList.map(async (filter) => {
console.log("Fetching", filter);
const data = await cacheFetch(filter);
console.log("Fetched", filter);
return data
.replace(/\[Adblock Plus\]/g, "") // Remove header
.replace(/^!.*$/gm, "") // Remove comments
.trim()
.split("\n");
})
);
console.log(fetchedLists);