mirror of
https://gitlab.com/KevinRoebert/ClearUrls
synced 2025-12-15 13:45:36 +07:00
Fixed counter issue
Fixed https://github.com/ClearURLs/Addon/issues/234
This commit is contained in:
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- [67](https://github.com/ClearURLs/Addon/issues/67)
|
||||
- [138](https://github.com/ClearURLs/Addon/issues/138)
|
||||
- [1177](https://gitlab.com/KevinRoebert/ClearUrls/-/issues/1177)
|
||||
- [234](https://github.com/ClearURLs/Addon/issues/234)
|
||||
|
||||
## [1.24.1] - 2022-03-25
|
||||
|
||||
|
||||
68
clearurls.js
68
clearurls.js
@@ -44,7 +44,6 @@ function removeFieldsFormURL(provider, pureUrl, quiet = false, request = null) {
|
||||
let fields = "";
|
||||
let rules = provider.getRules();
|
||||
let changes = false;
|
||||
let cancel = false;
|
||||
let rawRules = provider.getRawRules();
|
||||
let urlObject = new URL(url);
|
||||
|
||||
@@ -56,6 +55,37 @@ function removeFieldsFormURL(provider, pureUrl, quiet = false, request = null) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Expand the url by provider redirections. So no tracking on
|
||||
* url redirections form sites to sites.
|
||||
*/
|
||||
let re = provider.getRedirection(url);
|
||||
if (re !== null) {
|
||||
url = decodeURL(re);
|
||||
|
||||
//Log the action
|
||||
if (!quiet) {
|
||||
pushToLog(pureUrl, url, translate('log_redirect'));
|
||||
increaseTotalCounter(1);
|
||||
increaseBadged(false, request)
|
||||
}
|
||||
|
||||
return {
|
||||
"redirect": true,
|
||||
"url": url
|
||||
}
|
||||
}
|
||||
|
||||
if (provider.isCaneling() && storage.domainBlocking) {
|
||||
if (!quiet) pushToLog(pureUrl, pureUrl, translate('log_domain_blocked'));
|
||||
increaseTotalCounter(1);
|
||||
increaseBadged(quiet, request);
|
||||
return {
|
||||
"cancel": true,
|
||||
"url": url
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Apply raw rules to the URL.
|
||||
*/
|
||||
@@ -75,28 +105,6 @@ function removeFieldsFormURL(provider, pureUrl, quiet = false, request = null) {
|
||||
});
|
||||
|
||||
urlObject = new URL(url);
|
||||
|
||||
/*
|
||||
* Expand the url by provider redirections. So no tracking on
|
||||
* url redirections form sites to sites.
|
||||
*/
|
||||
let re = provider.getRedirection(url);
|
||||
if (re !== null) {
|
||||
url = decodeURL(re);
|
||||
|
||||
//Log the action
|
||||
if (!quiet) {
|
||||
pushToLog(pureUrl, url, translate('log_redirect'));
|
||||
increaseGlobalURLCounter(1);
|
||||
increaseBadged(false, request)
|
||||
}
|
||||
|
||||
return {
|
||||
"redirect": true,
|
||||
"url": url
|
||||
}
|
||||
}
|
||||
|
||||
fields = urlObject.searchParams;
|
||||
fragments = extractFragments(urlObject);
|
||||
domain = urlWithoutParamsAndHash(urlObject).toString();
|
||||
@@ -150,17 +158,11 @@ function removeFieldsFormURL(provider, pureUrl, quiet = false, request = null) {
|
||||
url = finalURL.replace(new RegExp("\\?&"), "?").replace(new RegExp("#&"), "#");
|
||||
}
|
||||
|
||||
if (provider.isCaneling() && storage.domainBlocking) {
|
||||
if (!quiet) pushToLog(pureUrl, pureUrl, translate('log_domain_blocked'));
|
||||
increaseGlobalURLCounter(1);
|
||||
increaseBadged(quiet, request);
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
"changes": changes,
|
||||
"url": url,
|
||||
"cancel": cancel
|
||||
"url": url
|
||||
}
|
||||
}
|
||||
|
||||
@@ -607,7 +609,7 @@ function start() {
|
||||
const URLbeforeReplaceCount = countFields(request.url);
|
||||
|
||||
//Add Fields form Request to global url counter
|
||||
increaseGlobalURLCounter(URLbeforeReplaceCount);
|
||||
increaseTotalCounter(URLbeforeReplaceCount);
|
||||
|
||||
if (storage.globalStatus) {
|
||||
let result = {
|
||||
@@ -620,7 +622,7 @@ function start() {
|
||||
if (storage.pingBlocking && storage.pingRequestTypes.includes(request.type)) {
|
||||
pushToLog(request.url, request.url, translate('log_ping_blocked'));
|
||||
increaseBadged(false, request);
|
||||
increaseGlobalURLCounter(1);
|
||||
increaseTotalCounter(1);
|
||||
return {cancel: true};
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ let badges = {};
|
||||
* Increases the badged by one.
|
||||
*/
|
||||
function increaseBadged(quiet = false, request) {
|
||||
if (!quiet) increaseURLCounter();
|
||||
if (!quiet) increaseCleanedCounter();
|
||||
|
||||
if(request === null) return;
|
||||
|
||||
@@ -74,4 +74,4 @@ function handleUpdated(tabId, changeInfo, tabInfo) {
|
||||
/**
|
||||
* Call by each tab is updated.
|
||||
*/
|
||||
browser.tabs.onUpdated.addListener(handleUpdated);
|
||||
browser.tabs.onUpdated.addListener(handleUpdated);
|
||||
|
||||
@@ -23,8 +23,8 @@ var elProgressbar_blocked = document.getElementById('progress_blocked');
|
||||
var elProgressbar_non_blocked = document.getElementById('progress_non_blocked');
|
||||
var elTotal = document.getElementById('statistics_total_elements');
|
||||
var globalPercentage = 0;
|
||||
var globalCounter;
|
||||
var globalurlcounter;
|
||||
var cleanedCounter;
|
||||
var totalCounter;
|
||||
var globalStatus;
|
||||
var badgedStatus;
|
||||
var hashStatus;
|
||||
@@ -47,19 +47,19 @@ function init()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the globalCounter and globalurlcounter value from the storage
|
||||
* Get the cleanedCounter and totalCounter value from the storage
|
||||
*/
|
||||
function changeStatistics()
|
||||
{
|
||||
globalPercentage = ((globalCounter/globalurlcounter)*100).toFixed(3);
|
||||
globalPercentage = ((cleanedCounter/totalCounter)*100).toFixed(3);
|
||||
|
||||
if(isNaN(Number(globalPercentage))) globalPercentage = 0;
|
||||
|
||||
element.textContent = globalCounter.toLocaleString();
|
||||
element.textContent = cleanedCounter.toLocaleString();
|
||||
elGlobalPercentage.textContent = globalPercentage+"%";
|
||||
elProgressbar_blocked.style.width = globalPercentage+'%';
|
||||
elProgressbar_non_blocked.style.width = (100-globalPercentage)+'%';
|
||||
elTotal.textContent = globalurlcounter.toLocaleString();
|
||||
elTotal.textContent = totalCounter.toLocaleString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,12 +161,12 @@ function setSwitchButton(id, varname)
|
||||
function resetGlobalCounter(){
|
||||
browser.runtime.sendMessage({
|
||||
function: "setData",
|
||||
params: ['globalCounter', 0]
|
||||
params: ['cleanedCounter', 0]
|
||||
}).catch(handleError);
|
||||
|
||||
browser.runtime.sendMessage({
|
||||
function: "setData",
|
||||
params: ['globalurlcounter', 0]
|
||||
params: ['totalCounter', 0]
|
||||
}).catch(handleError);
|
||||
|
||||
browser.runtime.sendMessage({
|
||||
@@ -174,15 +174,15 @@ function resetGlobalCounter(){
|
||||
params: []
|
||||
}).catch(handleError);
|
||||
|
||||
globalCounter = 0;
|
||||
globalurlcounter = 0;
|
||||
cleanedCounter = 0;
|
||||
totalCounter = 0;
|
||||
|
||||
changeStatistics();
|
||||
}
|
||||
|
||||
(function() {
|
||||
loadData("globalCounter")
|
||||
.then(() => loadData("globalurlcounter"))
|
||||
loadData("cleanedCounter")
|
||||
.then(() => loadData("totalCounter"))
|
||||
.then(() => loadData("globalStatus"))
|
||||
.then(() => loadData("badgedStatus"))
|
||||
.then(() => loadData("hashStatus"))
|
||||
|
||||
@@ -46,7 +46,7 @@ function _cleaning(url, quiet = false) {
|
||||
|
||||
if (!quiet) {
|
||||
//Add Fields form Request to global url counter
|
||||
increaseGlobalURLCounter(URLbeforeReplaceCount);
|
||||
increaseTotalCounter(URLbeforeReplaceCount);
|
||||
}
|
||||
|
||||
for (let i = 0; i < providers.length; i++) {
|
||||
|
||||
@@ -63,6 +63,13 @@ function storageDataAsString(key) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete key from browser storage.
|
||||
*/
|
||||
function deleteFromDisk(key) {
|
||||
browser.storage.local.remove(key).catch(handleError);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save multiple keys on the disk.
|
||||
* @param {String[]} keys
|
||||
@@ -159,6 +166,20 @@ function setData(key, value) {
|
||||
case "logLimit":
|
||||
storage[key] = Math.max(0, Number(value));
|
||||
break;
|
||||
case "globalurlcounter":
|
||||
// migrate from old key
|
||||
storage["totalCounter"] = value;
|
||||
delete storage[key];
|
||||
deleteFromDisk(key);
|
||||
saveOnExit();
|
||||
break;
|
||||
case "globalCounter":
|
||||
// migrate from old key
|
||||
storage["cleanedCounter"] = value;
|
||||
delete storage[key];
|
||||
deleteFromDisk(key);
|
||||
saveOnExit();
|
||||
break;
|
||||
default:
|
||||
storage[key] = value;
|
||||
}
|
||||
@@ -186,8 +207,8 @@ function initSettings() {
|
||||
storage.dataHash = "";
|
||||
storage.badgedStatus = true;
|
||||
storage.globalStatus = true;
|
||||
storage.globalurlcounter = 0;
|
||||
storage.globalCounter = 0;
|
||||
storage.totalCounter = 0;
|
||||
storage.cleanedCounter = 0;
|
||||
storage.hashStatus = "error";
|
||||
storage.loggingStatus = false;
|
||||
storage.log = {"log": []};
|
||||
|
||||
@@ -114,7 +114,7 @@ function checkLocalURL(url) {
|
||||
* @return {int} Number of Parameters
|
||||
*/
|
||||
function countFields(url) {
|
||||
return new URL(url).searchParams.entries.length;
|
||||
return [...new URL(url).searchParams].length
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,23 +158,23 @@ function loadOldDataFromStore() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase by {number} the GlobalURLCounter
|
||||
* Increase by {number} the total counter
|
||||
* @param {int} number
|
||||
*/
|
||||
function increaseGlobalURLCounter(number) {
|
||||
function increaseTotalCounter(number) {
|
||||
if (storage.statisticsStatus) {
|
||||
storage.globalurlcounter += number;
|
||||
deferSaveOnDisk('globalurlcounter');
|
||||
storage.totalCounter += number;
|
||||
deferSaveOnDisk('totalCounter');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase by one the URLCounter
|
||||
* Increase by one the cleaned counter
|
||||
*/
|
||||
function increaseURLCounter() {
|
||||
function increaseCleanedCounter() {
|
||||
if (storage.statisticsStatus) {
|
||||
storage.globalCounter++;
|
||||
deferSaveOnDisk('globalCounter');
|
||||
storage.cleanedCounter++;
|
||||
deferSaveOnDisk('cleanedCounter');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user