Files
KoalaSync/extension/tab-filter.js
T

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()));
}
}