mirror of
https://gitlab.com/KevinRoebert/ClearUrls
synced 2025-12-17 22:55:36 +07:00
first commit for adding whitelist
base functionality
This commit is contained in:
@@ -87,6 +87,10 @@
|
|||||||
"message": "Show numbers of cleaned urls",
|
"message": "Show numbers of cleaned urls",
|
||||||
"description": "This string is used as title for the badges switch button on the popup page."
|
"description": "This string is used as title for the badges switch button on the popup page."
|
||||||
},
|
},
|
||||||
|
"popup_html_configs_whitelist_button": {
|
||||||
|
"message": "Whitelist Site",
|
||||||
|
"description": "This string is used as name for the whitelist button on the popup page."
|
||||||
|
},
|
||||||
"popup_html_statistics_head": {
|
"popup_html_statistics_head": {
|
||||||
"message": "Statistics",
|
"message": "Statistics",
|
||||||
"description": "This string is used as title for the statistics on the popup page."
|
"description": "This string is used as title for the statistics on the popup page."
|
||||||
|
|||||||
13
clearurls.js
13
clearurls.js
@@ -47,6 +47,19 @@ function removeFieldsFormURL(provider, pureUrl, quiet = false, request = null) {
|
|||||||
let rawRules = provider.getRawRules();
|
let rawRules = provider.getRawRules();
|
||||||
let urlObject = new URL(url);
|
let urlObject = new URL(url);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Skip whitelisted sites
|
||||||
|
*/
|
||||||
|
for (const site of storage.whitelist) {
|
||||||
|
if (url.indexOf(site) != -1) {
|
||||||
|
return {
|
||||||
|
"changes": false,
|
||||||
|
"url": url,
|
||||||
|
"cancel": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (storage.localHostsSkipping && checkLocalURL(urlObject)) {
|
if (storage.localHostsSkipping && checkLocalURL(urlObject)) {
|
||||||
return {
|
return {
|
||||||
"changes": false,
|
"changes": false,
|
||||||
|
|||||||
@@ -155,6 +155,29 @@ function setSwitchButton(id, varname)
|
|||||||
element.checked = this[varname];
|
element.checked = this[varname];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the site the user is on to the whitelist
|
||||||
|
* Whitelisted sites do not get filtered
|
||||||
|
* @param {string} site Site url to add to whitelist
|
||||||
|
*/
|
||||||
|
function addToWhitelist() {
|
||||||
|
let site;
|
||||||
|
browser.tabs.query({active: true, currentWindow: true}, function(tabs) { // Couldn't figure out how to access currentUrl var
|
||||||
|
site = tabs[0].url; // So this is used instead
|
||||||
|
});
|
||||||
|
browser.runtime.sendMessage({
|
||||||
|
function: "getData",
|
||||||
|
params: ['whitelist']
|
||||||
|
}).then((data) => {
|
||||||
|
let domain = site.replace(/.*?:(?:\/\/)?(.*?\/).*/, '$1')
|
||||||
|
data.response.push(domain)
|
||||||
|
browser.runtime.sendMessage({
|
||||||
|
function: "setData",
|
||||||
|
params: ['whitelist', data.response]
|
||||||
|
}).catch(handleError);
|
||||||
|
}).catch(handleError);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the global statistic
|
* Reset the global statistic
|
||||||
*/
|
*/
|
||||||
@@ -191,6 +214,7 @@ function resetGlobalCounter(){
|
|||||||
.then(() => loadData("getCurrentURL", "currentURL"))
|
.then(() => loadData("getCurrentURL", "currentURL"))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
init();
|
init();
|
||||||
|
document.getElementById('whitelist_btn').onclick = addToWhitelist;
|
||||||
document.getElementById('reset_counter_btn').onclick = resetGlobalCounter;
|
document.getElementById('reset_counter_btn').onclick = resetGlobalCounter;
|
||||||
changeSwitchButton("globalStatus", "globalStatus");
|
changeSwitchButton("globalStatus", "globalStatus");
|
||||||
changeSwitchButton("tabcounter", "badgedStatus");
|
changeSwitchButton("tabcounter", "badgedStatus");
|
||||||
@@ -220,6 +244,7 @@ function setText()
|
|||||||
injectText('configs_switch_filter','popup_html_configs_switch_filter');
|
injectText('configs_switch_filter','popup_html_configs_switch_filter');
|
||||||
injectText('configs_head','popup_html_configs_head');
|
injectText('configs_head','popup_html_configs_head');
|
||||||
injectText('configs_switch_statistics','configs_switch_statistics');
|
injectText('configs_switch_statistics','configs_switch_statistics');
|
||||||
|
injectText('whitelist_btn','popup_html_configs_whitelist_button');
|
||||||
document.getElementById('donate').title = translate('donate_button');
|
document.getElementById('donate').title = translate('donate_button');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -216,6 +216,7 @@ function initSettings() {
|
|||||||
storage.badged_color = "#ffa500";
|
storage.badged_color = "#ffa500";
|
||||||
storage.hashURL = "https://rules2.clearurls.xyz/rules.minify.hash";
|
storage.hashURL = "https://rules2.clearurls.xyz/rules.minify.hash";
|
||||||
storage.ruleURL = "https://rules2.clearurls.xyz/data.minify.json";
|
storage.ruleURL = "https://rules2.clearurls.xyz/data.minify.json";
|
||||||
|
storage.whitelist = []; // TODO: If we do whitelist per rule, this needs to be obj
|
||||||
storage.contextMenuEnabled = true;
|
storage.contextMenuEnabled = true;
|
||||||
storage.historyListenerEnabled = true;
|
storage.historyListenerEnabled = true;
|
||||||
storage.localHostsSkipping = true;
|
storage.localHostsSkipping = true;
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
</label>
|
</label>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
<br />
|
<br />
|
||||||
|
<button type="button" id="whitelist_btn" class="btn btn-primary btn-sm text-wrap"></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user