Surge_by_SukkaW/Build/worker/build-reject-domainset-worker.js
2021-11-29 02:47:16 +08:00

58 lines
1.2 KiB
JavaScript

exports.dedupe = ({ fullSet, input }) => {
const output = new Set();
for (const domainFromInput of input) {
for (const domainFromFullSet of fullSet) {
if (
domainFromFullSet.startsWith('.')
&& domainFromFullSet !== domainFromInput
&& (
domainFromInput.endsWith(domainFromFullSet)
|| `.${domainFromInput}` === domainFromFullSet
)
) {
output.add(domainFromInput);
break;
}
}
}
return output;
};
exports.whitelisted = ({ whiteList, input }) => {
const output = new Set();
for (const domain of input) {
for (const white of whiteList) {
if (domain.includes(white) || white.includes(domain)) {
output.add(domain);
break;
}
}
}
return output;
};
exports.dedupeKeywords = ({ keywords, suffixes, input }) => {
const output = new Set();
for (const domain of input) {
for (const keyword of keywords) {
if (domain.includes(keyword) || keyword.includes(domain)) {
output.add(domain);
break;
}
}
for (const suffix of suffixes) {
if (domain.endsWith(suffix)) {
output.add(domain);
break;
}
}
}
return output;
}