Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add exclusion setting for domains ( related issue #353 ) #383

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions core_js/pureCleaning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions core_js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -122,6 +123,7 @@ function getData() {

loadData("ruleURL")
.then(() => loadData("hashURL"))
.then(() => loadData("excludeDomains"))
.then(() => loadData("types"))
.then(() => loadData("logLimit"))
.then(logData => {
Expand Down Expand Up @@ -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);
});
Expand Down
12 changes: 8 additions & 4 deletions core_js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/*
* This script is responsible for the storage.
*/
var storage = [];
var storage = {};
var hasPendingSaves = false;
var pendingSaves = new Set();

Expand Down Expand Up @@ -77,7 +77,7 @@ function deleteFromDisk(key) {
function saveOnDisk(keys) {
let json = {};

keys.forEach(function (key) {
keys.forEach(function(key) {
json[key] = storageDataAsString(key);
});

Expand All @@ -95,7 +95,7 @@ function deferSaveOnDisk(key) {
return;
}

setTimeout(function () {
setTimeout(function() {
saveOnDisk(Array.from(pendingSaves));
pendingSaves.clear();
hasPendingSaves = false;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -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"];
Expand Down
16 changes: 15 additions & 1 deletion html/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,21 @@
<label id="hash_url_label"></label><br />
<input type="url" id="hashURL" value="" name="hashURL" class="form-control" />
</p>
<br />
<p>
<label for="exclude_domains_label">Excluded Domains (newline-separated or regex):</label><br />
<textarea id="excludeDomains" style="height: 180px;" name="excludeDomains" class="form-control" placeholder="google.com&#10;*.withsubdomain.com&#10;^.*youtube\.com?$"></textarea>
<div class="form-text text-muted">
<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 />
Please specify domains you want to exclude from filtering:<br />
- Use a simple domain (e.g., <code>google.com</code>) for exact matches.<br />
- Use a wildcard for subdomains (e.g., <code>*.google.com</code>) to exclude all subdomains.<br />
- 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 />
- 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 />
- Each entry should be on a new line.
</div>
</p>
<br/>

<p>
<label id="types_label"></label><br />
<input type="text" id="types" value="" name="types" class="form-control" />
Expand Down