Version 1.16.0

#362
#440
#429
#428
#431
This commit is contained in:
Kevin Röbert
2020-03-20 01:50:22 +01:00
parent b1a5b5fcb0
commit 0298792aa1
18 changed files with 299 additions and 163 deletions

77
core_js/badgedHandler.js Normal file
View File

@@ -0,0 +1,77 @@
/*
* ClearURLs
* Copyright (c) 2017-2020 Kevin Röbert
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*jshint esversion: 6 */
/*
* This script is responsible for setting the badged.
*/
let badges = {};
/**
* Increases the badged by one.
*/
function increaseBadged(quiet = false, request) {
if (!quiet) increaseURLCounter();
if(request === null) return;
const tabId = request.tabId;
const url = request.url;
if(tabId === -1) return;
if (badges[tabId] == null) {
badges[tabId] = {
counter: 1,
lastURL: url
};
} else {
badges[tabId].counter += 1;
}
checkOSAndroid().then((res) => {
if (!res) {
if (storage.badgedStatus && !quiet) {
browser.browserAction.setBadgeText({text: (badges[tabId]).counter.toString(), tabId: tabId}).catch(handleError);
} else {
browser.browserAction.setBadgeText({text: "", tabId: tabId}).catch(handleError);
}
}
});
}
/**
* Call by each tab is updated.
* And if url has changed.
*/
function handleUpdated(tabId, changeInfo, tabInfo) {
if(!badges[tabId] || !changeInfo.url) return;
if (badges[tabId].lastURL !== changeInfo.url) {
badges[tabId] = {
counter: 0,
lastURL: tabInfo.url
};
}
}
/**
* Call by each tab is updated.
*/
browser.tabs.onUpdated.addListener(handleUpdated);

45
core_js/eTagFilter.js Normal file
View File

@@ -0,0 +1,45 @@
/*
* ClearURLs
* Copyright (c) 2017-2020 Kevin Röbert
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*jshint esversion: 6 */
/**
* Filters eTag headers from web requests.
*/
function eTagFilter(requestDetails) {
if(!requestDetails.responseHeaders || !storage.eTagFiltering) return {};
const responseHeaders = requestDetails.responseHeaders;
const filteredHeaders = responseHeaders.filter(header => {
return header.name.toLowerCase() !== "etag";
});
if(filteredHeaders.length < responseHeaders.length) {
pushToLog(requestDetails.url, requestDetails.url, translate("eTag_filtering_log"));
increaseBadged(false, requestDetails);
increaseGlobalURLCounter(1);
return {responseHeaders: filteredHeaders};
}
}
browser.webRequest.onHeadersReceived.addListener(
eTagFilter,
{urls: ["<all_urls>"]},
["blocking", "responseHeaders"]
);

View File

@@ -115,6 +115,7 @@ function getData()
.then(() => loadData("referralMarketing"))
.then(() => loadData("domainBlocking"))
.then(() => loadData("pingBlocking"))
.then(() => loadData("eTagFiltering"))
.then(() => {
changeSwitchButton("localHostsSkipping", "localHostsSkipping");
changeSwitchButton("historyListenerEnabled", "historyListenerEnabled");
@@ -122,6 +123,7 @@ function getData()
changeSwitchButton("referralMarketing", "referralMarketing");
changeSwitchButton("domainBlocking", "domainBlocking");
changeSwitchButton("pingBlocking", "pingBlocking");
changeSwitchButton("eTagFiltering", "eTagFiltering");
}).catch(handleError);
}
@@ -189,6 +191,8 @@ function setText()
injectText("domain_blocking_enabled", "domain_blocking_enabled");
$('#ping_blocking_enabled').html(translate('ping_blocking_enabled'))
.prop('title', translate('ping_blocking_enabled_title'));
$('#eTag_filtering_enabled').html(translate('eTag_filtering_enabled'))
.prop('title', translate('eTag_filtering_enabled_title'))
}
/**

View File

@@ -202,6 +202,8 @@ function initSettings() {
storage.logLimit = -1;
storage.domainBlocking = true;
storage.pingBlocking = true;
storage.eTagFiltering = true;
storage.watchDogErrorCount = 0;
if (getBrowser() === "Firefox") {
storage.types = ["font", "image", "imageset", "main_frame", "media", "object", "object_subrequest", "other", "script", "stylesheet", "sub_frame", "websocket", "xbl", "xml_dtd", "xmlhttprequest", "xslt"];
@@ -268,6 +270,10 @@ function storeHashStatus(status_code) {
case 3:
status_code = "hash_status_code_3";
break;
case 5:
status_code = "hash_status_code_5";
break;
case 4:
default:
status_code = "hash_status_code_4";
}

View File

@@ -47,10 +47,12 @@ function isEmpty(obj) {
/**
* Translate a string with the i18n API.
*
* @param {string} string Name of the attribute used for localization
* @param {string} string Name of the attribute used for localization
* @param {string[]} placeholders Array of placeholders
*/
function translate(string) {
return browser.i18n.getMessage(string);
function translate(string, ...placeholders)
{
return browser.i18n.getMessage(string, placeholders);
}
/**
@@ -181,32 +183,6 @@ function loadOldDataFromStore() {
localDataHash = storage.dataHash;
}
/**
* Save the hash status to the local storage (RAM).
* The status can have the following values:
* 1 "up to date"
* 2 "updated"
* 3 "update available"
* @param status_code the number for the status
*/
function storeHashStatus(status_code) {
switch (status_code) {
case 1:
status_code = "hash_status_code_1";
break;
case 2:
status_code = "hash_status_code_2";
break;
case 3:
status_code = "hash_status_code_3";
break;
default:
status_code = "hash_status_code_4";
}
storage.hashStatus = status_code;
}
/**
* Increase by {number} the GlobalURLCounter
* @param {int} number
@@ -257,6 +233,9 @@ function setBadgedStatus() {
browser.browserAction.setBadgeBackgroundColor({
'color': color
}).catch(handleError);
browser.browserAction.setBadgeTextColor({
color: "#FFFFFF"
}).catch(handleError);
}
});
}
@@ -305,4 +284,42 @@ Object.prototype.getOrDefault = function (key, defaultValue) {
function handleError(error) {
console.log(translate('core_error') + ":" + error);
}
/**
* Function to log all activities from ClearUrls.
* Only logging when activated.
* The log is only temporary saved in the cache and will
* permanently saved with the saveLogOnClose function.
*
* @param beforeProcessing the url before the clear process
* @param afterProcessing the url after the clear process
* @param rule the rule that triggered the process
*/
function pushToLog(beforeProcessing, afterProcessing, rule) {
const limit = storage.logLimit;
if (storage.loggingStatus && limit !== 0) {
if (limit > 0 && !isNaN(limit)) {
while (storage.log.log.length >= limit) {
storage.log.log.shift();
}
}
storage.log.log.push(
{
"before": beforeProcessing,
"after": afterProcessing,
"rule": rule,
"timestamp": Date.now()
}
);
deferSaveOnDisk('log');
}
}
/**
* Checks if the storage is available.
*/
function isStorageAvailable() {
return storage.ClearURLsData.length !== 0;
}

View File

@@ -24,15 +24,21 @@
*
* This watchdog restarts the whole Add-on, when the check fails.
*/
const CHECK_INTERVAL = 15000;
const CHECK_INTERVAL = 60000;
setInterval(function() {
const dirtyURL = "https://clearurls.roebert.eu?utm_source=addon";
const cleanURL = "https://clearurls.roebert.eu";
if(isStorageAvailable() && storage.globalStatus) {
const dirtyURL = "https://clearurls.roebert.eu?utm_source=addon";
const cleanURL = "https://clearurls.roebert.eu";
if(pureCleaning(dirtyURL, true) !== cleanURL) {
console.log(translate('watchdog'));
saveOnExit();
reload();
if(pureCleaning(dirtyURL, true) !== cleanURL) {
storage.watchDogErrorCount += 1;
console.log(translate('watchdog', storage.watchDogErrorCount));
saveOnExit();
if(storage.watchDogErrorCount < 3) reload();
} else if(storage.watchDogErrorCount > 0){
storage.watchDogErrorCount = 0;
saveOnExit();
}
}
}, CHECK_INTERVAL);