From e5ab578a0106e1c0940c78a9734b08b9b31c041e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20R=C3=B6bert?= Date: Sun, 6 Aug 2017 20:19:53 +0200 Subject: [PATCH] Save global Enable Status --- clearurls.js | 53 ++++++++++++++++++++------------ popup.js | 87 ++++++++++++++++++++-------------------------------- 2 files changed, 67 insertions(+), 73 deletions(-) diff --git a/clearurls.js b/clearurls.js index 72a940a..7298d4a 100644 --- a/clearurls.js +++ b/clearurls.js @@ -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"] + }; + } + } + } }; /** diff --git a/popup.js b/popup.js index 6390515..e30249c 100644 --- a/popup.js +++ b/popup.js @@ -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); }); \ No newline at end of file