2018-05-17 23:31:04 +00:00
|
|
|
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;
|
|
|
|
var globalStatus;
|
|
|
|
var badgedStatus;
|
|
|
|
var hashStatus;
|
|
|
|
var loggingStatus;
|
|
|
|
|
|
|
|
var core = function (func) {
|
|
|
|
return browser.runtime.getBackgroundPage().then(func);
|
|
|
|
};
|
|
|
|
|
|
|
|
function getData()
|
|
|
|
{
|
|
|
|
core(function (ref){
|
|
|
|
globalCounter = ref.getData('globalCounter');
|
|
|
|
globalurlcounter = ref.getData('globalurlcounter');
|
|
|
|
globalStatus = ref.getData('globalStatus');
|
|
|
|
badgedStatus = ref.getData('badgedStatus');
|
|
|
|
hashStatus = ref.getData('hashStatus');
|
|
|
|
loggingStatus = ref.getData('loggingStatus');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-31 19:19:32 +00:00
|
|
|
/**
|
2017-11-18 00:34:01 +00:00
|
|
|
* Initialize the UI.
|
|
|
|
*
|
|
|
|
*/
|
2017-08-31 19:19:32 +00:00
|
|
|
function init()
|
|
|
|
{
|
2017-11-18 00:34:01 +00:00
|
|
|
setHashStatus();
|
|
|
|
setGlobalStatus();
|
|
|
|
changeStatistics();
|
|
|
|
setTabcounter();
|
|
|
|
setLogging();
|
2017-08-31 19:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-18 00:34:01 +00:00
|
|
|
* Get the globalCounter value from the browser storage
|
|
|
|
* @param {(data){} Return value form browser.storage.local.get
|
|
|
|
*/
|
2017-08-31 19:19:32 +00:00
|
|
|
function changeStatistics(){
|
2018-05-17 23:31:04 +00:00
|
|
|
globalPercentage = ((globalCounter/globalurlcounter)*100).toFixed(3);
|
2017-11-18 00:34:01 +00:00
|
|
|
|
2018-05-17 23:31:04 +00:00
|
|
|
if(isNaN(Number(globalPercentage))) globalPercentage = 0;
|
2017-11-18 00:34:01 +00:00
|
|
|
|
2018-05-17 23:31:04 +00:00
|
|
|
element.text(globalCounter.toLocaleString());
|
|
|
|
elGlobalPercentage.text(globalPercentage+"%");
|
|
|
|
elProgressbar_blocked.css('width', globalPercentage+'%');
|
|
|
|
elProgressbar_non_blocked.css('width', (100-globalPercentage)+'%');
|
|
|
|
elTotal.text(globalurlcounter.toLocaleString());
|
2017-11-18 00:34:01 +00:00
|
|
|
}
|
2017-08-31 19:19:32 +00:00
|
|
|
|
|
|
|
/**
|
2017-11-18 00:34:01 +00:00
|
|
|
* Change the value of the globalStatus.
|
|
|
|
* Call by onChange()
|
|
|
|
*
|
|
|
|
*/
|
2017-08-31 19:19:32 +00:00
|
|
|
function changeGlobalStatus() {
|
2017-11-18 00:34:01 +00:00
|
|
|
var element = $('#globalStatus').is(':checked');
|
2017-08-31 19:19:32 +00:00
|
|
|
|
2018-05-17 23:31:04 +00:00
|
|
|
core(function (ref){
|
|
|
|
ref.setData('globalStatus', element);
|
|
|
|
});
|
2017-11-18 00:34:01 +00:00
|
|
|
}
|
2017-08-31 19:19:32 +00:00
|
|
|
|
|
|
|
/**
|
2017-11-18 00:34:01 +00:00
|
|
|
* Set the values for the global status switch
|
|
|
|
*/
|
2017-08-31 19:19:32 +00:00
|
|
|
function setGlobalStatus() {
|
2017-11-18 00:34:01 +00:00
|
|
|
var element = $('#globalStatus');
|
2018-05-17 23:31:04 +00:00
|
|
|
element.prop('checked', globalStatus);
|
2017-11-18 00:34:01 +00:00
|
|
|
}
|
2017-08-31 19:19:32 +00:00
|
|
|
|
|
|
|
/**
|
2017-11-18 00:34:01 +00:00
|
|
|
* Change the value of the badgedStatus.
|
|
|
|
* Call by onChange()
|
|
|
|
*
|
|
|
|
*/
|
2017-08-31 19:19:32 +00:00
|
|
|
function changeTabcounter() {
|
2017-11-18 00:34:01 +00:00
|
|
|
var element = $('#tabcounter').is(':checked');
|
2017-08-31 19:19:32 +00:00
|
|
|
|
2018-05-17 23:31:04 +00:00
|
|
|
core(function (ref){
|
|
|
|
ref.setData('badgedStatus', element);
|
|
|
|
});
|
2017-11-18 00:34:01 +00:00
|
|
|
}
|
2017-08-31 19:19:32 +00:00
|
|
|
|
|
|
|
/**
|
2017-11-18 00:34:01 +00:00
|
|
|
* Set the values for the tabcounter switch
|
|
|
|
*/
|
2017-08-31 19:19:32 +00:00
|
|
|
function setTabcounter() {
|
2017-11-18 00:34:01 +00:00
|
|
|
var element = $('#tabcounter');
|
2018-05-17 23:31:04 +00:00
|
|
|
element.prop('checked', badgedStatus);
|
2017-08-31 19:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-18 00:34:01 +00:00
|
|
|
* Change the value of the logging switch
|
|
|
|
*/
|
|
|
|
function changeLogging()
|
|
|
|
{
|
|
|
|
var element = $('#logging').is(':checked');
|
2018-05-17 23:31:04 +00:00
|
|
|
core(function (ref){
|
|
|
|
ref.setData('loggingStatus', element);
|
|
|
|
});
|
2017-11-18 00:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the value for the hashStatus on startUp.
|
2017-08-31 19:19:32 +00:00
|
|
|
*/
|
2017-11-18 00:34:01 +00:00
|
|
|
function setHashStatus()
|
|
|
|
{
|
|
|
|
var element = $('#hashStatus');
|
|
|
|
|
2018-05-17 23:31:04 +00:00
|
|
|
if(hashStatus)
|
|
|
|
{
|
|
|
|
element.text(hashStatus);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
element.text('Oops something went wrong!');
|
|
|
|
}
|
|
|
|
|
2017-11-18 00:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the value for the logging switch
|
|
|
|
*/
|
|
|
|
function setLogging()
|
|
|
|
{
|
|
|
|
var element = $('#logging');
|
2018-05-17 23:31:04 +00:00
|
|
|
element.prop('checked', loggingStatus);
|
2017-11-18 00:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the global statistic
|
|
|
|
*/
|
2017-08-31 19:19:32 +00:00
|
|
|
function resetGlobalCounter(){
|
2018-05-17 23:31:04 +00:00
|
|
|
core(function (ref){
|
|
|
|
globalurlcounter = 0;
|
|
|
|
globalCounter = 0;
|
|
|
|
ref.setData('globalCounter', 0);
|
|
|
|
ref.setData('globalurlcounter', 0);
|
|
|
|
});
|
2017-11-18 00:34:01 +00:00
|
|
|
}
|
2017-08-31 19:19:32 +00:00
|
|
|
|
2018-05-17 23:31:04 +00:00
|
|
|
getData();
|
2017-08-31 19:19:32 +00:00
|
|
|
$(document).ready(function(){
|
2017-11-18 00:34:01 +00:00
|
|
|
init();
|
|
|
|
$("#globalStatus").on("change", changeGlobalStatus);
|
|
|
|
$('#reset_counter_btn').on("click", resetGlobalCounter);
|
|
|
|
$('#tabcounter').on('change', changeTabcounter);
|
|
|
|
$('#logging').on('change', changeLogging);
|
2017-12-16 22:50:50 +00:00
|
|
|
$('#loggingPage').attr('href', browser.extension.getURL('./html/log.html'));
|
2017-11-18 00:34:01 +00:00
|
|
|
|
|
|
|
browser.storage.onChanged.addListener(changeStatistics);
|
2017-09-14 01:39:40 +00:00
|
|
|
});
|