mirror of
https://github.com/Nezumi-2711/cloudflare-gateway-pihole-scripts.git
synced 2026-09-22 13:38:37 +00:00
added code comments
This commit is contained in:
@@ -55,22 +55,32 @@ await readFile(resolve(blocklistFilename), (line, rl) => {
|
|||||||
|
|
||||||
if (!_line) return;
|
if (!_line) return;
|
||||||
|
|
||||||
|
// Check if the current line is a comment in any format
|
||||||
if (isComment(_line)) return;
|
if (isComment(_line)) return;
|
||||||
|
|
||||||
|
// Remove prefixes and suffixes in hosts, wildcard or adblock format
|
||||||
const domain = normalizeDomain(_line);
|
const domain = normalizeDomain(_line);
|
||||||
|
|
||||||
|
// Check if it is a valid domain which is not a URL or does not contain
|
||||||
|
// characters like * in the middle of the domain
|
||||||
if (!isValidDomain(domain)) return;
|
if (!isValidDomain(domain)) return;
|
||||||
|
|
||||||
processedDomainCount++;
|
processedDomainCount++;
|
||||||
|
|
||||||
|
// Get all the levels of the domain and check from the highest
|
||||||
|
// because we are blocking all subdomains
|
||||||
|
// Example: fourth.third.example.com => ["example.com", "third.example.com", "fourth.third.example.com"]
|
||||||
const anyDomainExists = extractDomain(domain)
|
const anyDomainExists = extractDomain(domain)
|
||||||
.reverse()
|
.reverse()
|
||||||
.some((item) => {
|
.some((item) => {
|
||||||
if (blocklist.has(item)) {
|
if (blocklist.has(item)) {
|
||||||
if (item === domain) {
|
if (item === domain) {
|
||||||
|
// The exact domain is already blocked
|
||||||
console.log(`Found ${item} in blocklist already - Skipping`);
|
console.log(`Found ${item} in blocklist already - Skipping`);
|
||||||
duplicateDomainCount++;
|
duplicateDomainCount++;
|
||||||
} else {
|
} else {
|
||||||
|
// The higher-level domain is already blocked
|
||||||
|
// so it's not necessary to block this domain
|
||||||
console.log(
|
console.log(
|
||||||
`Found ${item} in blocklist already - Skipping ${domain}`
|
`Found ${item} in blocklist already - Skipping ${domain}`
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user