mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-13 01:30:37 +08:00
Chore: also fetch EasyList & EasyPrivacy from fallback server
This commit is contained in:
parent
cd785a7ab8
commit
d5f0f2428f
@ -85,7 +85,13 @@ const threads = isCI ? cpuCount : cpuCount / 2;
|
|||||||
|
|
||||||
(await Promise.all([
|
(await Promise.all([
|
||||||
// Easy List
|
// Easy List
|
||||||
|
[
|
||||||
'https://easylist.to/easylist/easylist.txt',
|
'https://easylist.to/easylist/easylist.txt',
|
||||||
|
[
|
||||||
|
'https://easylist-downloads.adblockplus.org/easylist.txt',
|
||||||
|
'https://secure.fanboy.co.nz/easylist.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
// AdGuard DNS Filter
|
// AdGuard DNS Filter
|
||||||
'https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt',
|
'https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt',
|
||||||
// uBlock Origin Filter List
|
// uBlock Origin Filter List
|
||||||
@ -112,7 +118,13 @@ const threads = isCI ? cpuCount : cpuCount / 2;
|
|||||||
// AdGuard Chinese filter (EasyList China + AdGuard Chinese filter)
|
// AdGuard Chinese filter (EasyList China + AdGuard Chinese filter)
|
||||||
'https://filters.adtidy.org/extension/ublock/filters/224.txt',
|
'https://filters.adtidy.org/extension/ublock/filters/224.txt',
|
||||||
// Easy Privacy
|
// Easy Privacy
|
||||||
|
[
|
||||||
'https://easylist.to/easylist/easyprivacy.txt',
|
'https://easylist.to/easylist/easyprivacy.txt',
|
||||||
|
[
|
||||||
|
'https://secure.fanboy.co.nz/easyprivacy.txt',
|
||||||
|
'https://easylist-downloads.adblockplus.org/easyprivacy.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
// Curben's Malware Online UrlHaus
|
// Curben's Malware Online UrlHaus
|
||||||
'https://malware-filter.gitlab.io/malware-filter/urlhaus-filter-agh-online.txt',
|
'https://malware-filter.gitlab.io/malware-filter/urlhaus-filter-agh-online.txt',
|
||||||
// Curben's Phishing Online Filter
|
// Curben's Phishing Online Filter
|
||||||
@ -123,7 +135,14 @@ const threads = isCI ? cpuCount : cpuCount / 2;
|
|||||||
'https://raw.githubusercontent.com/DandelionSprout/adfilt/master/GameConsoleAdblockList.txt',
|
'https://raw.githubusercontent.com/DandelionSprout/adfilt/master/GameConsoleAdblockList.txt',
|
||||||
// PiHoleBlocklist
|
// PiHoleBlocklist
|
||||||
'https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/SmartTV-AGH.txt',
|
'https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/SmartTV-AGH.txt',
|
||||||
].map(processFilterRules))).forEach(({ white, black }) => {
|
].map(input => {
|
||||||
|
if (typeof input === 'string') {
|
||||||
|
return processFilterRules(input);
|
||||||
|
}
|
||||||
|
if (Array.isArray(input) && input.length === 2) {
|
||||||
|
return processFilterRules(input[0], input[1]);
|
||||||
|
}
|
||||||
|
}))).forEach(({ white, black }) => {
|
||||||
white.forEach(i => filterRuleWhitelistDomainSets.add(i));
|
white.forEach(i => filterRuleWhitelistDomainSets.add(i));
|
||||||
black.forEach(i => domainSets.add(i));
|
black.forEach(i => domainSets.add(i));
|
||||||
});
|
});
|
||||||
|
|||||||
@ -92,9 +92,12 @@ async function processHosts (hostsUrl, includeAllSubDomain = false) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string | URL} filterRulesUrl
|
* @param {string | URL} filterRulesUrl
|
||||||
|
* @param {(string | URL)[] | undefined} fallbackUrls
|
||||||
* @returns {Promise<{ white: Set<string>, black: Set<string> }>}
|
* @returns {Promise<{ white: Set<string>, black: Set<string> }>}
|
||||||
*/
|
*/
|
||||||
async function processFilterRules (filterRulesUrl) {
|
async function processFilterRules (filterRulesUrl, fallbackUrls) {
|
||||||
|
console.time(`processFilterRules: ${filterRulesUrl}`);
|
||||||
|
|
||||||
if (typeof filterRulesUrl === 'string') {
|
if (typeof filterRulesUrl === 'string') {
|
||||||
filterRulesUrl = new URL(filterRulesUrl);
|
filterRulesUrl = new URL(filterRulesUrl);
|
||||||
}
|
}
|
||||||
@ -105,7 +108,13 @@ async function processFilterRules (filterRulesUrl) {
|
|||||||
const blacklistDomainSets = new Set();
|
const blacklistDomainSets = new Set();
|
||||||
|
|
||||||
/** @type string[] */
|
/** @type string[] */
|
||||||
const filterRules = (await (await fetchWithRetry(filterRulesUrl)).text()).split('\n').map(line => line.trim());
|
const filterRules = (
|
||||||
|
await Promise.any(
|
||||||
|
[filterRulesUrl, ...(fallbackUrls || [])].map(
|
||||||
|
async url => (await fetchWithRetry(url)).text()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).split('\n').map(line => line.trim());
|
||||||
|
|
||||||
filterRules.forEach(line => {
|
filterRules.forEach(line => {
|
||||||
const lineStartsWithDoubleVerticalBar = line.startsWith('||');
|
const lineStartsWithDoubleVerticalBar = line.startsWith('||');
|
||||||
@ -197,6 +206,8 @@ async function processFilterRules (filterRulesUrl) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.timeEnd(`processFilterRules: ${filterRulesUrl}`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
white: whitelistDomainSets,
|
white: whitelistDomainSets,
|
||||||
black: blacklistDomainSets
|
black: blacklistDomainSets
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user