diff --git a/distribution/manifest_v2.json b/distribution/manifest_v2.json index 8f6cda9..a53f296 100644 --- a/distribution/manifest_v2.json +++ b/distribution/manifest_v2.json @@ -10,17 +10,12 @@ "default_popup": "popup/settings.html" }, "background": { - "scripts": [ - "dependencies/jquery.min.js", - "lib/background.bundle.js" - ] + "scripts": ["dependencies/jquery.min.js", "lib/background.bundle.js"] }, "content_scripts": [ { "run_at": "document_end", - "matches": [ - "" - ], + "matches": [""], "js": [ "dependencies/jquery.min.js", "lib/main.bundle.js", @@ -33,10 +28,7 @@ "48": "icons/auto-capitalise-sentence.png", "128": "icons/auto-capitalise-sentence.png" }, - "permissions": [ - "storage", - "tabs" - ], + "permissions": ["storage", "tabs"], "browser_specific_settings": { "gecko": { "id": "{680e06ed-65ed-4e11-a9c0-0e6f80b9a347}" diff --git a/src/background.js b/src/background.js index ad2e3af..5176a8a 100644 --- a/src/background.js +++ b/src/background.js @@ -12,7 +12,7 @@ import { } from './plugin-constants'; import browser from 'webextension-polyfill'; -browser.storage.local.set({ +browser.storage.sync.set({ [constantsKeyVal]: constantsKeyValuePairs, [namesKeyVal]: namesKeyValuePairs, [acronymsKeyVal]: acronymsKeyValuePairs, diff --git a/src/content.js b/src/content.js index 1fc51bf..2f9b790 100644 --- a/src/content.js +++ b/src/content.js @@ -19,7 +19,7 @@ import { const errorMsg = 'breaking loop'; let sitesToExclude = ['aws.amazon.com', 'whatsapp.com', 'messenger.com']; -browser.storage.local +browser.storage.sync .get([ sitesToIgnore, shouldCapitaliseI, @@ -39,26 +39,28 @@ browser.storage.local * The browser doesn't register the change and doesn't capitalise I by default after installing the extension. * This block will capture the event and update the value of 'shouldCapitaliseI'. */ -browser.storage.onChanged.addListener(function ( - changes, // object - areaName // string -) { - if (areaName === 'local') { - utils.toggleOptionsValue(changes, shouldCapitaliseI); - utils.toggleOptionsValue(changes, shouldCapitaliseNames); - utils.toggleOptionsValue(changes, shouldCapitaliseAcronyms); - utils.toggleOptionsValue(changes, shouldCapitaliseLocations); - - if (changes.wordsToExclude != null) { - const newValue = changes.wordsToExclude.newValue; - - if (newValue != null) { - utils.setWordsToExclude(newValue); +browser.storage.onChanged.addListener( + function ( + changes, // object + areaName // string + ) { + if (areaName === 'local') { + utils.toggleOptionsValue(changes, shouldCapitaliseI); + utils.toggleOptionsValue(changes, shouldCapitaliseNames); + utils.toggleOptionsValue(changes, shouldCapitaliseAcronyms); + utils.toggleOptionsValue(changes, shouldCapitaliseLocations); + + if (changes.wordsToExclude != null) { + const newValue = changes.wordsToExclude.newValue; + + if (newValue != null) { + utils.setWordsToExclude(newValue); + } } + //browser.runtime.reload() - reload browser } - //browser.runtime.reload() - reload browser } -}); +); function hookupEventHandlers() { observeInputTags(); diff --git a/src/settings.js b/src/settings.js index b3014bf..b674f6f 100644 --- a/src/settings.js +++ b/src/settings.js @@ -11,8 +11,8 @@ import { shouldCapitaliseLocations, } from './plugin-constants'; -browser.storage.local - .get([sitesToIgnore, sitesToExclude, wordsToExclude, wordsToInclude]) +browser.storage.sync + .get([sitesToIgnore, sitesToInclude, wordsToExclude, wordsToInclude]) .then(updateIgnoreLists, onError); function updateIgnoreLists(item) { @@ -48,7 +48,7 @@ $(document).on(`click.${pluginNamespace}`, '#ignoreSiteButton', function () { var sites = getExcludedSites(); sites.push(hostname); - browser.storage.local.set({ + browser.storage.sync.set({ sitesToIgnore: sites, }); @@ -61,7 +61,7 @@ $(document).on(`click.${pluginNamespace}`, '#ignoreSiteButton', function () { $(document).on(`click.${pluginNamespace}`, '#submitButton', function () { var sites = getExcludedSites(); - browser.storage.local.set({ + browser.storage.sync.set({ sitesToIgnore: sites, }); @@ -75,7 +75,7 @@ $(document).on( function () { var excludedWords = getExcludedWords(); - browser.storage.local.set({ + browser.storage.sync.set({ wordsToExclude: excludedWords, }); @@ -90,7 +90,7 @@ $(document).on( function () { var includedWords = getIncludedWords(); - browser.storage.local.set({ + browser.storage.sync.set({ wordsToInclude: includedWords, }); @@ -105,7 +105,7 @@ loadFlagValuesFromBrowserStorage(shouldCapitaliseAcronyms); loadFlagValuesFromBrowserStorage(shouldCapitaliseLocations); function loadFlagValuesFromBrowserStorage(flagName) { - browser.storage.local.get(flagName).then((items) => { + browser.storage.sync.get(flagName).then((items) => { const flagValue = items[flagName]; if (flagValue === true || flagValue === undefined) { @@ -135,7 +135,7 @@ function setupCheckboxChangeEventHandlers(flagName) { } function setShouldCapitaliseVariable(variableName, value) { - browser.storage.local.set({ + browser.storage.sync.set({ [variableName]: value, }); }