mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Chore: introduce eslint to build script
This commit is contained in:
@@ -17,4 +17,4 @@ module.exports.fetchRemoteTextAndCreateReadlineInterface = async (url, opt) => {
|
||||
input: Readable.fromWeb(resp.body),
|
||||
crlfDelay: Infinity
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ module.exports.normalizeDomain = (domain) => {
|
||||
|
||||
if (isIcann || isPrivate) {
|
||||
return hostname;
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ const warnOnce = (url, isWhite, ...message) => {
|
||||
}
|
||||
warnOnceUrl.add(key);
|
||||
console.warn(url, isWhite ? '(white)' : '(black)', ...message);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string | URL} domainListsUrl
|
||||
@@ -99,6 +99,9 @@ async function processHosts(hostsUrl, includeAllSubDomain = false) {
|
||||
return domainSets;
|
||||
}
|
||||
|
||||
const R_KNOWN_NOT_NETWORK_FILTER_PATTERN = /[#&%~=]/;
|
||||
const R_KNOWN_NOT_NETWORK_FILTER_PATTERN_2 = /(\$popup|\$removeparam|\$popunder)/;
|
||||
|
||||
/**
|
||||
* @param {string | URL} filterRulesUrl
|
||||
* @param {readonly (string | URL)[] | undefined} [fallbackUrls]
|
||||
@@ -130,7 +133,7 @@ async function processFilterRules(filterRulesUrl, fallbackUrls, includeThirdPart
|
||||
foundDebugDomain = true;
|
||||
}
|
||||
whitelistDomainSets.add(domainToBeAddedToWhite);
|
||||
}
|
||||
};
|
||||
|
||||
let filterRules;
|
||||
try {
|
||||
@@ -143,7 +146,7 @@ async function processFilterRules(filterRulesUrl, fallbackUrls, includeThirdPart
|
||||
)
|
||||
).split('\n').map(line => line.trim());
|
||||
} catch (e) {
|
||||
console.log('Download Rule for [' + filterRulesUrl + '] failed');
|
||||
console.log(`Download Rule for [${filterRulesUrl}] failed`);
|
||||
throw e;
|
||||
}
|
||||
|
||||
@@ -154,31 +157,34 @@ async function processFilterRules(filterRulesUrl, fallbackUrls, includeThirdPart
|
||||
|
||||
if (
|
||||
line === ''
|
||||
|| line.startsWith('/')
|
||||
|| R_KNOWN_NOT_NETWORK_FILTER_PATTERN.test(line)
|
||||
// doesn't include
|
||||
|| !line.includes('.') // rule with out dot can not be a domain
|
||||
// includes
|
||||
|| line.includes('#')
|
||||
// || line.includes('#')
|
||||
|| line.includes('!')
|
||||
|| line.includes('?')
|
||||
|| line.includes('*')
|
||||
|| line.includes('=')
|
||||
// || line.includes('=')
|
||||
|| line.includes('[')
|
||||
|| line.includes('(')
|
||||
|| line.includes(']')
|
||||
|| line.includes(')')
|
||||
|| line.includes(',')
|
||||
|| line.includes('~')
|
||||
|| line.includes('&')
|
||||
|| line.includes('%')
|
||||
// || line.includes('~')
|
||||
// || line.includes('&')
|
||||
// || line.includes('%')
|
||||
|| ((line.includes('/') || line.includes(':')) && !line.includes('://'))
|
||||
// ends with
|
||||
|| line.endsWith('.')
|
||||
|| line.endsWith('-')
|
||||
|| line.endsWith('_')
|
||||
// special modifier
|
||||
|| line.includes('$popup')
|
||||
|| line.includes('$removeparam')
|
||||
|| line.includes('$popunder')
|
||||
|| R_KNOWN_NOT_NETWORK_FILTER_PATTERN_2.test(line)
|
||||
// || line.includes('$popup')
|
||||
// || line.includes('$removeparam')
|
||||
// || line.includes('$popunder')
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
@@ -393,7 +399,7 @@ async function processFilterRules(filterRulesUrl, fallbackUrls, includeThirdPart
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string[]} data
|
||||
* @param {string[]} data
|
||||
*/
|
||||
function preprocessFullDomainSetBeforeUsedAsWorkerData(data) {
|
||||
return data
|
||||
@@ -401,7 +407,6 @@ function preprocessFullDomainSetBeforeUsedAsWorkerData(data) {
|
||||
.sort((a, b) => a.length - b.length);
|
||||
}
|
||||
|
||||
|
||||
module.exports.processDomainLists = processDomainLists;
|
||||
module.exports.processHosts = processHosts;
|
||||
module.exports.processFilterRules = processFilterRules;
|
||||
|
||||
@@ -6,7 +6,7 @@ const HOSTS = [
|
||||
['https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt', false],
|
||||
['https://raw.githubusercontent.com/jerryn70/GoodbyeAds/master/Extension/GoodbyeAds-Xiaomi-Extension.txt', false],
|
||||
['https://raw.githubusercontent.com/jdlingyu/ad-wars/master/hosts', false]
|
||||
]
|
||||
];
|
||||
|
||||
const ADGUARD_FILTERS = /** @type {const} */([
|
||||
// Easy List
|
||||
@@ -142,7 +142,7 @@ const ADGUARD_FILTERS = /** @type {const} */([
|
||||
[
|
||||
'https://curbengh.github.io/urlhaus-filter/urlhaus-filter-agh-online.txt',
|
||||
[
|
||||
'https://urlhaus-filter.pages.dev/urlhaus-filter-agh-online.txt',
|
||||
'https://urlhaus-filter.pages.dev/urlhaus-filter-agh-online.txt'
|
||||
// Prefer mirror, since malware-filter.gitlab.io has not been updated for a while
|
||||
// 'https://malware-filter.gitlab.io/urlhaus-filter/urlhaus-filter-agh-online.txt'
|
||||
],
|
||||
@@ -152,7 +152,7 @@ const ADGUARD_FILTERS = /** @type {const} */([
|
||||
[
|
||||
'https://curbengh.github.io/phishing-filter/phishing-filter-agh.txt',
|
||||
[
|
||||
'https://phishing-filter.pages.dev/phishing-filter-agh.txt',
|
||||
'https://phishing-filter.pages.dev/phishing-filter-agh.txt'
|
||||
// Prefer mirror, since malware-filter.gitlab.io has not been updated for a while
|
||||
// 'https://malware-filter.gitlab.io/malware-filter/phishing-filter-agh.txt'
|
||||
],
|
||||
@@ -162,7 +162,7 @@ const ADGUARD_FILTERS = /** @type {const} */([
|
||||
[
|
||||
'https://curbengh.github.io/pup-filter/pup-filter-agh.txt',
|
||||
[
|
||||
'https://pup-filter.pages.dev/pup-filter-agh.txt',
|
||||
'https://pup-filter.pages.dev/pup-filter-agh.txt'
|
||||
// Prefer mirror, since malware-filter.gitlab.io has not been updated for a while
|
||||
// 'https://malware-filter.gitlab.io/malware-filter/pup-filter-agh.txt'
|
||||
],
|
||||
@@ -241,7 +241,7 @@ const PREDEFINED_ENFORCED_WHITELIST = [
|
||||
'repl.co',
|
||||
'w3s.link',
|
||||
'translate.goog'
|
||||
]
|
||||
];
|
||||
|
||||
module.exports.HOSTS = HOSTS;
|
||||
module.exports.ADGUARD_FILTERS = ADGUARD_FILTERS;
|
||||
|
||||
@@ -13,7 +13,7 @@ async function compareAndWriteFile(linesA, filePath) {
|
||||
filePath,
|
||||
linesA.join('\n'),
|
||||
{ encoding: 'utf-8' }
|
||||
)
|
||||
);
|
||||
} else {
|
||||
console.log(`Same Content, bail out writing: ${filePath}`);
|
||||
}
|
||||
@@ -23,7 +23,7 @@ async function compareAndWriteFile(linesA, filePath) {
|
||||
* @param {string[]} linesA
|
||||
* @param {string[]} linesB
|
||||
*/
|
||||
function stringArrayCompare (linesA, linesB) {
|
||||
function stringArrayCompare(linesA, linesB) {
|
||||
if (linesA.length !== linesB.length) return false;
|
||||
|
||||
for (let i = 0; i < linesA.length; i++) {
|
||||
|
||||
@@ -31,6 +31,24 @@ class Trie {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} suffix
|
||||
*/
|
||||
contains(suffix) {
|
||||
let node = this.root;
|
||||
let token;
|
||||
|
||||
for (let i = suffix.length - 1; i >= 0; i--) {
|
||||
token = suffix[i];
|
||||
|
||||
node = node[token];
|
||||
|
||||
if (node == null) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to retrieve every item in the trie with the given prefix.
|
||||
*
|
||||
@@ -42,8 +60,6 @@ class Trie {
|
||||
let node = this.root;
|
||||
const matches = [];
|
||||
let token;
|
||||
let i;
|
||||
let l;
|
||||
|
||||
for (let i = suffix.length - 1; i >= 0; i--) {
|
||||
token = suffix[i];
|
||||
|
||||
Reference in New Issue
Block a user