Skip to content

Commit 124514c

Browse files
committed
add exclusion setting for domains ( related issue - ClearURLs#353 )
1 parent deec80b commit 124514c

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

core_js/pureCleaning.js

+22
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,31 @@
2626
* @return {String} cleaned URL
2727
*/
2828
function pureCleaning(url, quiet = false) {
29+
let exclude_domains = storage.excludeDomains.split('\n');
2930
let before = url;
3031
let after = url;
3132

33+
if (exclude_domains.length > 0) {
34+
let hostname = new URL(url).hostname;
35+
for (let i = 0; i < exclude_domains.length; i++) {
36+
let domain = exclude_domains[i];
37+
38+
// if regex
39+
if (domain.startsWith('^') && domain.endsWith('$') && new RegExp(domain.slice(1, -1)).test(hostname)) {
40+
return url;
41+
}
42+
// if exclude with subdomain
43+
else if (domain.startsWith('*') && hostname.endsWith(domain.slice(1))) {
44+
return url;
45+
}
46+
// if exclude exact domain
47+
else if (hostname.split('.').length === 2 && hostname === domain) {
48+
return url;
49+
}
50+
}
51+
}
52+
53+
3254
do {
3355
before = after;
3456
after = _cleaning(before, quiet);

core_js/settings.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function save() {
8282
saveData("badged_color", pickr.getColor().toHEXA().toString())
8383
.then(() => saveData("ruleURL", document.querySelector('input[name=ruleURL]').value))
8484
.then(() => saveData("hashURL", document.querySelector('input[name=hashURL]').value))
85+
.then(() => saveData("excludeDomains", document.querySelector('textarea[name=excludeDomains]').value))
8586
.then(() => saveData("types", document.querySelector('input[name=types]').value))
8687
.then(() => saveData("logLimit", Math.max(0, Math.min(5000, document.querySelector('input[name=logLimit]').value))))
8788
.then(() => browser.runtime.sendMessage({
@@ -122,6 +123,7 @@ function getData() {
122123

123124
loadData("ruleURL")
124125
.then(() => loadData("hashURL"))
126+
.then(() => loadData("excludeDomains"))
125127
.then(() => loadData("types"))
126128
.then(() => loadData("logLimit"))
127129
.then(logData => {
@@ -177,10 +179,16 @@ async function loadData(name) {
177179
params: [name]
178180
}).then(data => {
179181
settings[name] = data.response;
180-
if (document.querySelector('input[id=' + name + ']') == null) {
182+
if(document.querySelector('textarea[id=' + name + ']')) {
183+
document.querySelector('textarea[id=' + name + ']').value = data.response;
184+
}
185+
else if (document.querySelector('input[id=' + name + ']') == null) {
181186
console.debug(name)
182187
}
183-
document.querySelector('input[id=' + name + ']').value = data.response;
188+
else{
189+
document.querySelector('input[id=' + name + ']').value = data.response;
190+
}
191+
184192
resolve(data);
185193
}, handleError);
186194
});

core_js/storage.js

+5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ function setData(key, value) {
160160
case "ruleURL":
161161
storage[key] = replaceOldURLs(value);
162162
break;
163+
case "excludeDomains":
164+
console.log(`excludeDomains: '${value}'`);
165+
storage[key] = value;
166+
break;
163167
case "types":
164168
storage[key] = value.split(',');
165169
break;
@@ -225,6 +229,7 @@ function initSettings() {
225229
storage.pingBlocking = true;
226230
storage.eTagFiltering = false;
227231
storage.watchDogErrorCount = 0;
232+
storage.excludeDomains = "";
228233

229234
if (getBrowser() === "Firefox") {
230235
storage.types = ["font", "image", "imageset", "main_frame", "media", "object", "object_subrequest", "other", "script", "stylesheet", "sub_frame", "websocket", "xml_dtd", "xmlhttprequest", "xslt"];

html/settings.html

+15-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,21 @@
104104
<label id="hash_url_label"></label><br />
105105
<input type="url" id="hashURL" value="" name="hashURL" class="form-control" />
106106
</p>
107-
<br />
107+
<p>
108+
<label for="exclude_domains_label">Excluded Domains (newline-separated or regex):</label><br />
109+
<textarea id="excludeDomains" style="height: 180px;" name="excludeDomains" class="form-control" placeholder="google.com&#10;*.withsubdomain.com&#10;^.*youtube\.com?$"></textarea>
110+
<div class="form-text text-muted">
111+
<span style="color:red">Note : it will be applied on hostname which includes domain and subdomains. nothing after <code>/</code> will be filtered.</span><br />
112+
Please specify domains you want to exclude from filtering:<br />
113+
- Use a simple domain (e.g., <code>google.com</code>) for exact matches.<br />
114+
- Use a wildcard for subdomains (e.g., <code>*.google.com</code>) to exclude all subdomains.<br />
115+
- Use regex for advanced matching (e.g., <code>^.*google\.com$</code> to match anything ending with <code>google.com</code> or <code>google.co</code> using <code>?</code> as a wildcard).<br />
116+
- For more about regex, visit <a href="https://regexone.com/">regexone.com</a>, and test your regex at <a href="https://regex101.com/">regex101.com</a> or <a href="https://www.regexr.com/">regexr.com</a>.<br />
117+
- Each entry should be on a new line.
118+
</div>
119+
</p>
120+
<br/>
121+
108122
<p>
109123
<label id="types_label"></label><br />
110124
<input type="text" id="types" value="" name="types" class="form-control" />

0 commit comments

Comments
 (0)