From 84c069331ff0c0d615d04d4246b93573787d3d11 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kevin=20R=C3=B6bert?=
Date: Sun, 24 Nov 2019 18:05:42 +0100
Subject: [PATCH] Version 1.9.4
---
CHANGELOG.md | 21 ++++-
_locales/de/messages.json | 10 ++-
_locales/en/messages.json | 10 ++-
clearurls.js | 2 +-
core_js/popup.js | 111 ++++++++---------------
core_js/settings.js | 182 ++++++++++++++++----------------------
core_js/storage.js | 4 +
html/settings.html | 15 +++-
manifest.json | 2 +-
9 files changed, 168 insertions(+), 189 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bee6ad0..dec3e87 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [1.9.4] - 2019-11-24
+
+### Compatibility note
+- Require Firefox >= 55
+- Require Chrome >= 22
+
+### Fixed
+- Fixed toolbar icon on startup [#102](https://gitlab.com/KevinRoebert/ClearUrls/issues/102)
+
+### Added
+- Added option to disable/allow domain blocking [#294](https://gitlab.com/KevinRoebert/ClearUrls/issues/294)
+
+### Changed
+- Some refactoring
+
## [1.9.3.1] - 2019-11-15
### Compatibility note
@@ -31,7 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed [#290](https://gitlab.com/KevinRoebert/ClearUrls/issues/290)
-## Changed
+### Changed
- Updated some strings of Italian translation by [@gioxx](https://gitlab.com/gioxx)
### Added
@@ -60,7 +75,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed [#241](https://gitlab.com/KevinRoebert/ClearUrls/issues/241)
- Possible fix for [#203](https://gitlab.com/KevinRoebert/ClearUrls/issues/203)
-## Changed
+### Changed
- Refactoring
- Changed background script loading sequence to prevent that required functions are not yet loaded.
@@ -89,7 +104,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Require Firefox >= 55
- Require Chrome >= 22
-## Changed
+### Changed
- Force redirects only on main frames
- Added google link fix script, to avoid the sub frame permission for force redirection on google
diff --git a/_locales/de/messages.json b/_locales/de/messages.json
index 9d498b0..0d18ec0 100644
--- a/_locales/de/messages.json
+++ b/_locales/de/messages.json
@@ -286,7 +286,7 @@
"description": "Diese Zeichenfolge wird als Titel auf der Hinweisseite für blockierte Seiten verwendet."
},
"blocked_html_body": {
- "message": "Diese Seite wurde vom ClearURLs Add-On blockiert, weil wir sie als Werbe- bzw. Trackingservice identifiziert haben. Um diese Seite zu besuchen, müssen Sie das Add-On temporär deaktivieren. Dann können Sie auf den untenstehenden Button klicken, um die Seite aufzurufen.",
+ "message": "Diese Seite wurde vom ClearURLs Add-On blockiert, weil wir sie als Werbe- bzw. Trackingservice identifiziert haben. Um diese Seite zu besuchen, müssen Sie das Add-On temporär deaktivieren oder in den Einstellungen von ClearURLs das Domain-Blocking deaktivieren. Dann können Sie auf den untenstehenden Button klicken, um die Seite aufzurufen.",
"description": "Diese Zeichenfolge wird als Mengentext auf der Hinweisseite für blockierte Seiten verwendet."
},
"blocked_html_button": {
@@ -304,5 +304,13 @@
"watchdog": {
"message": "[ClearURLs]: Der Watchdog hat ein Problem festgestellt. ClearURLs wird neugestartet.",
"description": "Diese Zeichenkette wird als Text für den Watchdog verwendet."
+ },
+ "domain_blocking_enabled": {
+ "message": "Erlaube Domain-Blocking (Kann zu Problemen auf Seiten führen, die AdBlocker nicht erlauben)",
+ "description": "Diese Zeichenkette wird als Beschreibung für das Domain-Blocking verwendet."
+ },
+ "domain_blocking_enabled_title": {
+ "message": "Erlaube Domain-Blocking (Kann zu Problemen auf Seiten führen, die AdBlocker nicht erlauben)",
+ "description": "Diese Zeichenkette wird als Titel für das Domain-Blocking verwendet."
}
}
diff --git a/_locales/en/messages.json b/_locales/en/messages.json
index 775e433..d63f26d 100644
--- a/_locales/en/messages.json
+++ b/_locales/en/messages.json
@@ -286,7 +286,7 @@
"description": "This string is used as title on the blocked site page."
},
"blocked_html_body": {
- "message": "This site was blocked by the ClearURLs Add-on, because we identify this site as an advertising and/or tracking service. To visit this site, you must temporarily deactivate the Add-on. After deactivating ClearURLs you can click on the button below to load the page.",
+ "message": "This site was blocked by the ClearURLs Add-on, because we identify this site as an advertising and/or tracking service. To visit this site, you must temporarily deactivate the Add-on or disable domain blocking in the ClearURLs settings. After this you can click on the button below to load the page.",
"description": "This string is used as body on the blocked site page."
},
"blocked_html_button": {
@@ -304,5 +304,13 @@
"watchdog": {
"message": "[ClearURLs]: The watchdog has detected a problem. ClearURLs is restarted.",
"description": "This string is used as text for the watchdog"
+ },
+ "domain_blocking_enabled": {
+ "message": "Allow domain blocking (Can lead to problems on pages that do not allow AdBlocker)",
+ "description": "This string is used as label for the domain blocking switch"
+ },
+ "domain_blocking_enabled_title": {
+ "message": "Allow domain blocking (Can lead to problems on pages that do not allow AdBlocker)",
+ "description": "This string is used as title for the domain blocking switch"
}
}
diff --git a/clearurls.js b/clearurls.js
index 95476ea..0030d36 100644
--- a/clearurls.js
+++ b/clearurls.js
@@ -170,7 +170,7 @@ function removeFieldsFormURL(provider, pureUrl, quiet = false) {
url = finalURL.replace(new RegExp("\\?&"), "?").replace(new RegExp("#&"), "#");
}
- if (provider.isCaneling()) {
+ if (provider.isCaneling() && storage.domainBlocking) {
if (!quiet) pushToLog(pureUrl, pureUrl, translate('log_domain_blocked'));
if (badges[tabid] == null) {
badges[tabid] = 0;
diff --git a/core_js/popup.js b/core_js/popup.js
index 8035ed7..7d111a2 100644
--- a/core_js/popup.js
+++ b/core_js/popup.js
@@ -32,65 +32,6 @@ var loggingStatus;
var statisticsStatus;
var currentURL;
-async function getData()
-{
- await browser.runtime.sendMessage({
- function: "getData",
- params: ["globalCounter"]
- }).then((data) => {
- globalCounter = data.response;
- });
-
- await browser.runtime.sendMessage({
- function: "getData",
- params: ["globalurlcounter"]
- }).then((data) => {
- globalurlcounter = data.response;
- });
-
- await browser.runtime.sendMessage({
- function: "getData",
- params: ["globalStatus"]
- }).then((data) => {
- globalStatus = data.response;
- });
-
- await browser.runtime.sendMessage({
- function: "getData",
- params: ["badgedStatus"]
- }).then((data) => {
- badgedStatus = data.response;
- });
-
- await browser.runtime.sendMessage({
- function: "getData",
- params: ["hashStatus"]
- }).then((data) => {
- hashStatus = data.response;
- });
-
- await browser.runtime.sendMessage({
- function: "getData",
- params: ["loggingStatus"]
- }).then((data) => {
- loggingStatus = data.response;
- });
-
- await browser.runtime.sendMessage({
- function: "getData",
- params: ["statisticsStatus"]
- }).then((data) => {
- statisticsStatus = data.response;
- });
-
- await browser.runtime.sendMessage({
- function: "getCurrentURL",
- params: []
- }).then((data) => {
- currentURL = data.response;
- });
-}
-
/**
* Initialize the UI.
*
@@ -240,19 +181,26 @@ function resetGlobalCounter(){
}
$(document).ready(function(){
- getData().then(() => {
- init();
- $('#reset_counter_btn').on("click", resetGlobalCounter);
- changeSwitchButton("globalStatus", "globalStatus");
- changeSwitchButton("tabcounter", "badgedStatus");
- changeSwitchButton("logging", "loggingStatus");
- changeSwitchButton("statistics", "statisticsStatus");
- $('#loggingPage').attr('href', browser.extension.getURL('./html/log.html'));
- $('#settings').attr('href', browser.extension.getURL('./html/settings.html'));
- $('#cleaning_tools').attr('href', browser.extension.getURL('./html/cleaningTool.html'));
- setText();
- });
-
+ loadData("globalCounter")
+ .then(() => loadData("globalurlcounter"))
+ .then(() => loadData("globalStatus"))
+ .then(() => loadData("badgedStatus"))
+ .then(() => loadData("hashStatus"))
+ .then(() => loadData("loggingStatus"))
+ .then(() => loadData("statisticsStatus"))
+ .then(() => loadData("getCurrentURL", "currentURL"))
+ .then(() => {
+ init();
+ $('#reset_counter_btn').on("click", resetGlobalCounter);
+ changeSwitchButton("globalStatus", "globalStatus");
+ changeSwitchButton("tabcounter", "badgedStatus");
+ changeSwitchButton("logging", "loggingStatus");
+ changeSwitchButton("statistics", "statisticsStatus");
+ $('#loggingPage').attr('href', browser.extension.getURL('./html/log.html'));
+ $('#settings').attr('href', browser.extension.getURL('./html/settings.html'));
+ $('#cleaning_tools').attr('href', browser.extension.getURL('./html/cleaningTool.html'));
+ setText();
+ });
});
/**
@@ -299,6 +247,25 @@ function injectText(id, attribute, tooltip = "")
}
}
+/**
+ * Loads data from storage and saves into local variable.
+ *
+ * @param name data name
+ * @param varName variable name
+ * @returns {Promise} requested data
+ */
+async function loadData(name, varName=name) {
+ return new Promise((resolve, reject) => {
+ browser.runtime.sendMessage({
+ function: "getData",
+ params: [name]
+ }).then(data => {
+ this[varName] = data.response;
+ resolve(data);
+ }, handleError);
+ });
+}
+
/**
* Translate a string with the i18n API.
*
diff --git a/core_js/settings.js b/core_js/settings.js
index 7699b44..22e7d2f 100644
--- a/core_js/settings.js
+++ b/core_js/settings.js
@@ -78,45 +78,23 @@ function reset()
*/
function save()
{
- browser.runtime.sendMessage({
- function: "setData",
- params: ["badged_color", $('input[name=badged_color]').val()]
- }).then(handleResponse, handleError);
-
- browser.runtime.sendMessage({
- function: "setBadgedStatus",
- params: []
- }).then(handleResponse, handleError);
-
- browser.runtime.sendMessage({
- function: "setData",
- params: ["ruleURL", $('input[name=rule_url]').val()]
- }).then(handleResponse, handleError);
-
- browser.runtime.sendMessage({
- function: "setData",
- params: ["hashURL", $('input[name=hash_url]').val()]
- }).then(handleResponse, handleError);
-
- browser.runtime.sendMessage({
- function: "setData",
- params: ["types", $('input[name=types]').val()]
- }).then(handleResponse, handleError);
-
- browser.runtime.sendMessage({
- function: "setData",
- params: ["logLimit", $('input[name=logLimit]').val()]
- }).then(handleResponse, handleError);
-
- browser.runtime.sendMessage({
- function: "saveOnExit",
- params: []
- }).then(handleResponse, handleError);
-
- browser.runtime.sendMessage({
- function: "reload",
- params: []
- }).then(handleResponse, handleError);
+ saveData("badged_color", $('input[name=badged_color]').val())
+ .then(() => saveData("ruleURL", $('input[name=ruleURL]').val()))
+ .then(() => saveData("hashURL", $('input[name=hashURL]').val()))
+ .then(() => saveData("types", $('input[name=types]').val()))
+ .then(() => saveData("logLimit", $('input[name=logLimit]').val()))
+ .then(() => browser.runtime.sendMessage({
+ function: "setBadgedStatus",
+ params: []
+ }), handleError)
+ .then(() => browser.runtime.sendMessage({
+ function: "saveOnExit",
+ params: []
+ }), handleError)
+ .then(() => browser.runtime.sendMessage({
+ function: "reload",
+ params: []
+ }), handleError);
}
/**
@@ -135,66 +113,69 @@ function translate(string, ...placeholders)
*/
function getData()
{
- browser.runtime.sendMessage({
- function: "getData",
- params: ["badged_color"]
- }).then((data) => handleResponseData(data, "badged_color", "badged_color"), handleError);
+ loadData("badged_color")
+ .then(() => loadData("ruleURL"))
+ .then(() => loadData("hashURL"))
+ .then(() => loadData("types"))
+ .then(() => loadData("logLimit"))
+ .then(logData => {
+ if(logData.response === undefined || logData.response === -1) {
+ $('#logLimit_label').text(translate('setting_log_limit_label', "∞"));
+ } else {
+ $('#logLimit_label').text(translate('setting_log_limit_label', logData.response));
+ }
+ });
- browser.runtime.sendMessage({
- function: "getData",
- params: ["ruleURL"]
- }).then((data) => handleResponseData(data, "rule_url", "rule_url"), handleError);
+ loadData("contextMenuEnabled")
+ .then(() => loadData("historyListenerEnabled"))
+ .then(() => loadData("localHostsSkipping"))
+ .then(() => loadData("referralMarketing"))
+ .then(() => loadData("domainBlocking"))
+ .then(() => {
+ changeSwitchButton("localHostsSkipping", "localHostsSkipping");
+ changeSwitchButton("historyListenerEnabled", "historyListenerEnabled");
+ changeSwitchButton("contextMenuEnabled", "contextMenuEnabled");
+ changeSwitchButton("referralMarketing", "referralMarketing");
+ changeSwitchButton("domainBlocking", "domainBlocking");
+ });
+}
- browser.runtime.sendMessage({
- function: "getData",
- params: ["hashURL"]
- }).then((data) => handleResponseData(data, "hash_url", "hash_url"), handleError);
-
- browser.runtime.sendMessage({
- function: "getData",
- params: ["types"]
- }).then((data) => handleResponseData(data, "types", "types"), handleError);
-
- browser.runtime.sendMessage({
- function: "getData",
- params: ["logLimit"]
- }).then((data) => {
- handleResponseData(data, "logLimit", "logLimit");
- if(data.response === undefined || data.response === -1) {
- $('#logLimit_label').text(translate('setting_log_limit_label', "∞"));
- } else {
- $('#logLimit_label').text(translate('setting_log_limit_label', data.response));
- }
- }, handleError);
-
- browser.runtime.sendMessage({
- function: "getData",
- params: ["contextMenuEnabled"]
- }).then((data) => {
- handleResponseData(data, "contextMenuEnabled", "contextMenuEnabled");
+/**
+ * Loads data from storage and saves into local variable.
+ *
+ * @param name data/variable name
+ * @returns {Promise} requested data
+ */
+async function loadData(name) {
+ return new Promise((resolve, reject) => {
browser.runtime.sendMessage({
function: "getData",
- params: ["historyListenerEnabled"]
- }).then((data) => {
- handleResponseData(data, "historyListenerEnabled", "historyListenerEnabled");
- browser.runtime.sendMessage({
- function: "getData",
- params: ["localHostsSkipping"]
- }).then((data) => {
- handleResponseData(data, "localHostsSkipping", "localHostsSkipping");
- browser.runtime.sendMessage({
- function: "getData",
- params: ["referralMarketing"]
- }).then((data) => {
- handleResponseData(data, "referralMarketing", "referralMarketing");
- changeSwitchButton("contextMenuEnabled", "contextMenuEnabled");
- changeSwitchButton("historyListenerEnabled", "historyListenerEnabled");
- changeSwitchButton("localHostsSkipping", "localHostsSkipping");
- changeSwitchButton("referralMarketing", "referralMarketing");
- }, handleError);
- }, handleError);
+ params: [name]
+ }).then(data => {
+ settings[name] = data.response;
+ $('input[name='+name+']').val(data.response);
+ resolve(data);
}, handleError);
- }, handleError);
+ });
+}
+
+/**
+ * Saves data to storage.
+ *
+ * @param key key of the data that should be saved
+ * @param data data that should be saved
+ * @returns {Promise} message from background script
+ */
+async function saveData(key, data) {
+ return new Promise((resolve, reject) => {
+ browser.runtime.sendMessage({
+ function: "setData",
+ params: [key, data]
+ }).then(message => {
+ handleResponse(message);
+ resolve(message);
+ }, handleError);
+ });
}
/**
@@ -220,6 +201,7 @@ function setText()
$('#import_settings_btn_text').text(translate('setting_html_import_button'));
$('#import_settings_btn').prop('title', translate('setting_html_import_button_title'));
injectText("referral_marketing_enabled", "referral_marketing_enabled");
+ injectText("domain_blocking_enabled", "domain_blocking_enabled");
}
/**
@@ -267,18 +249,6 @@ function importSettings(evt) {
fileReader.readAsText(file);
}
-/**
- * Handle the response from the storage and saves the data.
- * @param {JSON-Object} data Data JSON-Object
- * @param varName
- * @param inputID
- */
-function handleResponseData(data, varName, inputID)
-{
- settings[varName] = data.response;
- $('input[name='+inputID+']').val(data.response);
-}
-
function handleResponse(message) {
console.log(`Message from the background script: ${message.response}`);
}
diff --git a/core_js/storage.js b/core_js/storage.js
index ba5f654..a196058 100644
--- a/core_js/storage.js
+++ b/core_js/storage.js
@@ -106,6 +106,9 @@ function genesis() {
// Start the clearurls.js
start();
+ //Set correct icon on startup
+ changeIcon();
+
// Start the context_menu
contextMenuStart();
@@ -205,6 +208,7 @@ function initSettings() {
storage.localHostsSkipping = true;
storage.referralMarketing = false;
storage.logLimit = -1;
+ storage.domainBlocking = true;
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"];
diff --git a/html/settings.html b/html/settings.html
index 36b384c..402dd27 100644
--- a/html/settings.html
+++ b/html/settings.html
@@ -99,12 +99,11 @@ along with this program. If not, see .
-
+
-
@@ -118,9 +117,9 @@ along with this program. If not, see .
-
+
@@ -141,6 +140,14 @@ along with this program. If not, see .
+
+
+
+
+