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;
|
2018-05-22 16:40:05 +00:00
|
|
|
var statisticsStatus;
|
2018-05-17 23:31:04 +00:00
|
|
|
|
|
|
|
var core = function (func) {
|
2018-05-22 16:40:05 +00:00
|
|
|
return browser.runtime.getBackgroundPage().then(func);
|
2018-05-17 23:31:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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');
|
2018-05-22 16:40:05 +00:00
|
|
|
statisticsStatus = ref.getData('statisticsStatus');
|
2018-05-17 23:31:04 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2018-05-22 16:40:05 +00:00
|
|
|
setSwitchButton("globalStatus", "globalStatus");
|
|
|
|
setSwitchButton("tabcounter", "badgedStatus");
|
|
|
|
setSwitchButton("logging", "loggingStatus");
|
|
|
|
setSwitchButton("statistics", "statisticsStatus");
|
2017-11-18 00:34:01 +00:00
|
|
|
setHashStatus();
|
|
|
|
changeStatistics();
|
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
|
|
|
|
*/
|
2018-05-22 16:40:05 +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
|
|
|
|
|
|
|
/**
|
2018-05-22 16:40:05 +00:00
|
|
|
* Set the value for the hashStatus on startUp.
|
2017-11-18 00:34:01 +00:00
|
|
|
*/
|
|
|
|
function setHashStatus()
|
|
|
|
{
|
|
|
|
var element = $('#hashStatus');
|
|
|
|
|
2018-05-17 23:31:04 +00:00
|
|
|
if(hashStatus)
|
|
|
|
{
|
2018-05-21 21:25:20 +00:00
|
|
|
element.text(translate(hashStatus));
|
2018-05-17 23:31:04 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-05-21 21:25:20 +00:00
|
|
|
element.text(translate('hash_status_code_5'));
|
2018-05-17 23:31:04 +00:00
|
|
|
}
|
|
|
|
|
2017-11-18 00:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-22 16:40:05 +00:00
|
|
|
* Change the value of a switch button.
|
|
|
|
* @param {string} id HTML id
|
|
|
|
* @param {string} storageID storage internal id
|
2017-11-18 00:34:01 +00:00
|
|
|
*/
|
2018-05-22 16:40:05 +00:00
|
|
|
function changeSwitchButton(id, storageID)
|
|
|
|
{
|
|
|
|
var element = $('#'+id);
|
|
|
|
|
2018-06-19 16:13:44 +00:00
|
|
|
changeVisibility(id, storageID);
|
|
|
|
|
2018-05-22 16:40:05 +00:00
|
|
|
element.on('change', function(){
|
|
|
|
core(function (ref){
|
|
|
|
ref.setData(storageID, element.is(':checked'));
|
|
|
|
if(storageID == "globalStatus") ref.changeIcon();
|
2018-06-19 16:13:44 +00:00
|
|
|
changeVisibility(id, storageID);
|
2018-05-22 16:40:05 +00:00
|
|
|
|
|
|
|
ref.saveOnExit();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-19 16:13:44 +00:00
|
|
|
/**
|
|
|
|
* Change the visibility of sections.
|
|
|
|
*/
|
|
|
|
function changeVisibility(id, storageID)
|
|
|
|
{
|
|
|
|
var element;
|
|
|
|
|
|
|
|
switch(storageID)
|
|
|
|
{
|
|
|
|
case "loggingStatus":
|
|
|
|
element = $('#log_section');
|
|
|
|
break;
|
|
|
|
case "statisticsStatus":
|
|
|
|
element = $('#statistic_section');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
element = "undefine";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(element != "undefine")
|
|
|
|
{
|
|
|
|
if($('#'+id).is(':checked'))
|
|
|
|
{
|
|
|
|
element.css('display', '');
|
|
|
|
element.css('display', '');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
element.css('display', 'none');
|
|
|
|
element.css('display', 'none');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-22 16:40:05 +00:00
|
|
|
/**
|
|
|
|
* Set the value of a switch button.
|
|
|
|
* @param {string} id HTML id
|
|
|
|
* @param {string} varname js internal variable name
|
|
|
|
*/
|
|
|
|
function setSwitchButton(id, varname)
|
2017-11-18 00:34:01 +00:00
|
|
|
{
|
2018-05-22 16:40:05 +00:00
|
|
|
var element = $('#'+id);
|
|
|
|
element.prop('checked', this[varname]);
|
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);
|
2018-05-22 16:40:05 +00:00
|
|
|
ref.saveOnExit();
|
|
|
|
|
|
|
|
changeStatistics();
|
2018-05-17 23:31:04 +00:00
|
|
|
});
|
2017-11-18 00:34:01 +00:00
|
|
|
}
|
2017-08-31 19:19:32 +00:00
|
|
|
|
2018-06-19 16:13:44 +00:00
|
|
|
if(!browser.extension.inIncognitoContext)
|
|
|
|
{
|
|
|
|
getData();
|
|
|
|
}
|
|
|
|
|
2017-08-31 19:19:32 +00:00
|
|
|
$(document).ready(function(){
|
2018-06-19 16:13:44 +00:00
|
|
|
if(!browser.extension.inIncognitoContext)
|
|
|
|
{
|
|
|
|
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'));
|
|
|
|
setText();
|
|
|
|
} else {
|
|
|
|
$('#config_section').remove();
|
|
|
|
$('#statistic_section').remove();
|
|
|
|
$('#status_section').remove();
|
|
|
|
$('#log_section').remove();
|
|
|
|
$('#incognito').css('display', '');
|
|
|
|
}
|
|
|
|
|
2017-09-14 01:39:40 +00:00
|
|
|
});
|
2018-05-21 21:25:20 +00:00
|
|
|
|
|
|
|
/**
|
2018-05-22 16:40:05 +00:00
|
|
|
* Set the text for the UI.
|
|
|
|
*/
|
2018-05-21 21:25:20 +00:00
|
|
|
function setText()
|
|
|
|
{
|
2018-06-11 17:46:56 +00:00
|
|
|
injectText('loggingPage','popup_html_log_head');
|
|
|
|
injectText('reset_counter_btn','popup_html_statistics_reset_button');
|
|
|
|
injectText('rules_status_head','popup_html_rules_status_head');
|
|
|
|
injectText('statistics_percentage','popup_html_statistics_percentage');
|
|
|
|
injectText('statistics_blocked','popup_html_statistics_blocked');
|
|
|
|
injectText('statistics_elements','popup_html_statistics_elements');
|
|
|
|
injectText('statistics_head','popup_html_statistics_head');
|
|
|
|
injectText('configs_switch_badges','popup_html_configs_switch_badges');
|
|
|
|
injectText('configs_switch_log','popup_html_configs_switch_log');
|
|
|
|
injectText('configs_switch_filter','popup_html_configs_switch_filter');
|
|
|
|
injectText('configs_head','popup_html_configs_head');
|
|
|
|
injectText('configs_switch_statistics','configs_switch_statistics');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to inject the translated text and tooltip.
|
|
|
|
*
|
|
|
|
* @param {string} id ID of the HTML element
|
|
|
|
* @param {string} attribute Name of the attribute used for localization
|
|
|
|
* @param {boolean} tooltip
|
|
|
|
*/
|
|
|
|
function injectText(id, attribute, tooltip)
|
|
|
|
{
|
|
|
|
object = $('#'+id);
|
|
|
|
object.text(translate(attribute));
|
|
|
|
|
|
|
|
/*
|
|
|
|
This function will throw an error if no translation
|
|
|
|
is found for the tooltip. This is a planned error.
|
|
|
|
*/
|
|
|
|
tooltip = translate(attribute+"_title");
|
|
|
|
|
|
|
|
if(tooltip != "")
|
|
|
|
{
|
|
|
|
object.prop('title', tooltip);
|
|
|
|
}
|
2018-05-21 21:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Translate a string with the i18n API.
|
|
|
|
*
|
|
|
|
* @param {string} string Name of the attribute used for localization
|
|
|
|
*/
|
|
|
|
function translate(string)
|
|
|
|
{
|
|
|
|
return browser.i18n.getMessage(string);
|
|
|
|
}
|