mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 17:20:35 +08:00
60 lines
1.4 KiB
JavaScript
60 lines
1.4 KiB
JavaScript
const { workerData } = require('piscina');
|
|
|
|
exports.dedupe = ({ chunk }) => {
|
|
const outputToBeRemoved = new Set();
|
|
|
|
for (let i = 0, l = chunk.length; i < l; i++) {
|
|
const domainFromInput = chunk[i];
|
|
for (const domainFromFullSet of workerData) {
|
|
if (domainFromFullSet === domainFromInput) continue;
|
|
if (domainFromFullSet.charAt(0) !== '.') continue;
|
|
|
|
if (
|
|
// `.${domainFromInput}` === domainFromFullSet
|
|
domainFromInput.endsWith(domainFromFullSet)
|
|
) {
|
|
outputToBeRemoved.add(domainFromInput);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return outputToBeRemoved;
|
|
};
|
|
|
|
exports.whitelisted = ({ whiteList }) => {
|
|
const outputToBeRemoved = new Set();
|
|
|
|
for (const domain of workerData) {
|
|
for (const white of whiteList) {
|
|
if (domain.includes(white) || white.includes(domain)) {
|
|
outputToBeRemoved.add(domain);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return outputToBeRemoved;
|
|
};
|
|
|
|
exports.dedupeKeywords = ({ keywords, suffixes }) => {
|
|
const outputToBeRemoved = new Set();
|
|
|
|
for (const domain of workerData) {
|
|
for (const keyword of keywords) {
|
|
if (domain.includes(keyword) || keyword.includes(domain)) {
|
|
outputToBeRemoved.add(domain);
|
|
break;
|
|
}
|
|
}
|
|
for (const suffix of suffixes) {
|
|
if (domain.endsWith(suffix)) {
|
|
outputToBeRemoved.add(domain);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return outputToBeRemoved;
|
|
}
|