From de2d5d0af2221f8fc81bf23a8c13aabdb223e625 Mon Sep 17 00:00:00 2001 From: Said Achmiz Date: Mon, 18 Feb 2019 17:49:25 -0500 Subject: [PATCH] Switched to using localStorage; incremented version to 1.2.6 --- src/contentScript.js | 2 +- src/options.js | 13 ++++++++++--- src/platform/chrome/manifest.json | 4 ++-- src/platform/firefox/manifest.json | 4 ++-- src/popup.js | 12 +++++++++--- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/contentScript.js b/src/contentScript.js index 03b4884..de0c853 100644 --- a/src/contentScript.js +++ b/src/contentScript.js @@ -127,7 +127,7 @@ function beginKillingStickies() { /******************/ function initialize() { - chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { + chrome.storage.local.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { let shouldKillSticky = checkForShouldKillSticky(result); updateIcon(shouldKillSticky); if (shouldKillSticky) { diff --git a/src/options.js b/src/options.js index 16336e2..bb51250 100644 --- a/src/options.js +++ b/src/options.js @@ -49,18 +49,25 @@ function saveChanges() { let matchingPatterns = document.querySelector("#matchingPatterns textarea").value; let exclusionPatterns = document.querySelector("#exclusionPatterns textarea").value; let mode = document.querySelector("input#whitelist-mode").checked ? "whitelist" : "blacklist"; - chrome.storage.sync.set({ + chrome.storage.local.set({ "matchingPatterns": matchingPatterns, "exclusionPatterns": exclusionPatterns, "mode": mode - }, () => { setButtonsActive(false); }); + }, () => { + let error = chrome.runtime.lastError; + if (error) { + alert(error.message); + } else { + setButtonsActive(false); + } + }); } /* Retrieves the saved state from storage and reset the UI to reflect it, discarding the user's changes. */ function resetChanges(callback) { - chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { + chrome.storage.local.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { AKS.matchingPatterns = result.matchingPatterns || ""; AKS.exclusionPatterns = result.exclusionPatterns || "" AKS.mode = result.mode || "blacklist"; diff --git a/src/platform/chrome/manifest.json b/src/platform/chrome/manifest.json index 0bc173c..646565c 100644 --- a/src/platform/chrome/manifest.json +++ b/src/platform/chrome/manifest.json @@ -1,11 +1,11 @@ { "manifest_version": 2, "name": "AlwaysKillSticky", - "version": "1.2.5.2", + "version": "1.2.6", "description": "Get rid of sticky elements on websites - permanently!", "author": "Said Achmiz", "homepage_url": "https://git.sr.ht/~achmizs/AlwaysKillSticky.git", - "permissions": [ "activeTab", "storage" ], + "permissions": [ "activeTab", "storage", "unlimitedStorage" ], "background": { "scripts": ["background.js"], "persistent": false diff --git a/src/platform/firefox/manifest.json b/src/platform/firefox/manifest.json index 04e2626..7470baf 100644 --- a/src/platform/firefox/manifest.json +++ b/src/platform/firefox/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "AlwaysKillSticky", - "version": "1.2.5.2", + "version": "1.2.6", "description": "Get rid of sticky elements on websites - permanently!", "author": "Said Achmiz", "browser_specific_settings": { @@ -11,7 +11,7 @@ } }, "homepage_url": "https://git.sr.ht/~achmizs/AlwaysKillSticky.git", - "permissions": [ "activeTab", "storage" ], + "permissions": [ "activeTab", "storage", "unlimitedStorage" ], "background": { "scripts": [ "background.js" ] }, diff --git a/src/popup.js b/src/popup.js index 7d66aba..159d1c4 100644 --- a/src/popup.js +++ b/src/popup.js @@ -219,7 +219,7 @@ function initialize() { chrome.tabs.query({currentWindow: true, active: true}, (tabs) => { AKS.activeTabLocation = tabs[0].url; AKS.activeTabID = tabs[0].id; - chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { + chrome.storage.local.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { updateState(result); updateUIState(); }); @@ -228,7 +228,7 @@ function initialize() { // Listener for main button. document.querySelector("button.main-button").addActivateEvent((event) => { /* This doesn’t actually kill the stickies yet; that’s below, in the - callback to storage.sync.set. */ + callback to storage.local.set. */ toggleState(); // Prepare the changes for saving. @@ -240,7 +240,13 @@ function initialize() { changes.matchingPatterns = AKS.matchingPatterns.join("\n"); // Save the changes. - chrome.storage.sync.set(changes, () => { + chrome.storage.local.set(changes, () => { + let error = chrome.runtime.lastError; + if (error) { + alert(error.message); + return; + } + // Update the UI, once changes are saved. updateUIState(); let reloadButton = document.querySelector("button.reload-button");