mirror of
https://gitlab.com/KevinRoebert/ClearUrls
synced 2025-12-16 22:25:36 +07:00
Version 1.2.2.0
Project memory management. I will test this version first and upload it to mozilla after the tests.
This commit is contained in:
@@ -1,3 +1,32 @@
|
||||
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');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the UI.
|
||||
*
|
||||
@@ -16,43 +45,15 @@ function init()
|
||||
* @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;
|
||||
globalPercentage = ((globalCounter/globalurlcounter)*100).toFixed(3);
|
||||
|
||||
browser.storage.local.get('globalCounter', function(data){
|
||||
if(data.globalCounter){
|
||||
globalCounter = data.globalCounter;
|
||||
}
|
||||
else {
|
||||
globalCounter = 0;
|
||||
}
|
||||
if(isNaN(Number(globalPercentage))) globalPercentage = 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());
|
||||
});
|
||||
element.text(globalCounter.toLocaleString());
|
||||
elGlobalPercentage.text(globalPercentage+"%");
|
||||
elProgressbar_blocked.css('width', globalPercentage+'%');
|
||||
elProgressbar_non_blocked.css('width', (100-globalPercentage)+'%');
|
||||
elTotal.text(globalurlcounter.toLocaleString());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +64,9 @@ function changeStatistics(){
|
||||
function changeGlobalStatus() {
|
||||
var element = $('#globalStatus').is(':checked');
|
||||
|
||||
browser.storage.local.set({'globalStatus': element});
|
||||
core(function (ref){
|
||||
ref.setData('globalStatus', element);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,19 +74,7 @@ function changeGlobalStatus() {
|
||||
*/
|
||||
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);
|
||||
}
|
||||
});
|
||||
element.prop('checked', globalStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +85,9 @@ function setGlobalStatus() {
|
||||
function changeTabcounter() {
|
||||
var element = $('#tabcounter').is(':checked');
|
||||
|
||||
browser.storage.local.set({'badgedStatus': element});
|
||||
core(function (ref){
|
||||
ref.setData('badgedStatus', element);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,20 +95,7 @@ function changeTabcounter() {
|
||||
*/
|
||||
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);
|
||||
}
|
||||
});
|
||||
element.prop('checked', badgedStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,8 +104,9 @@ function setTabcounter() {
|
||||
function changeLogging()
|
||||
{
|
||||
var element = $('#logging').is(':checked');
|
||||
|
||||
browser.storage.local.set({'loggingStatus': element});
|
||||
core(function (ref){
|
||||
ref.setData('loggingStatus', element);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,15 +116,14 @@ function setHashStatus()
|
||||
{
|
||||
var element = $('#hashStatus');
|
||||
|
||||
browser.storage.local.get('hashStatus', function(data) {
|
||||
if(data.hashStatus)
|
||||
{
|
||||
element.text(data.hashStatus);
|
||||
}
|
||||
else {
|
||||
element.text('Oops something went wrong!');
|
||||
}
|
||||
});
|
||||
if(hashStatus)
|
||||
{
|
||||
element.text(hashStatus);
|
||||
}
|
||||
else {
|
||||
element.text('Oops something went wrong!');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,31 +132,22 @@ function setHashStatus()
|
||||
function setLogging()
|
||||
{
|
||||
var element = $('#logging');
|
||||
|
||||
browser.storage.local.get('loggingStatus', function(data) {
|
||||
if(data.loggingStatus)
|
||||
{
|
||||
element.prop('checked', true);
|
||||
}
|
||||
else if(data.loggingStatus === null || typeof(data.loggingStatus) == "undefined"){
|
||||
element.prop('checked', false);
|
||||
browser.storage.local.set({'loggingStatus': false});
|
||||
}
|
||||
else {
|
||||
element.prop('checked', false);
|
||||
}
|
||||
});
|
||||
element.prop('checked', loggingStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the global statistic
|
||||
*
|
||||
*/
|
||||
function resetGlobalCounter(){
|
||||
browser.storage.local.set({"globalCounter": 0});
|
||||
browser.storage.local.set({"globalurlcounter": 0});
|
||||
core(function (ref){
|
||||
globalurlcounter = 0;
|
||||
globalCounter = 0;
|
||||
ref.setData('globalCounter', 0);
|
||||
ref.setData('globalurlcounter', 0);
|
||||
});
|
||||
}
|
||||
|
||||
getData();
|
||||
$(document).ready(function(){
|
||||
init();
|
||||
$("#globalStatus").on("change", changeGlobalStatus);
|
||||
|
||||
Reference in New Issue
Block a user