From 426db66b686dc680edf6312188a0edb9e99f7c64 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Mon, 1 Aug 2022 20:49:07 +0200 Subject: [PATCH] Update custom sites (load text from Google webcache) --- README.md | 2 +- background.js | 11 ++++++++ changelog.txt | 1 + contentScript.js | 52 +++++++++++++++++++++++++------------ custom/manifest.json | 2 +- manifest.json | 3 +-- options/options_custom.html | 2 +- options/options_custom.js | 10 ++++--- 8 files changed, 59 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 0f87776..4d1ad96 100755 --- a/README.md +++ b/README.md @@ -816,7 +816,7 @@ 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` 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 (paywall|article selector). +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). [Example list of custom sites](https://gitlab.com/magnolia1234/bypass-paywalls-chrome-clean/-/blob/master/custom/sites_custom.json) or [download list (json)](https://gitlab.com/magnolia1234/bypass-paywalls-chrome-clean/-/raw/master/custom/sites_custom.json) diff --git a/background.js b/background.js index e167394..8663302 100755 --- a/background.js +++ b/background.js @@ -70,6 +70,8 @@ var amp_redirect; var cs_code; // load text from json var ld_json; +// load text from Google webcache +var ld_google_webcache; // custom: block javascript var block_js_custom = []; @@ -91,6 +93,7 @@ function initSetRules() { amp_redirect = {}; cs_code = {}; ld_json = {}; + ld_google_webcache = {}; block_js_custom = []; block_js_custom_ext = []; blockedRegexes = {}; @@ -278,6 +281,11 @@ function set_rules(sites, sites_updated, sites_custom) { if (!dompurify_sites.includes(domain)) dompurify_sites.push(domain); } + if (rule.ld_google_webcache) { + ld_google_webcache[domain] = rule.ld_google_webcache; + if (!dompurify_sites.includes(domain)) + dompurify_sites.push(domain); + } } } } @@ -1103,6 +1111,9 @@ if (matchUrlDomain(change_headers, details.url) && !['font', 'image', 'styleshee let ld_json_domain = ''; if (ld_json_domain = matchUrlDomain(Object.keys(ld_json), currentTabUrl)) bg2csData.ld_json = ld_json[ld_json_domain]; + let ld_google_webcache_domain = ''; + if (ld_google_webcache_domain = matchUrlDomain(Object.keys(ld_google_webcache), currentTabUrl)) + bg2csData.ld_google_webcache = ld_google_webcache[ld_google_webcache_domain]; ext_api.tabs.executeScript(tabId, { code: 'var bg2csData = ' + JSON.stringify(bg2csData) + ';' }, function () { diff --git a/changelog.txt b/changelog.txt index 1334a0c..b5f149f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -5,6 +5,7 @@ Post-release Add Tagesspiegel.de Redirect Google AMP cache (opt-in to custom sites) Update block general paywall script (limit Evolok WordPress) +Update custom sites (load text from Google webcache) * v2.7.8.0 (2022-07-31) Add Crusoe (Brazil) diff --git a/contentScript.js b/contentScript.js index ca5a3f2..85ad8d1 100755 --- a/contentScript.js +++ b/contentScript.js @@ -60,24 +60,44 @@ var bg2csData; // custom/updated sites: load text from json if ((bg2csData !== undefined) && bg2csData.ld_json && dompurify_loaded) { if (bg2csData.ld_json.includes('|')) { - let ld_json_split = bg2csData.ld_json.split('|'); - let paywall_sel = ld_json_split[0]; - let article_sel = ld_json_split[1]; - let paywall = document.querySelector(paywall_sel); - if (paywall) { - removeDOMElement(paywall); - let json_script = getArticleJsonScript(); - if (json_script) { - let json_text = parseHtmlEntities(JSON.parse(json_script.text).articleBody); - let content = document.querySelector(article_sel); - if (json_text && content) { - let parser = new DOMParser(); - let doc = parser.parseFromString('
' + DOMPurify.sanitize(json_text) + '
', 'text/html'); - let content_new = doc.querySelector('div'); - content.parentNode.replaceChild(content_new, content); + window.setTimeout(function () { + let ld_json_split = bg2csData.ld_json.split('|'); + let paywall_sel = ld_json_split[0]; + let article_sel = ld_json_split[1]; + let paywall = document.querySelector(paywall_sel); + if (paywall) { + removeDOMElement(paywall); + let json_script = getArticleJsonScript(); + if (json_script) { + let json_text = parseHtmlEntities(JSON.parse(json_script.text).articleBody); + let content = document.querySelector(article_sel); + if (json_text && content) { + let parser = new DOMParser(); + let doc = parser.parseFromString('
' + DOMPurify.sanitize(json_text) + '
', 'text/html'); + let content_new = doc.querySelector('div'); + content.parentNode.replaceChild(content_new, content); + } } } - } + }, 1000); + } +} + +// custom/updated sites: load text from Google webcache +if ((bg2csData !== undefined) && bg2csData.ld_google_webcache && dompurify_loaded) { + if (bg2csData.ld_google_webcache.includes('|')) { + window.setTimeout(function () { + let url = window.location.href; + let ld_google_webcache_split = bg2csData.ld_google_webcache.split('|'); + let paywall_sel = ld_google_webcache_split[0]; + let article_sel = ld_google_webcache_split[1]; + let paywall = document.querySelector(paywall_sel); + if (paywall) { + removeDOMElement(paywall); + let url_cache = 'https://webcache.googleusercontent.com/search?q=cache:' + url; + replaceDomElementExt(url_cache, true, false, article_sel); + } + }, 1000); } } diff --git a/custom/manifest.json b/custom/manifest.json index 3517afe..6103577 100644 --- a/custom/manifest.json +++ b/custom/manifest.json @@ -43,5 +43,5 @@ "webRequestBlocking", "" ], - "version": "2.7.8.1" + "version": "2.7.8.2" } diff --git a/manifest.json b/manifest.json index 9165c9e..5afbdf1 100755 --- a/manifest.json +++ b/manifest.json @@ -655,7 +655,6 @@ "*://*.weborama.fr/*", "*://*.zephr.com/*", "*://*.amazonaws.com/*", - "*://*.apnarm.net.au/*", "*://*.bntech.io/*", "*://*.bwbx.io/*", "*://*.cedsdigital.it/*", @@ -686,5 +685,5 @@ "*://gcm.omerlocdn.com/*", "*://webcache.googleusercontent.com/*" ], - "version": "2.7.8.1" + "version": "2.7.8.2" } diff --git a/options/options_custom.html b/options/options_custom.html index 321ef5e..ebb42e8 100644 --- a/options/options_custom.html +++ b/options/options_custom.html @@ -20,7 +20,7 @@

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 (or when paywall(selector) redirect to) amp-page and/or load text from json (paywall|article selector).
+ 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 (or when paywall(selector) redirect to) amp-page and/or load text from json or Google webcache (paywall|article selector).
Custom sites (new) are enabled automatically in (cookies will be removed by default unless you enable allow_cookies).
If you want to use custom sites (for non-listed sites) enable it in Custom sites enabled:
diff --git a/options/options_custom.js b/options/options_custom.js index 7a87f87..9978aa0 100644 --- a/options/options_custom.js +++ b/options/options_custom.js @@ -215,6 +215,7 @@ function edit_options() { document.querySelector('input[data-key="amp_unhide"]').checked = (edit_site.amp_unhide > 0); document.querySelector('input[data-key="amp_redirect"]').value = edit_site.amp_redirect ? edit_site.amp_redirect : ''; document.querySelector('input[data-key="ld_json"]').value = edit_site.ld_json ? edit_site.ld_json : ''; + document.querySelector('input[data-key="ld_google_webcache"]').value = edit_site.ld_google_webcache ? edit_site.ld_google_webcache : ''; document.querySelector('select[data-key="referer"]').selectedIndex = referer_options.indexOf(edit_site.referer); document.querySelector('select[data-key="random_ip"]').selectedIndex = random_ip_options.indexOf(edit_site.random_ip); }); @@ -279,7 +280,8 @@ function renderOptions() { 'block_regex': 0, 'amp_unhide': 1, 'amp_redirect': 0, - 'ld_json': 0 + 'ld_json': 0, + 'ld_google_webcache': 0 }; for (var key in add_checkboxes) { labelEl = document.createElement('label'); @@ -295,7 +297,8 @@ function renderOptions() { domain: 'example.com', block_regex: '\\.example\\.com\\/js\\/', amp_redirect: 'div.paywall', - ld_json: 'div.paywall|div.article' + ld_json: 'div.paywall|div.article', + ld_google_webcache: 'div.paywall|div.article', }; if (placeholders[key]) inputEl.placeholder = placeholders[key]; @@ -351,7 +354,8 @@ function renderOptions() { (sites_custom[key]['random_ip'] ? ' | random_ip: ' + sites_custom[key]['random_ip'] : '') + (sites_custom[key]['amp_unhide'] > 0 ? ' | amp_unhide' : '') + (sites_custom[key]['amp_redirect'] ? ' | amp_redirect' : '') + - (sites_custom[key]['ld_json'] ? ' | ld_json' : ''); + (sites_custom[key]['ld_json'] ? ' | ld_json' : '') + + (sites_custom[key]['ld_google_webcache'] ? ' | ld_google_webcache' : ''); optionEl.value = key; selectEl.add(optionEl); }