mirror of
https://github.com/Shik3i/KoalaSync.git
synced 2026-07-26 12:08:15 +00:00
23 lines
930 B
JavaScript
23 lines
930 B
JavaScript
function hostnameMatchesDomain(hostname, domain) {
|
|
const normalizedHostname = String(hostname || '').toLowerCase();
|
|
const normalizedDomain = String(domain || '').toLowerCase();
|
|
return normalizedDomain
|
|
&& (normalizedHostname === normalizedDomain
|
|
|| normalizedHostname.endsWith(`.${normalizedDomain}`));
|
|
}
|
|
|
|
export function isTabUrlFiltered(url, blacklistDomains, allowlistDomains = []) {
|
|
const urlString = String(url || '');
|
|
|
|
try {
|
|
const hostname = new URL(urlString).hostname.toLowerCase();
|
|
if (allowlistDomains.some(domain => hostnameMatchesDomain(hostname, domain))) {
|
|
return false;
|
|
}
|
|
return blacklistDomains.some(domain => hostnameMatchesDomain(hostname, domain));
|
|
} catch {
|
|
const normalizedUrl = urlString.toLowerCase();
|
|
return blacklistDomains.some(domain => normalizedUrl.includes(String(domain).toLowerCase()));
|
|
}
|
|
}
|