diff --git a/core_js/pureCleaning.js b/core_js/pureCleaning.js index d26a6a2..6c81485 100644 --- a/core_js/pureCleaning.js +++ b/core_js/pureCleaning.js @@ -26,9 +26,24 @@ * @return {String} cleaned URL */ function pureCleaning(url, quiet = false) { + let exclude_domains = storage.excludeDomains.split('\n'); let before = url; let after = url; + if (exclude_domains.length > 0) { + let hostname = new URL(url).hostname; + for (const domain of exclude_domains) { + let isRegexMatch = domain.startsWith('^') && domain.endsWith('$') && new RegExp(domain.slice(1, -1)).test(hostname) + let isSubdomainExcludeMatch = domain.startsWith('*') && hostname.endsWith(domain.slice(1)) + let isExactDomainExcludeMatch = hostname.split('.').length === 2 && hostname === domain + + if (isRegexMatch || isSubdomainExcludeMatch || isExactDomainExcludeMatch) { + return url + } + } + } + + do { before = after; after = _cleaning(before, quiet); diff --git a/core_js/settings.js b/core_js/settings.js index 3e6162d..cf066b2 100644 --- a/core_js/settings.js +++ b/core_js/settings.js @@ -82,6 +82,7 @@ function save() { saveData("badged_color", pickr.getColor().toHEXA().toString()) .then(() => saveData("ruleURL", document.querySelector('input[name=ruleURL]').value)) .then(() => saveData("hashURL", document.querySelector('input[name=hashURL]').value)) + .then(() => saveData("excludeDomains", document.querySelector('textarea[name=excludeDomains]').value)) .then(() => saveData("types", document.querySelector('input[name=types]').value)) .then(() => saveData("logLimit", Math.max(0, Math.min(5000, document.querySelector('input[name=logLimit]').value)))) .then(() => browser.runtime.sendMessage({ @@ -122,6 +123,7 @@ function getData() { loadData("ruleURL") .then(() => loadData("hashURL")) + .then(() => loadData("excludeDomains")) .then(() => loadData("types")) .then(() => loadData("logLimit")) .then(logData => { @@ -177,10 +179,16 @@ async function loadData(name) { params: [name] }).then(data => { settings[name] = data.response; - if (document.querySelector('input[id=' + name + ']') == null) { + if(document.querySelector('textarea[id=' + name + ']')) { + document.querySelector('textarea[id=' + name + ']').value = data.response; + } + else if (document.querySelector('input[id=' + name + ']') == null) { console.debug(name) } - document.querySelector('input[id=' + name + ']').value = data.response; + else{ + document.querySelector('input[id=' + name + ']').value = data.response; + } + resolve(data); }, handleError); }); diff --git a/core_js/storage.js b/core_js/storage.js index ccfb980..72f88c3 100644 --- a/core_js/storage.js +++ b/core_js/storage.js @@ -20,7 +20,7 @@ /* * This script is responsible for the storage. */ -var storage = []; +var storage = {}; var hasPendingSaves = false; var pendingSaves = new Set(); @@ -77,7 +77,7 @@ function deleteFromDisk(key) { function saveOnDisk(keys) { let json = {}; - keys.forEach(function (key) { + keys.forEach(function(key) { json[key] = storageDataAsString(key); }); @@ -95,7 +95,7 @@ function deferSaveOnDisk(key) { return; } - setTimeout(function () { + setTimeout(function() { saveOnDisk(Array.from(pendingSaves)); pendingSaves.clear(); hasPendingSaves = false; @@ -160,6 +160,9 @@ function setData(key, value) { case "ruleURL": storage[key] = replaceOldURLs(value); break; + case "excludeDomains": + storage[key] = value; + break; case "types": storage[key] = value.split(','); break; @@ -211,7 +214,7 @@ function initSettings() { storage.cleanedCounter = 0; storage.hashStatus = "error"; storage.loggingStatus = false; - storage.log = {"log": []}; + storage.log = { "log": [] }; storage.statisticsStatus = true; storage.badged_color = "#ffa500"; storage.hashURL = "https://rules2.clearurls.xyz/rules.minify.hash"; @@ -225,6 +228,7 @@ function initSettings() { storage.pingBlocking = true; storage.eTagFiltering = false; storage.watchDogErrorCount = 0; + storage.excludeDomains = ""; if (getBrowser() === "Firefox") { storage.types = ["font", "image", "imageset", "main_frame", "media", "object", "object_subrequest", "other", "script", "stylesheet", "sub_frame", "websocket", "xml_dtd", "xmlhttprequest", "xslt"]; diff --git a/html/settings.html b/html/settings.html index f28ded9..91d957d 100644 --- a/html/settings.html +++ b/html/settings.html @@ -104,7 +104,21 @@

-
+

+
+ +

+ Note : it will be applied on hostname which includes domain and subdomains. nothing after / will be filtered.
+ Please specify domains you want to exclude from filtering:
+ - Use a simple domain (e.g., google.com) for exact matches.
+ - Use a wildcard for subdomains (e.g., *.google.com) to exclude all subdomains.
+ - Use regex for advanced matching (e.g., ^.*google\.com?$ to match anything ending with google.com or google.co using ? as a wildcard).
+ - For more about regex, visit regexone.com, and test your regex at regex101.com or regexr.com.
+ - Each entry should be on a new line. +
+

+
+