From 9cde15f19daba1a73291e6b5d48ea28af37e5bbe Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Wed, 15 Jan 2020 18:58:10 +0100 Subject: [PATCH] v1.6.3.6 Fix json-bug at install/options Fix json-bug when not saving options at start Further some maintenance on background.js: combine enabledSites and initialize allow/remove_cookies and sort blockedRegexes. --- background.js | 50 +++++++++++++++++++---------------------------- manifest.json | 2 +- options.js | 2 +- sites.json | 2 +- sites_custom.json | 2 +- updates.json | 5 +++-- 6 files changed, 27 insertions(+), 36 deletions(-) diff --git a/background.js b/background.js index 3331e58..9e60925 100644 --- a/background.js +++ b/background.js @@ -1,3 +1,5 @@ +/* Please respect alphabetical order when adding a site in any list */ + 'use strict'; // Cookies from this list are blocked by default (obsolete) @@ -84,24 +86,23 @@ function setDefaultOptions() { }); } -// to block external script also add domain to manifest.json (permissions) const blockedRegexes = { -'chicagotribune.com': /.+:\/\/.+\.tribdss\.com\//, -'thenation.com': /thenation\.com\/.+\/paywall-script\.php/, -'haaretz.co.il': /haaretz\.co\.il\/htz\/js\/inter\.js/, -'nzherald.co.nz': /nzherald\.co\.nz\/.+\/headjs\/.+\.js/, -'economist.com': /(.+\.tinypass\.com\/.+|economist\.com\/_next\/static\/runtime\/main.+\.js)/, -'lrb.co.uk': /.+\.tinypass\.com\/.+/, -'bostonglobe.com': /meter\.bostonglobe\.com\/js\/.+/, -'foreignpolicy.com': /.+\.tinypass\.com\/.+/, -'inquirer.com': /.+\.tinypass\.com\/.+/, -'spectator.co.uk': /.+\.tinypass\.com\/.+/, -'newcastleherald.com.au': /.+cdn-au\.piano\.io\/api\/tinypass.+\.js/, 'afr.com': /afr\.com\/assets\/vendorsReactRedux_client.+\.js/, -'theglobeandmail.com': /theglobeandmail\.com\/pb\/resources\/scripts\/build\/chunk-bootstraps\/.+\.js/, +'bostonglobe.com': /meter\.bostonglobe\.com\/js\/.+/, +'chicagotribune.com': /.+:\/\/.+\.tribdss\.com\//, +'economist.com': /(.+\.tinypass\.com\/.+|economist\.com\/_next\/static\/runtime\/main.+\.js)/, +'foreignpolicy.com': /.+\.tinypass\.com\/.+/, +'haaretz.co.il': /haaretz\.co\.il\/htz\/js\/inter\.js/, +'inquirer.com': /.+\.tinypass\.com\/.+/, 'leparisien.fr': /.+\.tinypass\.com\/.+/, 'lesechos.fr': /.+\.tinypass\.com\/.+/, -'nytimes.com': /(.+meter-svc\.nytimes\.com\/meter\.js.+|.+mwcm\.nyt\.com\/.+\.js)/ +'lrb.co.uk': /.+\.tinypass\.com\/.+/, +'newcastleherald.com.au': /.+cdn-au\.piano\.io\/api\/tinypass.+\.js/, +'nytimes.com': /(.+meter-svc\.nytimes\.com\/meter\.js.+|.+mwcm\.nyt\.com\/.+\.js)/, +'nzherald.co.nz': /nzherald\.co\.nz\/.+\/headjs\/.+\.js/, +'spectator.co.uk': /.+\.tinypass\.com\/.+/, +'theglobeandmail.com': /theglobeandmail\.com\/pb\/resources\/scripts\/build\/chunk-bootstraps\/.+\.js/, +'thenation.com': /thenation\.com\/.+\/paywall-script\.php/ }; const userAgentDesktop = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" @@ -109,28 +110,17 @@ const userAgentMobile = "Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible ; var enabledSites = []; -// Get the enabled sites -browser.storage.sync.get({ +// Get the enabled sites (from local storage) & add to allow/remove_cookies (if not already in one of these arrays) +chrome.storage.sync.get({ sites: {} }, function(items) { var sites = items.sites; enabledSites = Object.keys(items.sites).map(function(key) { return items.sites[key]; }); -}); - -var loadSites = []; - -// Load the sites (from local storage) & add to allow/remove_cookies (if not already in one of these arrays) -browser.storage.sync.get({ - sites: {} -}, function(items) { - var sites = items.sites; - loadSites = Object.keys(items.sites).map(function(key) { - return items.sites[key]; - }); - for (var domainIndex in loadSites) { - var domainVar = loadSites[domainIndex]; + enabledSites = enabledSites.filter(function(el) { return (el !== '###'); }); + for (var domainIndex in enabledSites) { + var domainVar = enabledSites[domainIndex]; if (!allow_cookies.includes(domainVar) && !remove_cookies.includes(domainVar)) { allow_cookies.push(domainVar); remove_cookies.push(domainVar); diff --git a/manifest.json b/manifest.json index 7611ecf..3b2e31f 100644 --- a/manifest.json +++ b/manifest.json @@ -44,5 +44,5 @@ "webRequest", "webRequestBlocking" ], - "version": "1.6.3.5" + "version": "1.6.3.6" } \ No newline at end of file diff --git a/options.js b/options.js index 13a812a..72b33b0 100644 --- a/options.js +++ b/options.js @@ -73,7 +73,7 @@ function renderOptions_default() { inputEl.dataset.key = key; inputEl.dataset.value = value; inputEl.checked = (key in sites) || (key.replace(/\s\(.*\)/, '') in sites); - if (value !=='') { + if (value !=='###') { labelEl.appendChild(inputEl); } labelEl.appendChild(document.createTextNode(' '+key)); diff --git a/sites.json b/sites.json index 67f8442..b65263d 100644 --- a/sites.json +++ b/sites.json @@ -100,7 +100,7 @@ "Vanity Fair": "vanityfair.com", "Vrij Nederland": "vn.nl", "Wired": "wired.com", - "——— Block Paywall-scripts ———": "", + "——— Block Paywall-scripts ———": "###", "Poool.fr": "poool.fr", "TinyPass": "tinypass.com", "Piano.io": "piano.io" diff --git a/sites_custom.json b/sites_custom.json index b2c3d32..7a928d9 100644 --- a/sites_custom.json +++ b/sites_custom.json @@ -1,3 +1,3 @@ { - "——— Custom Sites (updates) ——": "" + "——— Custom Sites (updates) ——": "###" } \ No newline at end of file diff --git a/updates.json b/updates.json index 9c08852..5ea8aa1 100644 --- a/updates.json +++ b/updates.json @@ -6,8 +6,9 @@ { "version": "1.6.3.3", "update_link": "https://github.com/magnolia1234/bypass-paywalls-firefox-clean/releases/download/v1.6.3.3/bypass_paywalls_clean-1.6.3.3-an+fx.xpi" }, { "version": "1.6.3.5", - "update_link": "https://github.com/magnolia1234/bypass-paywalls-firefox-clean/releases/download/v1.6.3.5/bypass_paywalls_clean-1.6.3.5-an+fx.xpi" } - + "update_link": "https://github.com/magnolia1234/bypass-paywalls-firefox-clean/releases/download/v1.6.3.5/bypass_paywalls_clean-1.6.3.5-an+fx.xpi" }, + { "version": "1.6.3.6", + "update_link": "https://github.com/magnolia1234/bypass-paywalls-firefox-clean/releases/download/v1.6.3.6/bypass_paywalls_clean-1.6.3.6-an+fx.xpi" } ] } }