mirror of
https://gitlab.com/KevinRoebert/ClearUrls
synced 2025-12-16 06:05:37 +07:00
Final version 1.2.2.8
I hope you all enjoy the new version.
This commit is contained in:
@@ -82,6 +82,7 @@ function setText()
|
||||
document.title = translate('log_html_page_title');
|
||||
$('#page_title').text(translate('log_html_page_title'));
|
||||
$('#reset_log_btn').text(translate('log_html_reset_button'));
|
||||
$('#log_html_reset_button').prop('title', translate('log_html_reset_button_title'));
|
||||
$('#head_1').text(translate('log_html_table_head_1'));
|
||||
$('#head_2').text(translate('log_html_table_head_2'));
|
||||
$('#head_3').text(translate('log_html_table_head_3'));
|
||||
|
||||
@@ -10,9 +10,10 @@ var globalStatus;
|
||||
var badgedStatus;
|
||||
var hashStatus;
|
||||
var loggingStatus;
|
||||
var statisticsStatus;
|
||||
|
||||
var core = function (func) {
|
||||
return browser.runtime.getBackgroundPage().then(func);
|
||||
return browser.runtime.getBackgroundPage().then(func);
|
||||
};
|
||||
|
||||
function getData()
|
||||
@@ -24,6 +25,7 @@ function getData()
|
||||
badgedStatus = ref.getData('badgedStatus');
|
||||
hashStatus = ref.getData('hashStatus');
|
||||
loggingStatus = ref.getData('loggingStatus');
|
||||
statisticsStatus = ref.getData('statisticsStatus');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,18 +35,20 @@ function getData()
|
||||
*/
|
||||
function init()
|
||||
{
|
||||
setSwitchButton("globalStatus", "globalStatus");
|
||||
setSwitchButton("tabcounter", "badgedStatus");
|
||||
setSwitchButton("logging", "loggingStatus");
|
||||
setSwitchButton("statistics", "statisticsStatus");
|
||||
setHashStatus();
|
||||
setGlobalStatus();
|
||||
changeStatistics();
|
||||
setTabcounter();
|
||||
setLogging();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the globalCounter value from the browser storage
|
||||
* @param {(data){} Return value form browser.storage.local.get
|
||||
*/
|
||||
function changeStatistics(){
|
||||
function changeStatistics()
|
||||
{
|
||||
globalPercentage = ((globalCounter/globalurlcounter)*100).toFixed(3);
|
||||
|
||||
if(isNaN(Number(globalPercentage))) globalPercentage = 0;
|
||||
@@ -57,64 +61,8 @@ function changeStatistics(){
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the value of the globalStatus.
|
||||
* Call by onChange()
|
||||
*
|
||||
* Set the value for the hashStatus on startUp.
|
||||
*/
|
||||
function changeGlobalStatus() {
|
||||
var element = $('#globalStatus').is(':checked');
|
||||
|
||||
core(function (ref){
|
||||
ref.setData('globalStatus', element);
|
||||
ref.saveOnExit();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the values for the global status switch
|
||||
*/
|
||||
function setGlobalStatus() {
|
||||
var element = $('#globalStatus');
|
||||
element.prop('checked', globalStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the value of the badgedStatus.
|
||||
* Call by onChange()
|
||||
*
|
||||
*/
|
||||
function changeTabcounter() {
|
||||
var element = $('#tabcounter').is(':checked');
|
||||
|
||||
core(function (ref){
|
||||
ref.setData('badgedStatus', element);
|
||||
ref.saveOnExit();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the values for the tabcounter switch
|
||||
*/
|
||||
function setTabcounter() {
|
||||
var element = $('#tabcounter');
|
||||
element.prop('checked', badgedStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the value of the logging switch
|
||||
*/
|
||||
function changeLogging()
|
||||
{
|
||||
var element = $('#logging').is(':checked');
|
||||
core(function (ref){
|
||||
ref.setData('loggingStatus', element);
|
||||
ref.saveOnExit();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value for the hashStatus on startUp.
|
||||
*/
|
||||
function setHashStatus()
|
||||
{
|
||||
var element = $('#hashStatus');
|
||||
@@ -130,12 +78,33 @@ function setHashStatus()
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value for the logging switch
|
||||
* Change the value of a switch button.
|
||||
* @param {string} id HTML id
|
||||
* @param {string} storageID storage internal id
|
||||
*/
|
||||
function setLogging()
|
||||
function changeSwitchButton(id, storageID)
|
||||
{
|
||||
var element = $('#logging');
|
||||
element.prop('checked', loggingStatus);
|
||||
var element = $('#'+id);
|
||||
|
||||
element.on('change', function(){
|
||||
core(function (ref){
|
||||
ref.setData(storageID, element.is(':checked'));
|
||||
if(storageID == "globalStatus") ref.changeIcon();
|
||||
|
||||
ref.saveOnExit();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of a switch button.
|
||||
* @param {string} id HTML id
|
||||
* @param {string} varname js internal variable name
|
||||
*/
|
||||
function setSwitchButton(id, varname)
|
||||
{
|
||||
var element = $('#'+id);
|
||||
element.prop('checked', this[varname]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,26 +116,28 @@ function resetGlobalCounter(){
|
||||
globalCounter = 0;
|
||||
ref.setData('globalCounter', 0);
|
||||
ref.setData('globalurlcounter', 0);
|
||||
ref.saveOnExit();
|
||||
|
||||
changeStatistics();
|
||||
});
|
||||
}
|
||||
|
||||
getData();
|
||||
$(document).ready(function(){
|
||||
init();
|
||||
$("#globalStatus").on("change", changeGlobalStatus);
|
||||
$('#reset_counter_btn').on("click", resetGlobalCounter);
|
||||
$('#tabcounter').on('change', changeTabcounter);
|
||||
$('#logging').on('change', changeLogging);
|
||||
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();
|
||||
|
||||
browser.storage.onChanged.addListener(changeStatistics);
|
||||
});
|
||||
|
||||
/**
|
||||
* Set the text for the UI.
|
||||
*/
|
||||
* Set the text for the UI.
|
||||
*/
|
||||
function setText()
|
||||
{
|
||||
$('#loggingPage').text(translate('popup_html_log_head'));
|
||||
@@ -183,6 +154,8 @@ function setText()
|
||||
$('#configs_switch_log').prop('title', translate('popup_html_configs_switch_log_title'));
|
||||
$('#configs_switch_filter').text(translate('popup_html_configs_switch_filter'));
|
||||
$('#configs_head').text(translate('popup_html_configs_head'));
|
||||
$('#configs_switch_statistics').text(translate('configs_switch_statistics'));
|
||||
$('#configs_switch_statistics').prop('title', translate('configs_switch_statistics_title'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
96
core_js/settings.js
Normal file
96
core_js/settings.js
Normal file
@@ -0,0 +1,96 @@
|
||||
var settings = [];
|
||||
|
||||
var core = function (func) {
|
||||
return browser.runtime.getBackgroundPage().then(func);
|
||||
};
|
||||
|
||||
getData();
|
||||
|
||||
/**
|
||||
* Load only when document is ready
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
setText();
|
||||
$(".pick-a-color").pickAColor();
|
||||
$('#reset_settings_btn').on("click", reset);
|
||||
$('#save_settings_btn').on("click", save);
|
||||
|
||||
$("#badged_color input").on("change", function () {
|
||||
settings.badged_color = $(this).val();
|
||||
core(function (ref){
|
||||
ref.setData('badged_color', settings.badged_color);
|
||||
ref.setBadgedStatus();
|
||||
ref.saveOnExit();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Reset everything.
|
||||
* Set everthing to the default values.
|
||||
*/
|
||||
function reset()
|
||||
{
|
||||
core(function (ref){
|
||||
ref.initSettings();
|
||||
ref.saveOnExit();
|
||||
ref.reload();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the settings.
|
||||
*/
|
||||
function save()
|
||||
{
|
||||
|
||||
core(function (ref){
|
||||
ref.setData('ruleURL', $('input[name=rule_url]').val());
|
||||
ref.setData('hashURL', $('input[name=hash_url]').val());
|
||||
ref.saveOnExit();
|
||||
ref.reload();
|
||||
});
|
||||
|
||||
location.reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data.
|
||||
*/
|
||||
function getData()
|
||||
{
|
||||
core(function (ref){
|
||||
settings.badged_color = ref.getData('badged_color');
|
||||
settings.rule_url = ref.getData('ruleURL');
|
||||
settings.hash_url = ref.getData('hashURL');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text for the UI.
|
||||
*/
|
||||
function setText()
|
||||
{
|
||||
document.title = translate('settings_html_page_title');
|
||||
$('#page_title').text(translate('settings_html_page_title'));
|
||||
$('#badged_color_label').text(translate('badged_color_label'));
|
||||
$('input[name=badged_color]').val(settings.badged_color);
|
||||
$('#reset_settings_btn').text(translate('setting_html_reset_button'));
|
||||
$('#reset_settings_btn').prop('title', translate('setting_html_reset_button_title'));
|
||||
$('#rule_url_label').text(translate('setting_rule_url_label'));
|
||||
$('input[name=rule_url]').val(settings.rule_url);
|
||||
$('#hash_url_label').text(translate('setting_hash_url_label'));
|
||||
$('input[name=hash_url]').val(settings.hash_url);
|
||||
$('#save_settings_btn').text(translate('settings_html_save_button'));
|
||||
$('#save_settings_btn').prop('title', translate('settings_html_save_button_title'));
|
||||
}
|
||||
Reference in New Issue
Block a user