From f1493a5c768a961030b077b1bac2d5052b78aa1d Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Thu, 12 Jan 2023 19:18:09 +0100 Subject: [PATCH] Update custom sites (default block cookies) --- README.md | 18 +++++++++++++++--- background.js | 2 +- changelog.txt | 1 + contentScript.js | 22 +++++++++++++--------- contentScript_once.js | 4 ++++ custom/sites_custom.json | 22 ++++++++++++++++++---- manifest.json | 2 +- options/clearCookies.js | 8 ++++++++ options/options_custom.html | 4 ++-- options/options_custom.js | 7 +++++++ sites.js | 4 ++-- 11 files changed, 72 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 65d5302..b1ee896 100644 --- a/README.md +++ b/README.md @@ -867,8 +867,20 @@ Add your own custom site (also for testing). Check 'Options'-link in popup-menu and go to custom sites. \* by default BPC has limited permissions, but you can opt-in to enable custom sites (and also clear cookies/block general paywall-scripts for non-listed sites). You can also just request permissions for the custom sites you added yourself (or `clear cookies` (BPC-icon) to ask for permission for current site). -By default sites' cookies/local storage are removed after page loads (to bypass article limit). -Also you can enable Googlebot/Bingbot user-agent, set referer (to Facebook, Google or Twitter; ignored when Googlebot is set), set random ip-address, disable Javascript for (sub)domain(s) and/or external domains, block regular expression, unhide text on (or when paywall(selector) redirect to) amp-page and/or load text from json or Google webcache (paywall|article selector). +By default sites' cookies/local storage are blocked/removed (for example to bypass article limit when metered paywall). + +Additional custom options: +* allow/remove cookies (no options selected: cookies are blocked) +* set useragent to Googlebot, Bingbot or Facebookbot +* set referer (to Facebook, Google or Twitter; ignored when Googlebot is set) +* set random ip-address +* disable Javascript for (sub)domain(s), external domains (when host permission) and/or inline scripts +* block regular expression (to block specific script and/or xhr) +* unhide text amp-page +* redirect to amp-page when paywall(selector) +* load text from json when paywall|article(selector) +* load text from Google webcache when paywall|article(selector) +* remove/unhide elements in dom (optional for dev; check examples) [Example list of custom sites](https://gitlab.com/magnolia1234/bypass-paywalls-firefox-clean/-/blob/master/custom/sites_custom.json) or [download list (json)](https://gitlab.com/magnolia1234/bypass-paywalls-firefox-clean/-/raw/master/custom/sites_custom.json) @@ -885,7 +897,7 @@ You can also exclude a specific domain which is grouped in options. * [Download the latest version](https://gitlab.com/magnolia1234/bypass-paywalls-firefox-clean/-/releases) ### License -Bypass Paywalls Clean is [MIT-licensed](https://gitlab.com/magnolia1234/bypass-paywalls-firefox-clean/-/blob/master/LICENSE). +* Bypass Paywalls Clean is [MIT-licensed](https://gitlab.com/magnolia1234/bypass-paywalls-firefox-clean/-/blob/master/LICENSE). ### Disclaimer * This software is provided for educational purposes only and is provided "AS IS", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software. diff --git a/background.js b/background.js index 1272818..ce30838 100644 --- a/background.js +++ b/background.js @@ -234,7 +234,7 @@ function set_rules(sites, sites_updated, sites_custom) { custom = true; } } - addCookieRules(rule, custom || custom_in_group); + addCookieRules(rule); if (rule.allow_cookies > 0 && !allow_cookies.includes(domain)) allow_cookies.push(domain); diff --git a/changelog.txt b/changelog.txt index 533a535..94e63d6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -7,6 +7,7 @@ Fix LesEchos.fr (investir) Fix National Review (no amp) Fix The Athletic (error) Remove Repubblica.it (fix obsolete) +Update custom sites (default block cookies) * v3.0.0.0 (2023-01-08) Add Deutscher Fachverlag Mediengruppe (opt-in to custom sites) diff --git a/contentScript.js b/contentScript.js index 359fc73..298155f 100644 --- a/contentScript.js +++ b/contentScript.js @@ -2745,19 +2745,23 @@ else if (matchDomain('bqprime.com')) { if (window.location.pathname.startsWith('/amp/')) { amp_unhide_subscr_section('.ad-container'); } else { - if (!window.location.search.startsWith('?rel=geo_block')) { - window.setTimeout(function () { - let geo_block = document.querySelector('div[class*="geotag-container_"]'); + window.setTimeout(function () { + let geo_block = document.querySelector('div[class*="geotag-container_"]'); + if (!window.location.search.startsWith('?rel=geo_block')) { if (geo_block) { removeDOMElement(geo_block); window.location.href = window.location.pathname + '?rel=geo_block'; } - }, 1000); - } else { - let hidden_images = document.querySelectorAll('img[src^="data:image/"][data-src]'); - for (let elem of hidden_images) - elem.setAttribute('src', elem.getAttribute('data-src')); - } + } else { + if (geo_block) + refreshCurrentTab(); + else { + let hidden_images = document.querySelectorAll('img[src^="data:image/"][data-src]'); + for (let elem of hidden_images) + elem.setAttribute('src', elem.getAttribute('data-src')); + } + } + }, 1000); } let ads = document.querySelectorAll('.responsive-ad'); removeDOMElement(...ads); diff --git a/contentScript_once.js b/contentScript_once.js index c37f37d..5cb8d65 100644 --- a/contentScript_once.js +++ b/contentScript_once.js @@ -133,11 +133,15 @@ function getCookieDomain(hostname) { let n = 0; let parts = hostname.split('.'); let str = '_gd' + (new Date()).getTime(); + try { while (n < (parts.length - 1) && document.cookie.indexOf(str + '=' + str) == -1) { domain = parts.slice(-1 - (++n)).join('.'); document.cookie = str + "=" + str + ";domain=" + domain + ";"; } document.cookie = str + "=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=" + domain + ";"; + } catch (e) { + console.log(e); + } return domain; } diff --git a/custom/sites_custom.json b/custom/sites_custom.json index 7455ad5..fa543ce 100644 --- a/custom/sites_custom.json +++ b/custom/sites_custom.json @@ -1,4 +1,9 @@ { + "Abajournal.com": { + "allow_cookies": 1, + "block_regex": "\\.piano\\.io", + "domain": "abajournal.com" + }, "Arkansasonline.com": { "domain": "arkansasonline.com" }, @@ -105,6 +110,11 @@ "block_regex": "\\.tinypass\\.com", "domain": "fastcompany.com" }, + "Finansavisen.no": { + "allow_cookies": 1, + "domain": "finansavisen.no", + "useragent": "googlebot" + }, "Finanz-szene.de": { "allow_cookies": 1, "domain": "finanz-szene.de", @@ -185,6 +195,11 @@ "domain": "kaleva.fi", "useragent": "googlebot" }, + "Kapital.no": { + "allow_cookies": 1, + "domain": "kapital.no", + "useragent": "googlebot" + }, "Lindipendente.online": { "allow_cookies": 1, "domain": "lindipendente.online", @@ -219,7 +234,9 @@ "domain": "marketscreener.com" }, "Medpagetoday.com": { - "domain": "medpagetoday.com" + "allow_cookies": 1, + "domain": "medpagetoday.com", + "remove_cookies": 1 }, "Milesplit.com": { "allow_cookies": 1, @@ -330,9 +347,6 @@ "amp_redirect": "div#story-notification", "domain": "swarajyamag.com" }, - "The-japan-news.com": { - "domain": "the-japan-news.com" - }, "The-past.com": { "domain": "the-past.com" }, diff --git a/manifest.json b/manifest.json index f0b6eb1..4abfe82 100644 --- a/manifest.json +++ b/manifest.json @@ -720,5 +720,5 @@ "*://*.wallkit.net/*", "*://webcache.googleusercontent.com/*" ], - "version": "3.0.0.4" + "version": "3.0.0.5" } diff --git a/options/clearCookies.js b/options/clearCookies.js index 817d2c1..ed55134 100644 --- a/options/clearCookies.js +++ b/options/clearCookies.js @@ -1,7 +1,11 @@ var ext_api = (typeof browser === 'object') ? browser : chrome; +try { window.localStorage.clear(); sessionStorage.clear(); +} catch (e) { + console.log(e); +} var cookie_domain = getCookieDomain(document.domain); @@ -18,11 +22,15 @@ function getCookieDomain(hostname) { let n = 0; let parts = hostname.split('.'); let str = '_gd' + (new Date()).getTime(); + try { while (n < (parts.length - 1) && document.cookie.indexOf(str + '=' + str) == -1) { domain = parts.slice(-1 - (++n)).join('.'); document.cookie = str + "=" + str + ";domain=" + domain + ";"; } document.cookie = str + "=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=" + domain + ";"; + } catch (e) { + console.log(e); + } return domain; } diff --git a/options/options_custom.html b/options/options_custom.html index b574108..d566587 100644 --- a/options/options_custom.html +++ b/options/options_custom.html @@ -10,8 +10,8 @@

Custom Sites

To add a new site, enter an unique title/domain (without www.).
- Select options for useragent (like Googlebot), set referer (ignored when Googlebot is set), set random ip-address, block Javascript, block regular expression, unhide text on amp-page (or redirect to it) and/or load text from json or Google webcache (paywall|article selector); for examples import from GitLab.
- Custom sites (new) are enabled automatically in (cookies will be removed by default unless you enable allow_cookies).
+ Select options below (see GitLab help; for examples import from GitLab.
+ Custom sites (new) are enabled automatically in (cookies will be blocked by default unless you enable allow_cookies).
If you want to use custom sites (for non-listed sites) enable it in Custom sites enabled:
You can also just request permissions for the custom sites & post-release added sites (below).
diff --git a/options/options_custom.js b/options/options_custom.js index 9bc04ea..63776e7 100644 --- a/options/options_custom.js +++ b/options/options_custom.js @@ -171,6 +171,8 @@ function delete_options() { var selectEl = document.querySelector('#custom_sites select'); var sites_custom = {}; var remove_key = selectEl.value; + if (!remove_key) + return false; // delete site from local storage ext_api.storage.local.get({ @@ -198,6 +200,8 @@ function edit_options() { var selectEl = document.querySelector('#custom_sites select'); var sites_custom = {}; var title = selectEl.value; + if (!title) + return false; // copy site to add-fields ext_api.storage.local.get({ @@ -209,6 +213,7 @@ function edit_options() { document.querySelector('input[data-key="domain"]').value = edit_site.domain; document.querySelector('select[data-key="useragent"]').selectedIndex = (edit_site.googlebot > 0) ? 1 : useragent_options.indexOf(edit_site.useragent); document.querySelector('input[data-key="allow_cookies"]').checked = (edit_site.allow_cookies > 0); + document.querySelector('input[data-key="remove_cookies"]').checked = (edit_site.remove_cookies > 0); document.querySelector('input[data-key="block_js"]').checked = (edit_site.block_js > 0 || edit_site.block_javascript > 0); document.querySelector('input[data-key="block_js_ext"]').checked = (edit_site.block_js_ext > 0 || edit_site.block_javascript_ext > 0); document.querySelector('input[data-key="block_js_inline"]').value = edit_site.block_js_inline ? edit_site.block_js_inline : ''; @@ -277,6 +282,7 @@ function renderOptions() { 'title': 0, 'domain': 0, 'allow_cookies': 1, + 'remove_cookies': 1, 'block_js (domain)': 1, 'block_js_ext': 1, 'block_js_inline': 0, @@ -359,6 +365,7 @@ function renderOptions() { optionEl.text += key + ': ' + domain + (sites_custom[key]['googlebot'] > 0 ? ' | googlebot' : '') + (sites_custom[key]['allow_cookies'] > 0 ? ' | allow_cookies' : '') + + (sites_custom[key]['remove_cookies'] > 0 ? ' | remove_cookies' : '') + ((sites_custom[key]['block_js'] > 0 || sites_custom[key]['block_javascript'] > 0) ? ' | block_js' : '') + ((sites_custom[key]['block_js_ext'] > 0 || sites_custom[key]['block_javascript_ext'] > 0) ? ' | block_js_ext' : '') + (sites_custom[key]['block_js_inline'] ? ' | block_js_inline' : '') + diff --git a/sites.js b/sites.js index 366aee3..c8c9013 100644 --- a/sites.js +++ b/sites.js @@ -2335,8 +2335,8 @@ var defaultSites_groups_domains = [].concat.apply([], Object.values(defaultSites }).map(x => x.group)); var defaultSites_domains = defaultSites_grouped_domains.concat(defaultSites_groups_domains); -function addCookieRules(rule, custom) { - if (rule.hasOwnProperty('remove_cookies_select_drop') || rule.hasOwnProperty('remove_cookies_select_hold') || (custom && !rule.hasOwnProperty('allow_cookies'))) { +function addCookieRules(rule) { + if (rule.hasOwnProperty('remove_cookies_select_drop') || rule.hasOwnProperty('remove_cookies_select_hold')) { rule.allow_cookies = 1; rule.remove_cookies = 1; }