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.
This commit is contained in:
magnolia1234 2020-01-15 18:58:10 +01:00 committed by GitHub
parent e738a72650
commit 9cde15f19d
6 changed files with 27 additions and 36 deletions

View file

@ -1,3 +1,5 @@
/* Please respect alphabetical order when adding a site in any list */
'use strict'; 'use strict';
// Cookies from this list are blocked by default (obsolete) // 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 = { 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/, '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\/.+/, 'leparisien.fr': /.+\.tinypass\.com\/.+/,
'lesechos.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)" 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 = []; var enabledSites = [];
// Get the enabled sites // Get the enabled sites (from local storage) & add to allow/remove_cookies (if not already in one of these arrays)
browser.storage.sync.get({ chrome.storage.sync.get({
sites: {} sites: {}
}, function(items) { }, function(items) {
var sites = items.sites; var sites = items.sites;
enabledSites = Object.keys(items.sites).map(function(key) { enabledSites = Object.keys(items.sites).map(function(key) {
return items.sites[key]; return items.sites[key];
}); });
}); enabledSites = enabledSites.filter(function(el) { return (el !== '###'); });
for (var domainIndex in enabledSites) {
var loadSites = []; var domainVar = enabledSites[domainIndex];
// 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];
if (!allow_cookies.includes(domainVar) && !remove_cookies.includes(domainVar)) { if (!allow_cookies.includes(domainVar) && !remove_cookies.includes(domainVar)) {
allow_cookies.push(domainVar); allow_cookies.push(domainVar);
remove_cookies.push(domainVar); remove_cookies.push(domainVar);

View file

@ -44,5 +44,5 @@
"webRequest", "webRequest",
"webRequestBlocking" "webRequestBlocking"
], ],
"version": "1.6.3.5" "version": "1.6.3.6"
} }

View file

@ -73,7 +73,7 @@ function renderOptions_default() {
inputEl.dataset.key = key; inputEl.dataset.key = key;
inputEl.dataset.value = value; inputEl.dataset.value = value;
inputEl.checked = (key in sites) || (key.replace(/\s\(.*\)/, '') in sites); inputEl.checked = (key in sites) || (key.replace(/\s\(.*\)/, '') in sites);
if (value !=='') { if (value !=='###') {
labelEl.appendChild(inputEl); labelEl.appendChild(inputEl);
} }
labelEl.appendChild(document.createTextNode(' '+key)); labelEl.appendChild(document.createTextNode(' '+key));

View file

@ -100,7 +100,7 @@
"Vanity Fair": "vanityfair.com", "Vanity Fair": "vanityfair.com",
"Vrij Nederland": "vn.nl", "Vrij Nederland": "vn.nl",
"Wired": "wired.com", "Wired": "wired.com",
"——— Block Paywall-scripts ———": "", "——— Block Paywall-scripts ———": "###",
"Poool.fr": "poool.fr", "Poool.fr": "poool.fr",
"TinyPass": "tinypass.com", "TinyPass": "tinypass.com",
"Piano.io": "piano.io" "Piano.io": "piano.io"

View file

@ -1,3 +1,3 @@
{ {
"——— Custom Sites (updates) ——": "" "——— Custom Sites (updates) ——": "###"
} }

View file

@ -6,8 +6,9 @@
{ "version": "1.6.3.3", { "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" }, "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", { "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" }
] ]
} }
} }