Save global Enable Status

This commit is contained in:
Kevin Röbert 2017-08-06 20:19:53 +02:00
parent bf19420a2b
commit e5ab578a01
2 changed files with 67 additions and 73 deletions

View File

@ -6,6 +6,7 @@
var data = [];
var providers = [];
var prvKeys = [];
var globalStatus;
/**
* Initialize the JSON provider object keys.
@ -200,6 +201,18 @@ function removeFieldsFormURL(provider, request)
*/
function clearUrl(request)
{
browser.storage.local.get('globalStatus', clear);
function clear(data){
globalStatus = data.globalStatus;
if(globalStatus == null){
globalStatus = true;
}
}
if(globalStatus){
console.log(data);
var result = {
"changes": false,
"url": ""
@ -221,7 +234,7 @@ function clearUrl(request)
};
}
}
}
};
/**

View File

@ -1,67 +1,48 @@
var exception = "off";
var resultFormRestore;
function init()
{
setStatus();
}
function saveOptions(key, result) {
console.log("Save with key"+key+" the result: "+result);
browser.storage.local.set({
key: result
function setStatus()
{
browser.storage.local.get('globalStatus', function(data){
//Hier neue ID des Mülleimers
var element = $("#globalStatus");
data = data.globalStatus;
if(data == null){
browser.storage.local.set({"globalStatus": true});
}
if(data){
//Hier neue Enable Classe des Mülleimers
element.removeClass().addClass("status statusEnabled");
}else{
//Hier neue Disable Classe des Mülleimers
element.removeClass().addClass("status statusDisabled");
}
});
}
function changeStatus(){
browser.storage.local.get('globalStatus', function(data){
//Hier neue ID des Mülleimers
var element = $("#globalStatus");
data = data.globalStatus;
if(data){
browser.storage.local.set({"globalStatus": false});
//Hier neue Disable Classe des Mülleimers
element.removeClass().addClass("status statusDisabled");
}else{
browser.storage.local.set({"globalStatus": true});
//Hier neue Enable Classe des Mülleimers
element.removeClass().addClass("status statusEnabled");
}
});
};
function restoreOptions(key)
{
resultFormRestore = null;
function setCurrentChoise(_result)
{
console.log("Reload config with key: "+key+" and result: ");
resultFormRestore = _result;
console.log(resultFormRestore);
};
function onError(error) {
console.log(`Error: ${error}`);
};
var getting = browser.storage.local.get(key);
getting.then(setCurrentChoise, onError);
return resultFormRestore;
}
function changeStatus(){
var status = restoreOptions("globalStatus");
console.log("status: "+status);
var element = $("#globalStatus");
if(status == null){
saveOptions("globalStatus", true);
status = true;
}
if(status){
status = saveOptions("globalStatus", false);
element.removeClass().addClass("status statusDisabled");
}else{
status = saveOptions("globalStatus", true);
element.removeClass().addClass("status statusEnabled");
}
};
function handleException(){
var element = $("#exception");
var val = "Enable on page";
if(exception == "off"){
val = "Disable on page";
exception = "on";
element.removeClass().addClass("disable");
}else{
exception = "off";
element.removeClass().addClass("enable");
}
element.html(val);
};
$(document).ready(function(){
init();
//Hier neue ID des Mülleimers
$("#globalStatus").on("click", changeStatus);
$("#exception").on("click", handleException);
});