Chore: implement debugging

This commit is contained in:
SukkaW
2022-08-28 00:48:55 +08:00
parent 2e0e2e29ac
commit be1315842d

View File

@@ -3,6 +3,8 @@ const { fetch } = require('undici');
const rDomain = /^(((?!\-))(xn\-\-)?[a-z0-9\-_]{0,61}[a-z0-9]{1,1}\.)*(xn\-\-)?([a-z0-9\-]{1,61}|[a-z0-9\-]{1,30})\.[a-z]{2,}$/m
const DEBUG_DOMAIN_TO_FIND = null; // example.com | null
/**
* @param {string | URL} domainListsUrl
*/
@@ -26,7 +28,14 @@ async function processDomainLists(domainListsUrl) {
) {
return;
}
domainSets.add(line.trim());
const domainToAdd = line.trim();
if (DEBUG_DOMAIN_TO_FIND && domainToAdd.includes(DEBUG_DOMAIN_TO_FIND)) {
console.log(DEBUG_DOMAIN_TO_FIND, 'found in domain list:', domainToAdd);
}
domainSets.add(domainToAdd);
});
return [...domainSets];
@@ -54,6 +63,11 @@ async function processHosts(hostsUrl, includeAllSubDomain = false) {
}
const [, ...domains] = line.split(' ');
const domain = domains.join(' ').trim();
if (DEBUG_DOMAIN_TO_FIND && domain.includes(DEBUG_DOMAIN_TO_FIND)) {
console.log(DEBUG_DOMAIN_TO_FIND, 'found in hosts:', hostsUrl);
}
if (rDomain.test(domain)) {
if (includeAllSubDomain) {
domainSets.add(`.${domain}`);
@@ -140,6 +154,11 @@ async function processFilterRules(filterRulesUrl) {
.replaceAll('^', '')
.trim();
if (rDomain.test(domain)) {
if (DEBUG_DOMAIN_TO_FIND && domain.includes(DEBUG_DOMAIN_TO_FIND)) {
console.log(DEBUG_DOMAIN_TO_FIND, 'found in filter list:', hostsUrl);
}
blacklistDomainSets.add(`.${domain}`);
}
} else if (line.startsWith('://')
@@ -150,6 +169,11 @@ async function processFilterRules(filterRulesUrl) {
) {
const domain = `${line.replaceAll('://', '').replaceAll('^|', '').replaceAll('^', '')}`.trim();
if (rDomain.test(domain)) {
if (DEBUG_DOMAIN_TO_FIND && domain.includes(DEBUG_DOMAIN_TO_FIND)) {
console.log(DEBUG_DOMAIN_TO_FIND, 'found in filter list:', hostsUrl);
}
blacklistDomainSets.add(domain);
}
}