mirror of
https://github.com/Nezumi-2711/cloudflare-gateway-pihole-scripts.git
synced 2026-09-22 13:38:37 +00:00
updated blocklist check logic to prevent adding a subdomain if a higher-level domain is already blocked
This commit is contained in:
@@ -17,6 +17,24 @@ export const sleep = (ms = 350) =>
|
||||
export const isValidDomain = (value) =>
|
||||
/^(?!-)[A-Za-z0-9-]+([\-\.]{1}[a-z0-9]+)*\.[A-Za-z]{2,6}$/.test(value);
|
||||
|
||||
/**
|
||||
* Extracts all subdomains from a domain including itself.
|
||||
* @param {string} domain The domain to be extracted.
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export const extractDomain = (domain) =>
|
||||
domain.split(".").reduce((previous, current, index, array) => {
|
||||
const nextIndex = index + 1;
|
||||
|
||||
if (nextIndex > array.length - 1) return previous;
|
||||
|
||||
const domain = [current, ...array.slice(nextIndex)].join(".");
|
||||
|
||||
previous.push(domain);
|
||||
|
||||
return previous;
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Checks if the value is a comment.
|
||||
* @param {string} value The value to be checked.
|
||||
|
||||
Reference in New Issue
Block a user