From 1311b5e56fddd98773993cf5b067c955d1960bac Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Wed, 17 Nov 2021 17:45:33 +0100 Subject: [PATCH] Updated sites: add amp-redirect --- background.js | 9 +++++++++ changelog.txt | 1 + contentScript.js | 27 ++++++++++++++++++++++----- manifest.json | 2 +- options/options_custom.js | 4 ++-- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/background.js b/background.js index d3868a6..a9d6971 100644 --- a/background.js +++ b/background.js @@ -59,6 +59,8 @@ var blockedRegexes = {}; // unhide text on amp-page var amp_unhide; +// redirect to amp-page +var amp_redirect; // custom: block javascript var block_js_custom = []; @@ -76,6 +78,7 @@ function initSetRules() { use_twitter_referer = []; change_headers = []; amp_unhide = []; + amp_redirect = {}; block_js_custom = []; block_js_custom_ext = []; blockedRegexes = {}; @@ -235,6 +238,9 @@ function set_rules(sites, sites_updated, sites_custom) { break; } } + // updated + if (rule.amp_redirect) + amp_redirect[domain] = rule.amp_redirect; // custom if (rule.googlebot > 0) use_google_bot.push(domain); @@ -920,6 +926,9 @@ if (matchUrlDomain(change_headers, details.url) && (!['font', 'image', 'styleshe optin_setcookie: optin_setcookie, amp_unhide: matchUrlDomain(amp_unhide, currentTabUrl) }; + let amp_redirect_domain = ''; + if (amp_redirect_domain = matchUrlDomain(Object.keys(amp_redirect), currentTabUrl)) + bg2csData.amp_redirect = amp_redirect[amp_redirect_domain]; ext_api.tabs.executeScript(tabId, { code: 'var bg2csData = ' + JSON.stringify(bg2csData) + ';' }, function () { diff --git a/changelog.txt b/changelog.txt index de942f8..7717ab4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -5,6 +5,7 @@ Post-release Add Advance Local (local USA) Add Italian.tech Fix Medium (faster) +Updated sites: add amp-redirect * v2.4.4.0 (2021-11-14) Fix Nikkei Asian Review (cookies) diff --git a/contentScript.js b/contentScript.js index 2cdd3ca..c342726 100644 --- a/contentScript.js +++ b/contentScript.js @@ -53,12 +53,29 @@ if ((bg2csData !== undefined) && bg2csData.amp_unhide) { let subscr_section = document.querySelectorAll('[subscriptions-section="content"]'); for (let elem of subscr_section) elem.removeAttribute('subscriptions-section'); + let content_hidden = document.querySelectorAll('[amp-access][amp-access-hide]'); + for (elem of content_hidden) + elem.removeAttribute('amp-access-hide'); + let amp_ads = document.querySelectorAll('amp-ad'); + removeDOMElement(...amp_ads); + } + }, 500); // Delay (in milliseconds) +} + +// updated sites: amp-redirect +if ((bg2csData !== undefined) && bg2csData.amp_redirect) { + window.setTimeout(function () { + let amp_page = document.querySelector('script[src^="https://cdn.ampproject.org/"]'); + if (!amp_page) { + let paywall = true; + if (bg2csData.amp_redirect.paywall) + paywall = document.querySelector(bg2csData.amp_redirect.paywall); + let amphtml = document.querySelector('link[rel="amphtml"]'); + if (paywall && amphtml) { + removeDOMElement(paywall); + window.location.href = amphtml.href; + } } - let content_hidden = document.querySelectorAll('[amp-access][amp-access-hide]'); - for (elem of content_hidden) - elem.removeAttribute('amp-access-hide'); - let amp_ads = document.querySelectorAll('amp-ad'); - removeDOMElement(...amp_ads); }, 500); // Delay (in milliseconds) } diff --git a/manifest.json b/manifest.json index efd3f8a..71e7f92 100644 --- a/manifest.json +++ b/manifest.json @@ -569,5 +569,5 @@ "*://*.wallkit.net/*", "*://*.wsj.net/*" ], - "version": "2.4.4.2" + "version": "2.4.4.3" } \ No newline at end of file diff --git a/options/options_custom.js b/options/options_custom.js index b55cd16..9d92b5b 100644 --- a/options/options_custom.js +++ b/options/options_custom.js @@ -324,9 +324,9 @@ function renderOptions() { labelEl.appendChild(document.createElement('label')); labelEl.appendChild(document.createTextNode('Updated sites: ' + sites_updated_domains_new.join())); custom_sitesEl.appendChild(labelEl); - perm_origins = perm_origins.concat(sites_updated_domains_new).map(x => '*://*.' + x + '/*'); } + perm_origins = perm_origins.concat(sites_updated_domains_new).map(x => '*://*.' + x + '/*'); var perm_custom = document.getElementById('perm-custom'); ext_api.permissions.contains({ origins: perm_origins @@ -337,7 +337,7 @@ function renderOptions() { perm_custom.innerText = 'NO'; } }); - }); + }); var custom_enabled = document.getElementById('custom-enabled'); ext_api.permissions.contains({