Skip to content
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
34 changes: 33 additions & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,38 @@
"message": "Open the log",
"description": "This string is used as title for the log button on the popup page."
},
"popup_html_site_head": {
"message": "Site",
"description": "This string is used as title for the current site section on the popup page."
},
"popup_html_site_disable": {
"message": "Disable on this site",
"description": "This string is used as label for disabling ClearURLs on the current site."
},
"popup_html_site_disable_title": {
"message": "Disable ClearURLs on the current site",
"description": "This string is used as title for the current-site disable button."
},
"popup_html_site_enable": {
"message": "Enable on this site",
"description": "This string is used as label for enabling ClearURLs on the current site."
},
"popup_html_site_enable_title": {
"message": "Enable ClearURLs again on the current site",
"description": "This string is used as title for the current-site enable button."
},
"popup_html_site_enabled": {
"message": "ClearURLs is active on $1",
"description": "This string is used to show that ClearURLs is active on the current site."
},
"popup_html_site_disabled": {
"message": "ClearURLs is disabled on $1",
"description": "This string is used to show that ClearURLs is disabled on the current site."
},
"popup_html_site_unavailable": {
"message": "This page does not have a normal site hostname.",
"description": "This string is used when the current tab does not expose a normal site hostname."
},
"popup_html_report_button": {
"message": "Report current URL",
"description": "Note: Currently not used."
Expand Down Expand Up @@ -375,4 +407,4 @@
"message": " ",
"description": "not needed, only to prevent exceptions"
}
}
}
4 changes: 4 additions & 0 deletions clearurls.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
if (fields.toString() !== "") finalURL += "?" + urlSearchParamsToString(fields);
if (fragments.toString() !== "") finalURL += "#" + fragments.toString();

url = finalURL.replace(new RegExp("\\?&"), "?").replace(new RegExp("#&"), "#");

Check warning on line 158 in clearurls.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

`String.raw` should be used to avoid escaping `\`.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdY35i6orNl3BkQs&open=AZ5VEdY35i6orNl3BkQs&pullRequest=516
}


Expand All @@ -172,7 +172,7 @@
*
* @param {object} obj
*/
function getKeys(obj) {

Check warning on line 175 in clearurls.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move function 'getKeys' to the outer scope.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdY35i6orNl3BkQt&open=AZ5VEdY35i6orNl3BkQt&pullRequest=516
for (const key in obj) {
prvKeys.push(key);
}
Expand Down Expand Up @@ -245,7 +245,7 @@
/**
* Deactivates ClearURLs, if no rules can be downloaded and also no old rules in storage
*/
function deactivateOnFailure() {

Check warning on line 248 in clearurls.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move function 'deactivateOnFailure' to the outer scope.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdY35i6orNl3BkQu&open=AZ5VEdY35i6orNl3BkQu&pullRequest=516
if (storage.ClearURLsData.length === 0) {
storage.globalStatus = false;
storage.dataHash = "";
Expand Down Expand Up @@ -274,7 +274,7 @@
if (result.status === 200 && result.hash) {
dataHash = result.hash;

if (dataHash !== localDataHash.trim()) {

Check warning on line 277 in clearurls.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdY35i6orNl3BkQv&open=AZ5VEdY35i6orNl3BkQv&pullRequest=516
fetchFromURL();
} else {
toObject(storage.ClearURLsData);
Expand Down Expand Up @@ -342,7 +342,7 @@
* @param {boolean} _forceRedirection Whether redirects should be enforced via a "tabs.update"
* @param {boolean} _isActive Is the provider active?
*/
function Provider(_name, _completeProvider = false, _forceRedirection = false, _isActive = true) {

Check warning on line 345 in clearurls.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move function 'Provider' to the outer scope.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdY35i6orNl3BkQw&open=AZ5VEdY35i6orNl3BkQw&pullRequest=516
let name = _name;
let urlPattern;
let enabled_rules = {};
Expand Down Expand Up @@ -512,7 +512,7 @@
* @param {String} method HTTP Method Name
*/
this.addMethod = function (method) {
if (methods.indexOf(method) === -1) {

Check warning on line 515 in clearurls.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use `.includes()`, rather than `.indexOf()`, when checking for existence.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdY35i6orNl3BkQx&open=AZ5VEdY35i6orNl3BkQx&pullRequest=516
methods.push(method);
}
}
Expand All @@ -525,7 +525,7 @@
*/
this.matchMethod = function (details) {
if (!methods.length) return true;
return methods.indexOf(details['method']) > -1;

Check warning on line 528 in clearurls.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use `.includes()`, rather than `.indexOf()`, when checking for existence.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdY35i6orNl3BkQy&open=AZ5VEdY35i6orNl3BkQy&pullRequest=516
}

/**
Expand Down Expand Up @@ -606,6 +606,10 @@
* @return {Array} redirectUrl or none
*/
function clearUrl(request) {
if (isURLDisabled(getRequestContextURL(request))) {
return {};
}

const URLbeforeReplaceCount = countFields(request.url);

//Add Fields form Request to global url counter
Expand Down Expand Up @@ -710,7 +714,7 @@
* @type {requestDetails}
* @return {boolean}
*/
function isDataURL(requestDetails) {

Check warning on line 717 in clearurls.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move function 'isDataURL' to the outer scope.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdY35i6orNl3BkQz&open=AZ5VEdY35i6orNl3BkQz&pullRequest=516
const s = requestDetails.url;

return s.substring(0, 4) === "data";
Expand Down
2 changes: 1 addition & 1 deletion core_js/historyListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function historyListenerStart() {
* which is associated with the new history entry created by replaceState()
*/
function historyCleaner(details) {
if(storage.globalStatus) {
if(storage.globalStatus && !isURLDisabled(details.url)) {
const urlBefore = details.url;
const urlAfter = pureCleaning(details.url);

Expand Down
87 changes: 84 additions & 3 deletions core_js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
var loggingStatus;
var statisticsStatus;
var currentURL;
var disabledDomains = [];

Check failure on line 34 in core_js/popup.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdXr5i6orNl3BkQi&open=AZ5VEdXr5i6orNl3BkQi&pullRequest=516
var currentHostname = "";

Check failure on line 35 in core_js/popup.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdXr5i6orNl3BkQj&open=AZ5VEdXr5i6orNl3BkQj&pullRequest=516
var siteSwitchButton = document.getElementById('siteSwitchButton');

Check failure on line 36 in core_js/popup.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdXr5i6orNl3BkQk&open=AZ5VEdXr5i6orNl3BkQk&pullRequest=516
var siteStatus = document.getElementById('siteStatus');

Check failure on line 37 in core_js/popup.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdXr5i6orNl3BkQl&open=AZ5VEdXr5i6orNl3BkQl&pullRequest=516

/**
* Initialize the UI.
Expand All @@ -44,6 +48,7 @@
setSwitchButton("statistics", "statisticsStatus");
setHashStatus();
changeStatistics();
updateSiteSection();
}

/**
Expand All @@ -53,7 +58,7 @@
{
globalPercentage = ((cleanedCounter/totalCounter)*100).toFixed(3);

if(isNaN(Number(globalPercentage))) globalPercentage = 0;

Check warning on line 61 in core_js/popup.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `Number.isNaN` over `isNaN`.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdXr5i6orNl3BkQm&open=AZ5VEdXr5i6orNl3BkQm&pullRequest=516

element.textContent = cleanedCounter.toLocaleString();
elGlobalPercentage.textContent = globalPercentage+"%";
Expand Down Expand Up @@ -180,6 +185,78 @@
changeStatistics();
}

function updateSiteSection() {
if (!siteSwitchButton || !siteStatus) {
return;
}

const siteDisabled = disabledDomains.includes(currentHostname);

if (!currentHostname) {
siteStatus.textContent = translate('popup_html_site_unavailable');
siteSwitchButton.disabled = true;
siteSwitchButton.textContent = translate('popup_html_site_disable');
siteSwitchButton.removeAttribute('title');
return;
}

siteSwitchButton.disabled = false;

if (siteDisabled) {
siteStatus.textContent = translate('popup_html_site_disabled', currentHostname);
siteSwitchButton.textContent = translate('popup_html_site_enable');
siteSwitchButton.setAttribute('title', translate('popup_html_site_enable_title'));
} else {
siteStatus.textContent = translate('popup_html_site_enabled', currentHostname);
siteSwitchButton.textContent = translate('popup_html_site_disable');
siteSwitchButton.setAttribute('title', translate('popup_html_site_disable_title'));
}
}

function toggleCurrentSite() {
if (!currentHostname) {
return;
}

const siteDisabled = disabledDomains.includes(currentHostname);

browser.runtime.sendMessage({
function: "setDisabledDomain",
params: [currentHostname, !siteDisabled]
}).then(() => {
if (siteDisabled) {
disabledDomains = disabledDomains.filter((domain) => domain !== currentHostname);
} else {
disabledDomains.push(currentHostname);
disabledDomains.sort((left, right) => left.localeCompare(right));
}

updateSiteSection();

return browser.runtime.sendMessage({
function: "saveOnExit",
params: []
});
}).catch(handleError);
}

function loadCurrentTab() {
return browser.tabs.query({
active: true,
currentWindow: true
}).then((tabs) => {
const activeTab = tabs[0];

currentURL = activeTab && activeTab.url ? activeTab.url : "";

Check warning on line 250 in core_js/popup.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdXr5i6orNl3BkQo&open=AZ5VEdXr5i6orNl3BkQo&pullRequest=516

try {
currentHostname = currentURL ? new URL(currentURL).hostname.toLowerCase() : "";
} catch (error) {
currentHostname = "";
}

Check warning on line 256 in core_js/popup.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Handle this exception or don't catch it at all.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdXr5i6orNl3BkQp&open=AZ5VEdXr5i6orNl3BkQp&pullRequest=516
});
}

(function() {
loadData("cleanedCounter")
.then(() => loadData("totalCounter"))
Expand All @@ -188,14 +265,16 @@
.then(() => loadData("hashStatus"))
.then(() => loadData("loggingStatus"))
.then(() => loadData("statisticsStatus"))
.then(() => loadData("getCurrentURL", "currentURL"))
.then(() => loadData("disabledDomains"))
.then(() => loadCurrentTab())
.then(() => {
init();
document.getElementById('reset_counter_btn').onclick = resetGlobalCounter;
changeSwitchButton("globalStatus", "globalStatus");
changeSwitchButton("tabcounter", "badgedStatus");
changeSwitchButton("logging", "loggingStatus");
changeSwitchButton("statistics", "statisticsStatus");
siteSwitchButton.onclick = toggleCurrentSite;
document.getElementById('loggingPage').href = browser.runtime.getURL('./html/log.html');
document.getElementById('settings').href = browser.runtime.getURL('./html/settings.html');
document.getElementById('cleaning_tools').href = browser.runtime.getURL('./html/cleaningTool.html');
Expand All @@ -209,6 +288,7 @@
function setText()
{
injectText('loggingPage','popup_html_log_head');
injectText('siteHead', 'popup_html_site_head');
injectText('reset_counter_btn','popup_html_statistics_reset_button');
injectText('rules_status_head','popup_html_rules_status_head');
injectText('statistics_percentage','popup_html_statistics_percentage');
Expand All @@ -221,6 +301,7 @@
injectText('configs_head','popup_html_configs_head');
injectText('configs_switch_statistics','configs_switch_statistics');
document.getElementById('donate').title = translate('donate_button');
updateSiteSection();
}

/**
Expand Down Expand Up @@ -271,9 +352,9 @@
*
* @param {string} string Name of the attribute used for localization
*/
function translate(string)
function translate(string, ...placeholders)
{
return browser.i18n.getMessage(string);
return browser.i18n.getMessage(string, placeholders);
}

function handleError(error) {
Expand Down
7 changes: 7 additions & 0 deletions core_js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
//Set correct icon on startup
changeIcon();

// Cache active and open tab URLs for per-site controls and filtering
initializeTabURLs();

// Start the context_menu
contextMenuStart();

Expand Down Expand Up @@ -163,6 +166,9 @@
case "types":
storage[key] = value.split(',');
break;
case "disabledDomains":
storage[key] = Array.isArray(value) ? value : value.split(',').filter(Boolean);

Check warning on line 170 in core_js/storage.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make it an object if it must have named properties; otherwise, use a numeric index here.

See more on https://sonarcloud.io/project/issues?id=ClearURLs_Addon&issues=AZ5VEdX-5i6orNl3BkQq&open=AZ5VEdX-5i6orNl3BkQq&pullRequest=516
break;
case "logLimit":
storage[key] = Math.max(0, Number(value));
break;
Expand Down Expand Up @@ -224,6 +230,7 @@
storage.domainBlocking = true;
storage.pingBlocking = true;
storage.eTagFiltering = false;
storage.disabledDomains = [];
storage.watchDogErrorCount = 0;

if (getBrowser() === "Firefox") {
Expand Down
Loading