mirror of
https://gitlab.com/KevinRoebert/ClearUrls
synced 2025-12-16 06:05:37 +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)
|
- [67](https://github.com/ClearURLs/Addon/issues/67)
|
||||||
- [138](https://github.com/ClearURLs/Addon/issues/138)
|
- [138](https://github.com/ClearURLs/Addon/issues/138)
|
||||||
- [1177](https://gitlab.com/KevinRoebert/ClearUrls/-/issues/1177)
|
- [1177](https://gitlab.com/KevinRoebert/ClearUrls/-/issues/1177)
|
||||||
|
- [234](https://github.com/ClearURLs/Addon/issues/234)
|
||||||
|
|
||||||
## [1.24.1] - 2022-03-25
|
## [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 fields = "";
|
||||||
let rules = provider.getRules();
|
let rules = provider.getRules();
|
||||||
let changes = false;
|
let changes = false;
|
||||||
let cancel = false;
|
|
||||||
let rawRules = provider.getRawRules();
|
let rawRules = provider.getRawRules();
|
||||||
let urlObject = new URL(url);
|
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.
|
* Apply raw rules to the URL.
|
||||||
*/
|
*/
|
||||||
@@ -75,28 +105,6 @@ function removeFieldsFormURL(provider, pureUrl, quiet = false, request = null) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
urlObject = new URL(url);
|
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;
|
fields = urlObject.searchParams;
|
||||||
fragments = extractFragments(urlObject);
|
fragments = extractFragments(urlObject);
|
||||||
domain = urlWithoutParamsAndHash(urlObject).toString();
|
domain = urlWithoutParamsAndHash(urlObject).toString();
|
||||||
@@ -150,17 +158,11 @@ function removeFieldsFormURL(provider, pureUrl, quiet = false, request = null) {
|
|||||||
url = finalURL.replace(new RegExp("\\?&"), "?").replace(new RegExp("#&"), "#");
|
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 {
|
return {
|
||||||
"changes": changes,
|
"changes": changes,
|
||||||
"url": url,
|
"url": url
|
||||||
"cancel": cancel
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -607,7 +609,7 @@ function start() {
|
|||||||
const URLbeforeReplaceCount = countFields(request.url);
|
const URLbeforeReplaceCount = countFields(request.url);
|
||||||
|
|
||||||
//Add Fields form Request to global url counter
|
//Add Fields form Request to global url counter
|
||||||
increaseGlobalURLCounter(URLbeforeReplaceCount);
|
increaseTotalCounter(URLbeforeReplaceCount);
|
||||||
|
|
||||||
if (storage.globalStatus) {
|
if (storage.globalStatus) {
|
||||||
let result = {
|
let result = {
|
||||||
@@ -620,7 +622,7 @@ function start() {
|
|||||||
if (storage.pingBlocking && storage.pingRequestTypes.includes(request.type)) {
|
if (storage.pingBlocking && storage.pingRequestTypes.includes(request.type)) {
|
||||||
pushToLog(request.url, request.url, translate('log_ping_blocked'));
|
pushToLog(request.url, request.url, translate('log_ping_blocked'));
|
||||||
increaseBadged(false, request);
|
increaseBadged(false, request);
|
||||||
increaseGlobalURLCounter(1);
|
increaseTotalCounter(1);
|
||||||
return {cancel: true};
|
return {cancel: true};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ let badges = {};
|
|||||||
* Increases the badged by one.
|
* Increases the badged by one.
|
||||||
*/
|
*/
|
||||||
function increaseBadged(quiet = false, request) {
|
function increaseBadged(quiet = false, request) {
|
||||||
if (!quiet) increaseURLCounter();
|
if (!quiet) increaseCleanedCounter();
|
||||||
|
|
||||||
if(request === null) return;
|
if(request === null) return;
|
||||||
|
|
||||||
@@ -74,4 +74,4 @@ function handleUpdated(tabId, changeInfo, tabInfo) {
|
|||||||
/**
|
/**
|
||||||
* Call by each tab is updated.
|
* 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 elProgressbar_non_blocked = document.getElementById('progress_non_blocked');
|
||||||
var elTotal = document.getElementById('statistics_total_elements');
|
var elTotal = document.getElementById('statistics_total_elements');
|
||||||
var globalPercentage = 0;
|
var globalPercentage = 0;
|
||||||
var globalCounter;
|
var cleanedCounter;
|
||||||
var globalurlcounter;
|
var totalCounter;
|
||||||
var globalStatus;
|
var globalStatus;
|
||||||
var badgedStatus;
|
var badgedStatus;
|
||||||
var hashStatus;
|
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()
|
function changeStatistics()
|
||||||
{
|
{
|
||||||
globalPercentage = ((globalCounter/globalurlcounter)*100).toFixed(3);
|
globalPercentage = ((cleanedCounter/totalCounter)*100).toFixed(3);
|
||||||
|
|
||||||
if(isNaN(Number(globalPercentage))) globalPercentage = 0;
|
if(isNaN(Number(globalPercentage))) globalPercentage = 0;
|
||||||
|
|
||||||
element.textContent = globalCounter.toLocaleString();
|
element.textContent = cleanedCounter.toLocaleString();
|
||||||
elGlobalPercentage.textContent = globalPercentage+"%";
|
elGlobalPercentage.textContent = globalPercentage+"%";
|
||||||
elProgressbar_blocked.style.width = globalPercentage+'%';
|
elProgressbar_blocked.style.width = globalPercentage+'%';
|
||||||
elProgressbar_non_blocked.style.width = (100-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(){
|
function resetGlobalCounter(){
|
||||||
browser.runtime.sendMessage({
|
browser.runtime.sendMessage({
|
||||||
function: "setData",
|
function: "setData",
|
||||||
params: ['globalCounter', 0]
|
params: ['cleanedCounter', 0]
|
||||||
}).catch(handleError);
|
}).catch(handleError);
|
||||||
|
|
||||||
browser.runtime.sendMessage({
|
browser.runtime.sendMessage({
|
||||||
function: "setData",
|
function: "setData",
|
||||||
params: ['globalurlcounter', 0]
|
params: ['totalCounter', 0]
|
||||||
}).catch(handleError);
|
}).catch(handleError);
|
||||||
|
|
||||||
browser.runtime.sendMessage({
|
browser.runtime.sendMessage({
|
||||||
@@ -174,15 +174,15 @@ function resetGlobalCounter(){
|
|||||||
params: []
|
params: []
|
||||||
}).catch(handleError);
|
}).catch(handleError);
|
||||||
|
|
||||||
globalCounter = 0;
|
cleanedCounter = 0;
|
||||||
globalurlcounter = 0;
|
totalCounter = 0;
|
||||||
|
|
||||||
changeStatistics();
|
changeStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
loadData("globalCounter")
|
loadData("cleanedCounter")
|
||||||
.then(() => loadData("globalurlcounter"))
|
.then(() => loadData("totalCounter"))
|
||||||
.then(() => loadData("globalStatus"))
|
.then(() => loadData("globalStatus"))
|
||||||
.then(() => loadData("badgedStatus"))
|
.then(() => loadData("badgedStatus"))
|
||||||
.then(() => loadData("hashStatus"))
|
.then(() => loadData("hashStatus"))
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ function _cleaning(url, quiet = false) {
|
|||||||
|
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
//Add Fields form Request to global url counter
|
//Add Fields form Request to global url counter
|
||||||
increaseGlobalURLCounter(URLbeforeReplaceCount);
|
increaseTotalCounter(URLbeforeReplaceCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < providers.length; i++) {
|
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.
|
* Save multiple keys on the disk.
|
||||||
* @param {String[]} keys
|
* @param {String[]} keys
|
||||||
@@ -159,6 +166,20 @@ function setData(key, value) {
|
|||||||
case "logLimit":
|
case "logLimit":
|
||||||
storage[key] = Math.max(0, Number(value));
|
storage[key] = Math.max(0, Number(value));
|
||||||
break;
|
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:
|
default:
|
||||||
storage[key] = value;
|
storage[key] = value;
|
||||||
}
|
}
|
||||||
@@ -186,8 +207,8 @@ function initSettings() {
|
|||||||
storage.dataHash = "";
|
storage.dataHash = "";
|
||||||
storage.badgedStatus = true;
|
storage.badgedStatus = true;
|
||||||
storage.globalStatus = true;
|
storage.globalStatus = true;
|
||||||
storage.globalurlcounter = 0;
|
storage.totalCounter = 0;
|
||||||
storage.globalCounter = 0;
|
storage.cleanedCounter = 0;
|
||||||
storage.hashStatus = "error";
|
storage.hashStatus = "error";
|
||||||
storage.loggingStatus = false;
|
storage.loggingStatus = false;
|
||||||
storage.log = {"log": []};
|
storage.log = {"log": []};
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ function checkLocalURL(url) {
|
|||||||
* @return {int} Number of Parameters
|
* @return {int} Number of Parameters
|
||||||
*/
|
*/
|
||||||
function countFields(url) {
|
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
|
* @param {int} number
|
||||||
*/
|
*/
|
||||||
function increaseGlobalURLCounter(number) {
|
function increaseTotalCounter(number) {
|
||||||
if (storage.statisticsStatus) {
|
if (storage.statisticsStatus) {
|
||||||
storage.globalurlcounter += number;
|
storage.totalCounter += number;
|
||||||
deferSaveOnDisk('globalurlcounter');
|
deferSaveOnDisk('totalCounter');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increase by one the URLCounter
|
* Increase by one the cleaned counter
|
||||||
*/
|
*/
|
||||||
function increaseURLCounter() {
|
function increaseCleanedCounter() {
|
||||||
if (storage.statisticsStatus) {
|
if (storage.statisticsStatus) {
|
||||||
storage.globalCounter++;
|
storage.cleanedCounter++;
|
||||||
deferSaveOnDisk('globalCounter');
|
deferSaveOnDisk('cleanedCounter');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user