diff --git a/src/lib/brain.js b/src/lib/brain.js index 3d0ca36..63c9683 100644 --- a/src/lib/brain.js +++ b/src/lib/brain.js @@ -1,32 +1,42 @@ var wpAdminHide = { /* - * Adds a domain name to localStorage + * Adds a domain name to Chrome storage */ addD: function(d) { - localStorage[d] = true; - console.log(d + " added."); + var save = {}; + save[d] = true; + chrome.storage.sync.set(save, function(result) { + console.log(d, "added to storage, admin bar removed."); + }); }, /* - * Removes a domain from localStorage + * Removes a domain from Chrome storage */ remD: function(d) { - localStorage.removeItem(d); - console.log(d + " removed."); + chrome.storage.sync.remove(d, function() { + console.log(d, "removed from storage, admin bar restored."); + }); }, /* - * Checks for the existence of a localStorage item that matches the domain passed as the first + * Checks for the existence of a Chrome storage item that matches the domain passed as the first * argument. Second and third arguments are what to do if there is or isn't a match, respectively. */ chkD: function(tabId, pass, fail) { chrome.tabs.get(tabId, function(tab) { - d = tab.url.split("/")[2]; - if (localStorage[d]) { - pass(d); - } else { - fail(d); + if(tab.url.indexOf('chrome') == 0){ + console.error('can\'t run on chrome pages, sorry :('); + }else{ + d = tab.url.split("/")[2]; + chrome.storage.sync.get(d, function(result){ + if (result[d]) { + pass(d); + } else { + fail(d); + } + }); } }); }, @@ -79,11 +89,12 @@ var wpAdminHide = { }); } } + }; /* - * Listener for browser action button clickage. Checks the active tab against localstorage and toggles - * the state of the plugin accordingly + * Listener for browser action button clickage. Checks the active tab against Chrome storage + * and toggles the state of the plugin accordingly. */ chrome.browserAction.onClicked.addListener(function(tab) { wpAdminHide.chkD( @@ -101,7 +112,7 @@ chrome.browserAction.onClicked.addListener(function(tab) { /* * Keep the icon up to date based on whether or not the domain exists in local storage. - * Going to assum that the hiding was handled on tab load so this is just for keeping up + * Going to assume that the hiding was handled on tab load so this is just for keeping up * appearances. */ chrome.tabs.onActivated.addListener(function(tab) { diff --git a/src/manifest.json b/src/manifest.json index 8aaca0c..47be7bf 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -3,7 +3,7 @@ "name": "Wordpress Admin Bar Control", "short_name": "WP Admin Bar Hider", - "version": "1.0.3", + "version": "1.1.0", "description": "Hide & show the admin bar with one easy click!", "browser_action": { @@ -15,7 +15,9 @@ }, "permissions": [ - "tabs", "*://*/*" + "storage", + "tabs", + "*://*/*" ], "background":{