47c4882e9b
The total elements field need async to long to load, so that this value is NaN by scanning the first url. We check now first of NaN or Null and get the current value. The browser is waiting until the value is loaded.
136 lines
3.2 KiB
JavaScript
136 lines
3.2 KiB
JavaScript
/**
|
|
* Initialize the UI.
|
|
*
|
|
*/
|
|
function init()
|
|
{
|
|
setGlobalStatus();
|
|
changeStatistics();
|
|
setTabcounter();
|
|
}
|
|
|
|
/**
|
|
* Get the globalCounter value from the browser storage
|
|
* @param {(data){} Return value form browser.storage.local.get
|
|
*/
|
|
function changeStatistics(){
|
|
var element = $("#statistics_value");
|
|
var elGlobalPercentage = $("#statistics_value_global_percentage");
|
|
var elProgressbar_blocked = $('#progress_blocked');
|
|
var elProgressbar_non_blocked = $('#progress_non_blocked');
|
|
var elTotal = $('#statistics_total_elements');
|
|
var globalPercentage = 0;
|
|
var globalCounter;
|
|
var globalurlcounter;
|
|
|
|
browser.storage.local.get('globalCounter', function(data){
|
|
if(data.globalCounter){
|
|
globalCounter = data.globalCounter;
|
|
}
|
|
else {
|
|
globalCounter = 0;
|
|
}
|
|
|
|
element.text(globalCounter.toLocaleString());
|
|
});
|
|
|
|
browser.storage.local.get('globalurlcounter', function(data){
|
|
if(data.globalurlcounter){
|
|
globalurlcounter = data.globalurlcounter;
|
|
}
|
|
else {
|
|
globalurlcounter = 0;
|
|
}
|
|
|
|
globalPercentage = ((globalCounter/globalurlcounter)*100).toFixed(3);
|
|
|
|
if(isNaN(Number(globalPercentage))) globalPercentage = 0;
|
|
|
|
elGlobalPercentage.text(globalPercentage+"%");
|
|
elProgressbar_blocked.css('width', globalPercentage+'%');
|
|
elProgressbar_non_blocked.css('width', (100-globalPercentage)+'%');
|
|
elTotal.text(globalurlcounter.toLocaleString());
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Change the value of the globalStatus.
|
|
* Call by onChange()
|
|
*
|
|
*/
|
|
function changeGlobalStatus() {
|
|
var element = $('#globalStatus').is(':checked');
|
|
|
|
browser.storage.local.set({'globalStatus': element});
|
|
};
|
|
|
|
/**
|
|
* Set the values for the global status switch
|
|
*/
|
|
function setGlobalStatus() {
|
|
var element = $('#globalStatus');
|
|
|
|
browser.storage.local.get('globalStatus', function(data) {
|
|
if(data.globalStatus) {
|
|
element.prop('checked', true);
|
|
}
|
|
else if(data.globalStatus === null || typeof(data.globalStatus) == "undefined"){
|
|
element.prop('checked', true);
|
|
browser.storage.local.set({'globalStatus': true});
|
|
}
|
|
else {
|
|
element.prop('checked', false);
|
|
}
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Change the value of the badgedStatus.
|
|
* Call by onChange()
|
|
*
|
|
*/
|
|
function changeTabcounter() {
|
|
var element = $('#tabcounter').is(':checked');
|
|
|
|
browser.storage.local.set({'badgedStatus': element});
|
|
};
|
|
|
|
/**
|
|
* Set the values for the tabcounter switch
|
|
*/
|
|
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);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reset the global statistic
|
|
*
|
|
*/
|
|
function resetGlobalCounter(){
|
|
browser.storage.local.set({"globalCounter": 0});
|
|
browser.storage.local.set({"globalurlcounter": 0});
|
|
};
|
|
|
|
$(document).ready(function(){
|
|
init();
|
|
$("#globalStatus").on("change", changeGlobalStatus);
|
|
$('#reset_counter_btn').on("click", resetGlobalCounter);
|
|
$('#tabcounter').on('change', changeTabcounter);
|
|
|
|
browser.storage.onChanged.addListener(changeStatistics);
|
|
});
|