From f5911a88c0a174aef447faf7b68483bacc4707fc Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Tue, 5 Jan 2021 18:53:46 +0100 Subject: [PATCH] Update options (excluded sites) --- README.md | 5 +++ background.js | 92 ++++++++++++++++++++++++++++--------------- changelog.txt | 1 + manifest.json | 2 +- options.html | 2 + options.js | 30 +++++++++++--- options_excluded.html | 43 ++++++++++++++++++++ options_excluded.js | 52 ++++++++++++++++++++++++ sites.js | 6 +-- 9 files changed, 192 insertions(+), 41 deletions(-) create mode 100644 options_excluded.html create mode 100644 options_excluded.js diff --git a/README.md b/README.md index dd14e47..dbce981 100755 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ * [Sites with limited number of free articles](#sites-with-limited-number-of-free-articles) * [New site requests](#new-site-requests) * [Add custom site](#add-custom-site) +* [Add excluded site](#add-excluded-site) * [Troubleshooting](#troubleshooting) * [Changelog-releases](#changelog-releases) * [License](#license) @@ -511,6 +512,10 @@ Make sure the (new) site is checked under Options (or check on/off-button). By default sites' cookies/local storage are removed after page loads (to bypass article limit). Also you can enable Googlebot user-agent or disable Javascript for (sub)domain(s)/external sources. +### Add excluded site +Add excluded sites/domains (for your subscriptions).\ +You can also exclude a specific domain which is grouped in options. + ### Troubleshooting * This extension works best alongside [uBlock Origin](https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm). * If a site doesn't work, try turning off uBlock and refreshing. diff --git a/background.js b/background.js index 5baa208..ebf03eb 100755 --- a/background.js +++ b/background.js @@ -132,7 +132,6 @@ const remove_cookies_select_hold = { // select only specific cookie(s) to drop from remove_cookies domains var remove_cookies_select_drop = { - 'ad.nl': ['temptationTrackingId'], 'caixinglobal.com': ['CAIXINGLB_LOGIN_UUID'], 'dn.se': ['randomSplusId'], 'fd.nl': ['socialread'], @@ -227,7 +226,6 @@ var blockedRegexes = { 'haaretz.com': /haaretz\.com\/hdc\/web\/js\/minified\/header-scripts-int.js.+/, 'hbr.org': /cdn\.tinypass\.com\/.+/, 'historyextra.com': /.+\.evolok\.net\/.+\/authorize\/.+/, - 'ilmessaggero.it': /utils\.cedsdigital\.it\/js\/PaywallMeter\.js/, 'ilrestodelcarlino.it': /cdn\.tinypass\.com\/.+/, 'independent.ie': /(cdn\.flip-pay\.com\/clients\/inm\/flip-pay\.js|cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js)/, 'inquirer.com': /cdn\.tinypass\.com\/.+/, @@ -298,9 +296,9 @@ const fi_alma_talent_domains = ['arvopaperi.fi', 'kauppalehti.fi', 'marmai.fi', const fr_be_groupe_rossel_domains = ['aisnenouvelle.fr', 'courrier-picard.fr', 'lardennais.fr', 'lavoixdunord.fr', 'lecho.be', 'lesoir.be', 'lest-eclair.fr', 'liberation-champagne.fr', 'lunion.fr', 'nordeclair.fr', 'paris-normandie.fr', 'sudinfo.be']; const fr_groupe_ebra_domains = ['bienpublic.com', 'dna.fr', 'estrepublicain.fr', 'lalsace.fr', 'ledauphine.com', 'lejsl.com', 'leprogres.fr', 'republicain-lorrain.fr', 'vosgesmatin.fr']; const fr_groupe_la_depeche_domains = ['centrepresseaveyron.fr', 'ladepeche.fr', 'lindependant.fr', 'midi-olympique.fr', 'midilibre.fr', 'nrpyrenees.fr', 'petitbleu.fr']; -const it_ilmessaggero_domains = ['corriereadriatico.it', 'ilgazzettino.it', 'ilmattino.it', 'quotidianodipuglia.it']; -const nl_ad_region_domains = ['bd.nl', 'ed.nl', 'tubantia.nl', 'bndestem.nl', 'pzc.nl', 'destentor.nl', 'gelderlander.nl']; -const nymag_domains = ['grubstreet.com', 'thecut.com', 'vulture.com']; +const it_ilmessaggero_domains = ['corriereadriatico.it', 'ilgazzettino.it', 'ilmattino.it', 'ilmessaggero.it', 'quotidianodipuglia.it']; +const nl_ad_region_domains = ['ad.nl', 'bd.nl', 'ed.nl', 'tubantia.nl', 'bndestem.nl', 'pzc.nl', 'destentor.nl', 'gelderlander.nl']; +const usa_nymag_domains = ['grubstreet.com', 'nymag.com', 'thecut.com', 'vulture.com']; // grouped domains (rules only) const au_nine_domains = ['brisbanetimes.com.au', 'smh.com.au', 'theage.com.au', 'watoday.com.au']; @@ -315,9 +313,10 @@ const userAgentMobileB = "Chrome/80.0.3987.92 Mobile Safari/537.36 (compatible; var enabledSites = []; var disabledSites = []; var defaultSites_grouped_domains = Object.values(defaultSites); -var defaultSites_domains = defaultSites_grouped_domains.concat(au_comm_media_domains, au_news_corp_domains, au_prov_news_domains, de_funke_media_domains, de_madsack_domains, es_grupo_vocento_domains, fi_alma_talent_domains, fr_be_groupe_rossel_domains, fr_groupe_ebra_domains, fr_groupe_la_depeche_domains, it_ilmessaggero_domains, nl_ad_region_domains, nymag_domains); +var defaultSites_domains = defaultSites_grouped_domains.concat(au_comm_media_domains, au_news_corp_domains, au_prov_news_domains, de_funke_media_domains, de_madsack_domains, es_grupo_vocento_domains, fi_alma_talent_domains, fr_be_groupe_rossel_domains, fr_groupe_ebra_domains, fr_groupe_la_depeche_domains, it_ilmessaggero_domains, nl_ad_region_domains, usa_nymag_domains); var customSites = {}; var customSites_domains = []; +var excludedSites = []; function setDefaultOptions() { ext_api.storage.local.set({ @@ -361,9 +360,9 @@ var grouped_sites = { '###_fr_be_groupe_rossel': fr_be_groupe_rossel_domains, '###_fr_groupe_ebra': fr_groupe_ebra_domains, '###_fr_groupe_la_depeche': fr_groupe_la_depeche_domains, -'ad.nl': nl_ad_region_domains, -'ilmessaggero.it': it_ilmessaggero_domains, -'nymag.com': nymag_domains +'###_it_ilmessaggero': it_ilmessaggero_domains, +'###_nl_ad_region': nl_ad_region_domains, +'###_usa_nymag': usa_nymag_domains }; function add_grouped__enabled_domains(groups) { @@ -372,6 +371,12 @@ function add_grouped__enabled_domains(groups) { enabledSites = enabledSites.concat(groups[key]); else disabledSites = disabledSites.concat(groups[key]); + for (let site of excludedSites) { + if (enabledSites.includes(site)) { + enabledSites.splice(enabledSites.indexOf(site), 1); + disabledSites.push(site); + } + } } } @@ -433,10 +438,12 @@ function add_grouped_sites(init_rules) { // Add googlebot- and block_javascript-settings for custom sites ext_api.storage.local.get({ sites: {}, - sites_custom: {} + sites_custom: {}, + sites_excluded: [] }, function (items) { var sites = items.sites; var sites_custom = items.sites_custom; + excludedSites = items.sites_excluded; for (let key in sites_custom) { var domainVar = sites_custom[key]['domain'].toLowerCase(); @@ -458,7 +465,7 @@ ext_api.storage.local.get({ customSites = sites_custom; customSites_domains = Object.values(sites_custom).map(x => x.domain); disabledSites = defaultSites_domains.concat(customSites_domains).filter(x => !enabledSites.includes(x) && x !== '###'); - add_grouped_sites(true); + add_grouped_sites(true); //and exclude sites for (let domainVar of enabledSites) { if (!allow_cookies.includes(domainVar) && !remove_cookies.includes(domainVar)) { @@ -491,9 +498,6 @@ ext_api.storage.onChanged.addListener(function (changes, namespace) { remove_cookies.push(domainVar); } } - // reset disableJavascriptOnListedSites eventListener - ext_api.webRequest.onBeforeRequest.removeListener(disableJavascriptOnListedSites); - ext_api.webRequest.handlerBehaviorChanged(); } if (key === 'sites_custom') { var sites_custom = storageChange.newValue ? storageChange.newValue : {}; @@ -555,11 +559,33 @@ ext_api.storage.onChanged.addListener(function (changes, namespace) { block_js_custom_ext.push(domainVar); } } - - // reset disableJavascriptOnListedSites eventListener - ext_api.webRequest.onBeforeRequest.removeListener(disableJavascriptOnListedSites); - ext_api.webRequest.handlerBehaviorChanged(); } + if (key === 'sites_excluded') { + var sites_excluded = storageChange.newValue ? storageChange.newValue : []; + var sites_excluded_old = storageChange.oldValue ? storageChange.oldValue : []; + excludedSites = sites_excluded; + + // add/remove excluded sites in en/disabledSites + var sites_excluded_added = sites_excluded.filter(x => !sites_excluded_old.includes(x)); + var sites_excluded_removed = sites_excluded_old.filter(x => !sites_excluded.includes(x)); + + for (let site of sites_excluded_added) { + if (enabledSites.includes(site)) { + enabledSites.splice(enabledSites.indexOf(site), 1); + disabledSites.push(site); + } + } + for (let site of sites_excluded_removed) { + if (disabledSites.includes(site)) { + disabledSites.splice(disabledSites.indexOf(site), 1); + enabledSites.push(site); + } + } + } + // reset disableJavascriptOnListedSites eventListener + ext_api.webRequest.onBeforeRequest.removeListener(disableJavascriptOnListedSites); + ext_api.webRequest.handlerBehaviorChanged(); + // Refresh the current tab ext_api.tabs.query({ active: true, @@ -967,19 +993,23 @@ function site_switch() { } function popup_show_toggle_tab(callback) { - ext_api.tabs.query({ - active: true, - currentWindow: true - }, function (tabs) { - if (tabs.length > 0 && tabs[0].url && tabs[0].url.indexOf("http") !== -1) { - let currentUrl = tabs[0].url; - let isDefaultSiteGrouped = matchUrlDomain(defaultSites_domains, currentUrl); - let isDefaultSite = matchUrlDomain(defaultSites_domains, currentUrl); - let isCustomSite = matchUrlDomain(Object.values(customSites_domains), currentUrl); - let domain = isDefaultSiteGrouped || (!isDefaultSite && isCustomSite); - callback(domain); - } - }); + ext_api.tabs.query({ + active: true, + currentWindow: true + }, function (tabs) { + if (tabs.length > 0 && tabs[0].url && tabs[0].url.indexOf("http") !== -1) { + let currentUrl = tabs[0].url; + let domain; + let isExcludedSite = matchUrlDomain(excludedSites, currentUrl); + if (!isExcludedSite) { + let isDefaultSiteGrouped = matchUrlDomain(defaultSites_domains, currentUrl); + let isDefaultSite = matchUrlDomain(defaultSites_domains, currentUrl); + let isCustomSite = matchUrlDomain(Object.values(customSites_domains), currentUrl); + domain = isDefaultSiteGrouped || (!isDefaultSite && isCustomSite); + } + callback(domain); + } + }); }; // remove cookies after page load diff --git a/changelog.txt b/changelog.txt index 25c2973..b8f911c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ Changelog Bypass Paywalls Clean - Chrome Post-release +Update options (excluded sites) * v2.0.2.0 (2021-01-03) Add La Vanguardia (Spain) diff --git a/manifest.json b/manifest.json index c690c48..19f7e5a 100755 --- a/manifest.json +++ b/manifest.json @@ -402,5 +402,5 @@ "*://*.repstatic.it/*", "*://*.userzoom.com/*" ], - "version": "2.0.2.0" + "version": "2.0.2.1" } \ No newline at end of file diff --git a/options.html b/options.html index 3d14b06..4d4c299 100644 --- a/options.html +++ b/options.html @@ -28,6 +28,7 @@
+
@@ -41,6 +42,7 @@ + diff --git a/options.js b/options.js index e137561..69e7c68 100755 --- a/options.js +++ b/options.js @@ -21,6 +21,9 @@ function save_options() { // Update status to let user know options were saved. var status = document.getElementById('status'); status.textContent = 'Options saved.'; + setTimeout(function () { + status.textContent = ''; + }, 800); }); } @@ -28,16 +31,16 @@ function save_options() { function renderOptions() { var labelEl; ext_api.storage.local.get({ - sites: {}, sites_custom: {} + sites: {}, sites_custom: {}, sites_excluded: [] }, function(items) { var sites = items.sites; + var sites_excluded = items.sites_excluded; var sitesEl = document.getElementById('bypass_sites'); var clean_key; for (var key in defaultSites) { if (!defaultSites.hasOwnProperty(key)) { continue; } - var value = defaultSites[key]; labelEl = document.createElement('label'); var inputEl = document.createElement('input'); @@ -45,7 +48,7 @@ function renderOptions() { inputEl.dataset.key = key; inputEl.dataset.value = value; clean_key = key.replace(/\s\(.*\)/, ''); - inputEl.checked = Object.keys(sites).some(title => (title.replace(/\s\(.*\)/, '') === clean_key)); + inputEl.checked = Object.keys(sites).some(title => (title.replace(/\s\(.*\)/, '') === clean_key)) && !sites_excluded.includes(value); if (value !== '###') { labelEl.appendChild(inputEl); } else { @@ -68,28 +71,43 @@ function renderOptions() { if (defaultSites.hasOwnProperty(key) || defaultSites_domains.includes(domain)) { continue; } - labelEl = document.createElement('label'); var inputEl = document.createElement('input'); inputEl.type = 'checkbox'; inputEl.dataset.key = key; inputEl.dataset.value = domain; clean_key = key.replace(/\s\(.*\)/, ''); - inputEl.checked = Object.keys(sites).some(title => (title.replace(/\s\(.*\)/, '') === clean_key)); + inputEl.checked = Object.keys(sites).some(title => (title.replace(/\s\(.*\)/, '') === clean_key)) && !sites_excluded.includes(domain); if (value !== '' && value !== '###') { labelEl.appendChild(inputEl); } labelEl.appendChild(document.createTextNode(' '+key)); sitesEl.appendChild(labelEl); } + // excluded + labelEl.appendChild(document.createElement('hr')); + labelEl = document.createElement('label'); + labelEl.setAttribute('style', ' font-weight: bold;'); + labelEl.appendChild(document.createTextNode('* Excluded Sites (ignored when checked in list)')); + sitesEl.appendChild(labelEl); + labelEl = document.createElement('label'); + labelEl.appendChild(document.createTextNode(sites_excluded.join())); + sitesEl.appendChild(labelEl); + save_options(); }); } function selectAll() { var inputEls = Array.from(document.querySelectorAll('input')); - inputEls.forEach(function(inputEl) { + inputEls.forEach(function (inputEl) { inputEl.checked = true; }); + // Update status to let user know all sites are selected. + var status = document.getElementById('status'); + status.textContent = 'All sites selected.'; + setTimeout(function () { + status.textContent = ''; + }, 800); } function selectNone() { diff --git a/options_excluded.html b/options_excluded.html new file mode 100644 index 0000000..a1f309e --- /dev/null +++ b/options_excluded.html @@ -0,0 +1,43 @@ + + + + + + Bypass Paywalls Clean Options Excluded + + + +

Excluded Sites

+
+ Add excluded sites/domains (for your subscriptions) as a comma-separated list (www.-prefix and spaces are removed).
+ You can also exclude a specific domain which is grouped in options.
+ Checked sites in options are ignored (to still enable select all).
+
+
+
+

Sites

+
+
+
+
+
+
+ + + + + + + + + diff --git a/options_excluded.js b/options_excluded.js new file mode 100644 index 0000000..11408a3 --- /dev/null +++ b/options_excluded.js @@ -0,0 +1,52 @@ +var ext_api = chrome || browser; + +// Saves options to ext_api.storage +function save_options() { + var textareaEl = document.querySelector('#excluded_sites textarea'); + var sites_excluded = []; + if (textareaEl.value !== '') + var sites_excluded = textareaEl.value.split(',').map(function(item) { return item.trim().replace('www.', ''); }); + ext_api.storage.local.set({ + sites_excluded: sites_excluded + }, function () { + // Update status to let user know excluded sites were saved. + var status = document.getElementById('status'); + status.textContent = 'Excluded sites saved.'; + }); +} + +// Sort json by key in textarea +function sort_options() { + var textareaEl = document.querySelector('#excluded_sites textarea'); + var sites_excluded = []; + if (textareaEl.value !== '') { + var sites_excluded = textareaEl.value.split(',').map(function(item) { return item.trim().replace('www.', ''); }); + var sites_excluded_sorted = sites_excluded.sort(); + textareaEl.value = sites_excluded_sorted.join(); + } + // Update status to let user know excluded sites were sorted. + var status = document.getElementById('status'); + status.textContent = 'Excluded sites sorted (not saved yet)'; +} + +function renderOptions() { + ext_api.storage.local.get({ + sites_excluded: [] + }, function (items) { + var sites_excluded = items.sites_excluded; + var sitesEl = document.getElementById('excluded_sites'); + sitesEl.innerHTML = ''; + var labelEl = document.createElement('label'); + var textareaEl = document.createElement('textarea'); + textareaEl.placeholder = 'example1.com,example2.com'; + textareaEl.value = sites_excluded.join(); + textareaEl.rows = 12; + textareaEl.cols = 40; + labelEl.appendChild(textareaEl); + sitesEl.appendChild(labelEl); + }); +} + +document.addEventListener('DOMContentLoaded', renderOptions); +document.getElementById('save').addEventListener('click', save_options); +document.getElementById('sort').addEventListener('click', sort_options); \ No newline at end of file diff --git a/sites.js b/sites.js index 68dd4b3..a0fc05f 100755 --- a/sites.js +++ b/sites.js @@ -2,7 +2,7 @@ var defaultSites = { "ABC.es": "abc.es", "Adweek": "adweek.com", - "Algemeen Dagblad (+ regional)": "ad.nl", + "Algemeen Dagblad (+ regional)": "###_nl_ad_region", "Alma Talent (Finland)": "###_fi_alma_talent", "Alternatives Economiques": "alternatives-economiques.fr", "American Affairs": "americanaffairsjournal.org", @@ -90,7 +90,7 @@ var defaultSites = "Humo.be": "humo.be", "Il Fatto Quotidiano": "ilfattoquotidiano.it", "Il Manifesto": "ilmanifesto.it", - "Il Messaggero (+ regional)": "ilmessaggero.it", + "Il Messaggero (+ regional)": "###_it_ilmessaggero", "Il Resto del Carlino": "ilrestodelcarlino.it", "Inc.com": "inc.com", "Inkl": "inkl.com", @@ -138,7 +138,7 @@ var defaultSites = "National Review": "nationalreview.com", "Nautilus": "nautil.us", "Neue Zürcher Zeitung": "nzz.ch", - "New York Magazine (+ Grub Street, The Cut & Vulture)": "nymag.com", + "New York Magazine (+ Grub Street, The Cut & Vulture)": "###_usa_nymag", "New Zealand Herald": "nzherald.co.nz", "Newsweek": "newsweek.com", "Nikkei Asian Review": "asia.nikkei.com",