From f7b85adc24b5dd92bf3126b1ad176e193af00515 Mon Sep 17 00:00:00 2001 From: nobody Date: Mon, 8 Jun 2020 11:38:52 +0200 Subject: [PATCH] Implemented Sync extension settings with Firefox Sync or own server (experimental) --- core/interceptor.js | 2 +- core/main.js | 12 ++++++------ core/request-analyzer.js | 6 +++--- core/request-sanitizer.js | 2 +- core/state-manager.js | 18 +++++++++--------- pages/options/options.js | 4 ++-- pages/popup/popup.js | 4 ++-- pages/statistics/statistics.js | 2 +- pages/updates/updates.html | 1 + 9 files changed, 26 insertions(+), 25 deletions(-) diff --git a/core/interceptor.js b/core/interceptor.js index 0b7ed273..eef0509d 100644 --- a/core/interceptor.js +++ b/core/interceptor.js @@ -137,7 +137,7 @@ interceptor.relatedSettings.push(Setting.AMOUNT_INJECTED); interceptor.relatedSettings.push(Setting.XHR_TEST_DOMAIN); interceptor.relatedSettings.push(Setting.BLOCK_MISSING); -chrome.storage.local.get(interceptor.relatedSettings, function (items) { +chrome.storage.sync.get(interceptor.relatedSettings, function (items) { interceptor.amountInjected = items.amountInjected || 0; interceptor.xhrTestDomain = items.xhrTestDomain || Address.DECENTRALEYES; diff --git a/core/main.js b/core/main.js index 83c83757..aaf01999 100644 --- a/core/main.js +++ b/core/main.js @@ -38,7 +38,7 @@ main._initializeSettings = function () { [Setting.DOMAINS_MANIPULATE_DOM]: {} }; - chrome.storage.local.get(settingDefaults, function (items) { + chrome.storage.sync.get(settingDefaults, function (items) { if (items === null) { items = settingDefaults; // Restore setting defaults. @@ -57,7 +57,7 @@ main._initializeSettings = function () { }); } - chrome.storage.local.set(items); + chrome.storage.sync.set(items); }); }; @@ -70,7 +70,7 @@ main._showReleaseNotes = function (details) { if (details.reason === chrome.runtime.OnInstalledReason.INSTALL) { - chrome.storage.local.set({ + chrome.storage.sync.set({ [Setting.LAST_MAPPING_UPDATE]: lastMappingUpdate }, function() { @@ -82,7 +82,7 @@ main._showReleaseNotes = function (details) { if (details.temporary !== true) { - chrome.storage.local.get([Setting.HIDE_RELEASE_NOTES], function (items) { + chrome.storage.sync.get([Setting.HIDE_RELEASE_NOTES], function (items) { if (items.hideReleaseNotes !== true) { @@ -100,13 +100,13 @@ main._showReleaseNotes = function (details) { let oldValue = ""; // If add-on update true, check last update of mappings.js - chrome.storage.local.get([Setting.LAST_MAPPING_UPDATE, Setting.HIDE_RELEASE_NOTES], function (items) { + chrome.storage.sync.get([Setting.LAST_MAPPING_UPDATE, Setting.HIDE_RELEASE_NOTES], function (items) { oldValue = items.lastMappingUpdate; if (oldValue !== newValue) { // Updated mappings.js - chrome.storage.local.set({ + chrome.storage.sync.set({ [Setting.LAST_MAPPING_UPDATE]: newValue }, function() { if (!items.hideReleaseNotes) { diff --git a/core/request-analyzer.js b/core/request-analyzer.js index 83c6e654..7423428a 100644 --- a/core/request-analyzer.js +++ b/core/request-analyzer.js @@ -102,7 +102,7 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel let resourcePath, versionNumber, resourcePattern, filename, shorthandResource; - chrome.storage.local.get(Setting.LOGGING, function (items) { + chrome.storage.sync.get(Setting.LOGGING, function (items) { requestAnalyzer.logging = items.enableLogging; }); @@ -168,13 +168,13 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel requestAnalyzer._applyWhitelistedDomains = function () { - chrome.storage.local.get(Setting.WHITELISTED_DOMAINS, function (items) { + chrome.storage.sync.get(Setting.WHITELISTED_DOMAINS, function (items) { requestAnalyzer.whitelistedDomains = items.whitelistedDomains || {}; }); }; requestAnalyzer._applyManipulateDOMDomains = function () { - chrome.storage.local.get(Setting.DOMAINS_MANIPULATE_DOM, function (items) { + chrome.storage.sync.get(Setting.DOMAINS_MANIPULATE_DOM, function (items) { requestAnalyzer.domainsManipulateDOM = items.domainsManipulateDOM || {}; }); }; diff --git a/core/request-sanitizer.js b/core/request-sanitizer.js index 8951ec1c..d1ee45e5 100644 --- a/core/request-sanitizer.js +++ b/core/request-sanitizer.js @@ -65,7 +65,7 @@ requestSanitizer._stripMetadata = function (requestDetails) { * Initializations */ -chrome.storage.local.get({[Setting.STRIP_METADATA]: true}, function (items) { +chrome.storage.sync.get({[Setting.STRIP_METADATA]: true}, function (items) { if (items === null || items.stripMetadata !== false) { requestSanitizer.enable(); diff --git a/core/state-manager.js b/core/state-manager.js index 05648a3c..b45dcd61 100644 --- a/core/state-manager.js +++ b/core/state-manager.js @@ -55,18 +55,18 @@ stateManager.registerInjection = function (tabIdentifier, injection) { if (isNaN(interceptor.amountInjected)) { - chrome.storage.local.get(Setting.AMOUNT_INJECTED, function (items) { + chrome.storage.sync.get(Setting.AMOUNT_INJECTED, function (items) { interceptor.amountInjected = items.amountInjected; - chrome.storage.local.set({ + chrome.storage.sync.set({ [Setting.AMOUNT_INJECTED]: ++interceptor.amountInjected }); }); } else { - chrome.storage.local.set({ + chrome.storage.sync.set({ [Setting.AMOUNT_INJECTED]: ++interceptor.amountInjected }); } @@ -94,7 +94,7 @@ stateManager.updateEnvironment = function (preferredEnvironment) { let requiredItems = [Setting.BLOCK_MISSING, Setting.ENFORCE_STAGING]; - chrome.storage.local.get(requiredItems, function (items) { + chrome.storage.sync.get(requiredItems, function (items) { if (items.blockMissing === true || items.enforceStaging === true) { stateManager.setEnvironment(Environment.STAGING); @@ -120,7 +120,7 @@ stateManager.addDomainToWhitelist = function (domain) { let whitelistedDomains = requestAnalyzer.whitelistedDomains; whitelistedDomains[domain] = true; - chrome.storage.local.set({whitelistedDomains}, resolve); + chrome.storage.sync.set({whitelistedDomains}, resolve); }); }; @@ -131,7 +131,7 @@ stateManager.removeDomainFromWhitelist = function (domain) { let whitelistedDomains = requestAnalyzer.whitelistedDomains; delete whitelistedDomains[domain]; - chrome.storage.local.set({whitelistedDomains}, resolve); + chrome.storage.sync.set({whitelistedDomains}, resolve); }); }; @@ -142,7 +142,7 @@ stateManager.addDomainToManipulateDOMlist = function (domain) { let domainsManipulateDOM = requestAnalyzer.domainsManipulateDOM; domainsManipulateDOM[domain] = true; - chrome.storage.local.set({domainsManipulateDOM}, resolve); + chrome.storage.sync.set({domainsManipulateDOM}, resolve); }); }; @@ -153,7 +153,7 @@ stateManager.removeDomainFromManipulateDOMlist = function (domain) { let domainsManipulateDOM = requestAnalyzer.domainsManipulateDOM; delete domainsManipulateDOM[domain]; - chrome.storage.local.set({domainsManipulateDOM}, resolve); + chrome.storage.sync.set({domainsManipulateDOM}, resolve); }); }; @@ -339,7 +339,7 @@ chrome.tabs.query({}, function (tabs) { tabs.forEach(stateManager._createTab); }); -chrome.storage.local.get(Setting.SHOW_ICON_BADGE, function (items) { +chrome.storage.sync.get(Setting.SHOW_ICON_BADGE, function (items) { if (items.showIconBadge === undefined) { items.showIconBadge = true; diff --git a/pages/options/options.js b/pages/options/options.js index 9080900d..5f6a487c 100644 --- a/pages/options/options.js +++ b/pages/options/options.js @@ -123,7 +123,7 @@ options._determineOptionValues = function () { let optionKeys = Object.keys(options._optionElements); - chrome.storage.local.get(optionKeys, function (items) { + chrome.storage.sync.get(optionKeys, function (items) { options._optionValues = items; resolve(); @@ -242,7 +242,7 @@ options._onOptionChanged = function ({target}) { optionValue = options._parseDomainWhitelist(optionValue); } - chrome.storage.local.set({ + chrome.storage.sync.set({ [optionKey]: optionValue }); }; diff --git a/pages/popup/popup.js b/pages/popup/popup.js index 5e0c9080..66977798 100644 --- a/pages/popup/popup.js +++ b/pages/popup/popup.js @@ -259,7 +259,7 @@ popup._determineAmountInjected = function () { return new Promise((resolve) => { - chrome.storage.local.get(Setting.AMOUNT_INJECTED, function (items) { + chrome.storage.sync.get(Setting.AMOUNT_INJECTED, function (items) { popup._amountInjected = items.amountInjected || 0; resolve(); @@ -527,7 +527,7 @@ popup._onMoreInjectionsButton = function () { // Store current injections in extension storage. // Maybe a local statistic/diagram will be implemented later. - chrome.storage.local.set({ + chrome.storage.sync.set({ [Setting.STATISTIC_DATA]: statisticData }); diff --git a/pages/statistics/statistics.js b/pages/statistics/statistics.js index 67f95ca5..50936bd4 100644 --- a/pages/statistics/statistics.js +++ b/pages/statistics/statistics.js @@ -162,7 +162,7 @@ statistics._createInjectionElement = function (injection) { statistics._onDocumentLoaded = function () { - chrome.storage.local.get([Setting.STATISTIC_DATA], function (items) { + chrome.storage.sync.get([Setting.STATISTIC_DATA], function (items) { statisticData = items.statisticData; statistics._renderContents(); }); diff --git a/pages/updates/updates.html b/pages/updates/updates.html index 2620f55b..a01d120e 100644 --- a/pages/updates/updates.html +++ b/pages/updates/updates.html @@ -31,6 +31,7 @@
  • Improved: uMatrix Rule Generator (#23)
  • Replaced: Twitter-Bootstrap CSS v2.3.2 with Twitter-Bootstrap CSS Combined v2.3.2
  • Added: D3 Legend v2.25.6
  • +
  • Implemented: Sync extension settings with Firefox Sync or own server (experimental)
  • Please update your uBlock/uMatrix rules