diff --git a/clearurls.js b/clearurls.js index 485a8af..503689d 100644 --- a/clearurls.js +++ b/clearurls.js @@ -8,6 +8,7 @@ var providers = []; var prvKeys = []; var globalStatus; var badges = []; +var badgedStatus; var tabid = 0; var globalCounter; var globalURLCounter; @@ -205,7 +206,14 @@ function removeFieldsFormURL(provider, request) } browser.storage.local.set({"globalCounter": ++globalCounter}); - browser.browserAction.setBadgeText({text: (++badges[tabid]).toString(), tabId: tabid}); + if(badgedStatus) { + browser.browserAction.setBadgeText({text: (++badges[tabid]).toString(), tabId: tabid}); + } + else + { + browser.browserAction.setBadgeText({text: "", tabId: tabid}); + } + changes = true; } } @@ -217,7 +225,13 @@ function removeFieldsFormURL(provider, request) } browser.storage.local.set({"globalCounter": ++globalCounter}); - browser.browserAction.setBadgeText({text: (++badges[tabid]).toString(), tabId: tabid}); + if(badgedStatus) { + browser.browserAction.setBadgeText({text: (++badges[tabid]).toString(), tabId: tabid}); + } + else + { + browser.browserAction.setBadgeText({text: "", tabId: tabid}); + } cancel = true; } @@ -237,8 +251,8 @@ function removeFieldsFormURL(provider, request) */ function countFields(url) { - var matches = url.match(/[a-z\d]+=[a-z\d]+/gi); - var count = matches? matches.length : 0; + var matches = (url.match(/[^\/|\?|&]+=[^\/|\?|&]+/gi) || []); + var count = matches.length; return count; } @@ -332,12 +346,36 @@ function setGlobalCounter() { }); } +/** + * Get the badged status from the browser storage and put the value + * into a local variable. + * + */ +function setBadgedStatus() { + browser.storage.local.get('badgedStatus', function(data) { + if(data.badgedStatus) { + badgedStatus = data.badgedStatus; + browser.browserAction.setBadgeBackgroundColor({ + 'color': 'orange' + }); + } + else if(data.badgedStatus === null || typeof(data.badgedStatus) == "undefined"){ + badgedStatus = false; + } + else { + badgedStatus = false; + } + }); +} + +setBadgedStatus(); setGlobalCounter(); /** * Call by each change in the browser storage. */ browser.storage.onChanged.addListener(setGlobalCounter); +browser.storage.onChanged.addListener(setBadgedStatus); /** * Call by each tab is closed. diff --git a/manifest.json b/manifest.json index 56eef4f..e2f1bbb 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "ClearURLs", - "version": "1.1.1.3", + "version": "1.1.1.4", "author": "Kevin R., Arne S.", "description": "Remove tracking elements form URLs. ", "homepage_url": "https://github.com/KevinRoebert/ClearUrls", diff --git a/popup.html b/popup.html index 2f1e13b..28387b0 100644 --- a/popup.html +++ b/popup.html @@ -10,13 +10,13 @@
-
ClearURLs 1.1.1.3
+
ClearURLs 1.1.1.4
Enable globally:
-
+


Totally blocked elements:
@@ -25,7 +25,13 @@
-
+

+

+
diff --git a/popup.js b/popup.js index a53a566..7fe6f93 100644 --- a/popup.js +++ b/popup.js @@ -2,6 +2,7 @@ function init() { setStatus(); changeStatistics(); + setTabcounter(); } function setStatus() @@ -74,6 +75,30 @@ function changeStatistics(){ }); }; +function changeTabcounter() { + var element = $('#tabcounter').is(':checked'); + + browser.storage.local.set({'badgedStatus': element}); +}; + +function setTabcounter() { + var element = $('#tabcounter'); + + browser.storage.local.get('badgedStatus', function(data) { + if(data.badgedStatus) + { + element.prop('checked', true); + } + else if(data.badgedStatus === null || typeof(data.badgedStatus) == "undefined"){ + element.prop('checked', true); + browser.storage.local.set({'badgedStatus': true}); + } + else { + element.prop('checked', false); + } + }); +} + function resetGlobalCounter(){ browser.storage.local.set({"globalCounter": 0}); browser.storage.local.set({"globalURLCounter": 0}); @@ -84,6 +109,7 @@ $(document).ready(function(){ //Hier neue ID des Mülleimers $("#globalStatus").on("click", changeStatus); $('.reset_counter_btn').on("click", resetGlobalCounter); + $('#tabcounter').on('change', changeTabcounter); browser.storage.onChanged.addListener(changeStatistics); }); \ No newline at end of file