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,28 +201,40 @@ function removeFieldsFormURL(provider, request)
*/
function clearUrl(request)
{
var result = {
"changes": false,
"url": ""
};
/*
* Call for every provider the removeFieldsFormURL method.
*/
for (var i = 0; i < providers.length; i++) {
result = removeFieldsFormURL(providers[i], request);
browser.storage.local.get('globalStatus', clear);
/*
* Ensure that the function go not into
* an loop.
*/
if(result["changes"]){
return {
redirectUrl: result["url"]
};
}
function clear(data){
globalStatus = data.globalStatus;
if(globalStatus == null){
globalStatus = true;
}
}
if(globalStatus){
console.log(data);
var result = {
"changes": false,
"url": ""
};
/*
* Call for every provider the removeFieldsFormURL method.
*/
for (var i = 0; i < providers.length; i++) {
result = removeFieldsFormURL(providers[i], request);
/*
* Ensure that the function go not into
* an loop.
*/
if(result["changes"]){
return {
redirectUrl: result["url"]
};
}
}
}
};
/**

View File

@ -1,67 +1,48 @@
var exception = "off";
var resultFormRestore;
function saveOptions(key, result) {
console.log("Save with key"+key+" the result: "+result);
browser.storage.local.set({
key: result
});
};
function restoreOptions(key)
function init()
{
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;
setStatus();
}
function changeStatus(){
var status = restoreOptions("globalStatus");
console.log("status: "+status);
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");
}
});
}
if(status == null){
saveOptions("globalStatus", true);
status = true;
}
function changeStatus(){
browser.storage.local.get('globalStatus', function(data){
//Hier neue ID des Mülleimers
var element = $("#globalStatus");
data = data.globalStatus;
if(status){
status = saveOptions("globalStatus", false);
if(data){
browser.storage.local.set({"globalStatus": false});
//Hier neue Disable Classe des Mülleimers
element.removeClass().addClass("status statusDisabled");
}else{
status = saveOptions("globalStatus", true);
browser.storage.local.set({"globalStatus": true});
//Hier neue Enable Classe des Mülleimers
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);
});