Add Tabcounter (de)activation switch
Thanks to https://addons.mozilla.org/de/firefox/user/HardKoreG/ for the idea
This commit is contained in:
parent
3a4d2a7460
commit
942e0950a4
46
clearurls.js
46
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.
|
||||
|
|
|
@ -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",
|
||||
|
|
12
popup.html
12
popup.html
|
@ -10,13 +10,13 @@
|
|||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div class="header">ClearURLs 1.1.1.3</div>
|
||||
<div class="header">ClearURLs 1.1.1.4</div>
|
||||
<div id="content">
|
||||
<div id="default">
|
||||
<div id="global">
|
||||
Enable globally:<br>
|
||||
<button id="globalStatus" class="status statusEnabled"></button>
|
||||
</div>
|
||||
</div><br>
|
||||
<hr>
|
||||
<div id="statistics">
|
||||
Totally blocked elements:<br>
|
||||
|
@ -25,7 +25,13 @@
|
|||
<span id="statistics_value_global_percentage" class="statistics_value"></span><br>
|
||||
<div class="center">
|
||||
<button class="reset_counter_btn">Reset counter</button>
|
||||
</div>
|
||||
</div><br>
|
||||
<hr><br>
|
||||
<label class="switch">
|
||||
<input type="checkbox" id="tabcounter">
|
||||
<span class="slider round"></span>
|
||||
<label>Tabcounter</label>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
26
popup.js
26
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);
|
||||
});
|
Loading…
Reference in New Issue
Block a user