mirror of
https://gitlab.com/KevinRoebert/ClearUrls
synced 2025-12-18 15:15:37 +07:00
Merge branch 'whitelist' into 'master'
Draft: Whitelist See merge request ClearURLs/ClearUrls!110
This commit is contained in:
@@ -62,6 +62,34 @@ function changeStatistics()
|
||||
elTotal.textContent = totalCounter.toLocaleString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the whitelist button text
|
||||
*/
|
||||
function setWhitelistText()
|
||||
{
|
||||
let element = document.getElementById('whitelist_btn');
|
||||
let currentSite;
|
||||
browser.tabs.query({active: true, currentWindow: true}, function(tabs) {
|
||||
currentSite = tabs[0].url;
|
||||
});
|
||||
|
||||
browser.runtime.sendMessage({
|
||||
function: "getData",
|
||||
params: ['whitelist']
|
||||
}).then((data) => {
|
||||
let siteFound = data.response.some(site => currentSite.indexOf(site) !== -1);
|
||||
if (siteFound) {
|
||||
element.classList.replace('btn-primary', 'btn-danger')
|
||||
element.textContent = translate('popup_html_configs_whitelist_button_remove')
|
||||
document.getElementById('whitelist_btn').onclick = () => {changeWhitelist(true)};
|
||||
} else {
|
||||
element.classList.replace('btn-danger', 'btn-primary')
|
||||
element.textContent = translate('popup_html_configs_whitelist_button_add')
|
||||
document.getElementById('whitelist_btn').onclick = () => {changeWhitelist(false)};
|
||||
}
|
||||
}).catch(handleError);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value for the hashStatus on startUp.
|
||||
*/
|
||||
@@ -155,6 +183,36 @@ function setSwitchButton(id, varname)
|
||||
element.checked = this[varname];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds (or removes) the site the user is on to the whitelist
|
||||
* Whitelisted sites do not get filtered
|
||||
* @param {boolean} removeWl If true remove current site instead of adding
|
||||
*/
|
||||
function changeWhitelist(removeWl) {
|
||||
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 siteUrl = new URL(site)
|
||||
let domain = siteUrl.hostname
|
||||
if (removeWl) {
|
||||
data.response = data.response.filter(wlSite => wlSite !== domain)
|
||||
} else {
|
||||
data.response.push(domain)
|
||||
}
|
||||
browser.runtime.sendMessage({
|
||||
function: "setData",
|
||||
params: ['whitelist', data.response]
|
||||
}).then(() => {
|
||||
setWhitelistText();
|
||||
}).catch(handleError);
|
||||
}).catch(handleError);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the global statistic
|
||||
*/
|
||||
@@ -220,6 +278,7 @@ function setText()
|
||||
injectText('configs_switch_filter','popup_html_configs_switch_filter');
|
||||
injectText('configs_head','popup_html_configs_head');
|
||||
injectText('configs_switch_statistics','configs_switch_statistics');
|
||||
setWhitelistText();
|
||||
document.getElementById('donate').title = translate('donate_button');
|
||||
}
|
||||
|
||||
|
||||
@@ -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("whitelist", document.querySelector('input[name=whitelist]').value.split(',')))
|
||||
.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("whitelist"))
|
||||
.then(() => loadData("types"))
|
||||
.then(() => loadData("logLimit"))
|
||||
.then(logData => {
|
||||
@@ -216,6 +218,7 @@ function setText() {
|
||||
document.getElementById('reset_settings_btn').setAttribute('title', translate('setting_html_reset_button_title'));
|
||||
document.getElementById('rule_url_label').textContent = translate('setting_rule_url_label');
|
||||
document.getElementById('hash_url_label').textContent = translate('setting_hash_url_label');
|
||||
document.getElementById('whitelist_list_label').textContent = translate('setting_whitelist_list_label');
|
||||
document.getElementById('types_label').innerHTML = translate('setting_types_label');
|
||||
document.getElementById('save_settings_btn').textContent = translate('settings_html_save_button');
|
||||
document.getElementById('save_settings_btn').setAttribute('title', translate('settings_html_save_button_title'));
|
||||
|
||||
@@ -216,6 +216,7 @@ function initSettings() {
|
||||
storage.badged_color = "#ffa500";
|
||||
storage.hashURL = "https://rules2.clearurls.xyz/rules.minify.hash";
|
||||
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.historyListenerEnabled = true;
|
||||
storage.localHostsSkipping = true;
|
||||
|
||||
Reference in New Issue
Block a user