From be7009a35b87ef7c0536b1954de38774edfec105 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Thu, 19 Jan 2023 08:31:41 +0100 Subject: [PATCH] Fix ET Prime (mobile epaper) --- background.js | 2 +- changelog.txt | 3 ++- contentScript.js | 14 +++++++++++--- custom/sites_custom.json | 5 ----- manifest.json | 2 +- options/popup.js | 41 +++++++++++++++++++++++++++++++--------- 6 files changed, 47 insertions(+), 20 deletions(-) diff --git a/background.js b/background.js index a7e521f..2a0641f 100644 --- a/background.js +++ b/background.js @@ -626,7 +626,7 @@ ext_api.webRequest.onBeforeSendHeaders.addListener(function (details) { // economictimes redirect ext_api.webRequest.onBeforeRequest.addListener(function (details) { - if (!isSiteEnabled(details)) { + if (!isSiteEnabled(details) || details.url.includes('.com/epaper/')) { return; } var updatedUrl = details.url.split('?')[0].replace('economictimes.indiatimes.com', 'm.economictimes.com'); diff --git a/changelog.txt b/changelog.txt index 872fd5f..7c2f5f2 100644 --- a/changelog.txt +++ b/changelog.txt @@ -4,6 +4,7 @@ Changelog Bypass Paywalls Clean - Firefox Post-release Add Cellesche Zeitung Add DvhN.nl +Fix ET Prime (mobile epaper) Fix Fd.nl (search) Fix Statista (outlook) Fix StuDocu @@ -20,7 +21,7 @@ Fix Vogue Business Remove Repubblica.it (fix obsolete) Remove Republic.ru (fix obsolete) Update custom sites (default block cookies) -Update popup (Google Mobile-Friendly tool) +Update popup (Google Search Tool) * 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 4ff8afe..e59d49b 100644 --- a/contentScript.js +++ b/contentScript.js @@ -275,7 +275,7 @@ else { comments = document.querySelector('#story-comments, .comments-wrapper'); } else if (window.location.search.match(/(\?|&)amp/)) { amp_unhide_subscr_section(amp_ads_sel, true, true, '.newscdn.com.au'); - comments = document.querySelector('#comments-load'); + comments = document.querySelector('#comments-load, .comments-module'); let amp_iframe_sizers = document.querySelectorAll('amp-iframe > i-amphtml-sizer'); removeDOMElement(...amp_iframe_sizers) } @@ -2992,6 +2992,8 @@ else if (matchDomain('economictimes.com')) { let content = document.querySelector('.paywall[style="display:none;"]'); if (content) content.setAttribute('style', 'display:block;'); + else + window.location.href = 'https://economictimes.indiatimes.com' + window.location.pathname.replace('amp_prime', 'prime'); let intro = document.querySelector('.art_wrap'); let article_blocker = document.querySelector('.articleBlocker'); let amp_ads = document.querySelectorAll('amp-ad'); @@ -3002,11 +3004,17 @@ else if (matchDomain('economictimes.com')) { let paywall = document.querySelector('div#blocker_layer'); let data_prime = document.querySelector('div[data-prime="1"]'); let amphtml = document.querySelector('link[rel="amphtml"]'); - if ((paywall || data_prime) && amphtml) { + if (paywall || data_prime) { removeDOMElement(paywall); if (data_prime) data_prime.removeAttribute('data-prime'); - window.location.href = amphtml.href; + if (amphtml) + window.location.href = amphtml.href; + else if (window.location.pathname.startsWith('/epaper/')) + window.location.href = 'https://economictimes.indiatimes.com' + window.location.pathname; + } else { + let ads = document.querySelectorAll('.adContainer'); + removeDOMElement(...ads); } }, 500); } diff --git a/custom/sites_custom.json b/custom/sites_custom.json index 225fae3..54f33f1 100644 --- a/custom/sites_custom.json +++ b/custom/sites_custom.json @@ -190,11 +190,6 @@ "block_regex": "\\.irishexaminer\\.com\\/pu_examiner\\/scripts\\/engage", "domain": "irishexaminer.com" }, - "Kaleva.fi": { - "allow_cookies": 1, - "domain": "kaleva.fi", - "useragent": "googlebot" - }, "Kapital.no": { "allow_cookies": 1, "domain": "kapital.no", diff --git a/manifest.json b/manifest.json index a66cbe7..63dc420 100644 --- a/manifest.json +++ b/manifest.json @@ -723,5 +723,5 @@ "*://*.wallkit.net/*", "*://webcache.googleusercontent.com/*" ], - "version": "3.0.1.4" + "version": "3.0.1.5" } diff --git a/options/popup.js b/options/popup.js index ba375b2..235895b 100644 --- a/options/popup.js +++ b/options/popup.js @@ -62,12 +62,14 @@ function showArchiveLinks() { active: true, currentWindow: true }, function (tabs) { - if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) { - let url = encodeURIComponent(tabs[0].url.split('?')[0]); + if (tabs && tabs[0] && /^http/.test(tabs[0].url)) { + let url = tabs[0].url.split('?')[0]; + let url_enc = encodeURIComponent(url); + let hostname = urlHost(url); let archive_array = { - 'Archive.today': 'https://archive.today?run=1&url=' + url, - 'Google webcache': 'https://webcache.googleusercontent.com/search?q=cache:' + url, - 'Google Mobile-Friendly Tool\n(use online html-viewer - no fix)': 'https://search.google.com/test/mobile-friendly?url=' + url + 'Archive.today': 'https://archive.today?run=1&url=' + url_enc, + 'Google webcache': 'https://webcache.googleusercontent.com/search?q=cache:' + url_enc, + 'Google Search Tool\n(use online html-viewer - no fix)': 'https://search.google.com/test/rich-results?url=' + url_enc }; let archive_id = document.querySelector('span#archive'); if (archive_id) { @@ -76,10 +78,12 @@ function showArchiveLinks() { let elem_div = document.createElement('div'); let elem = document.createElement('a'); elem.innerText = key; - elem.href = archive_array[key]; - elem.target = '_blank'; - elem_div.appendChild(elem); - archive_id.appendChild(elem_div); + if (!(matchDomain(['google.com', 'googleusercontent.com'], hostname) || hostname.match(/^archive\.\w{2}$/))) { + elem.href = archive_array[key]; + elem.target = '_blank'; + elem_div.appendChild(elem); + archive_id.appendChild(elem_div); + } } } } @@ -87,6 +91,25 @@ function showArchiveLinks() { } showArchiveLinks(); +function matchDomain(domains, hostname = window.location.hostname) { + let matched_domain = false; + if (typeof domains === 'string') + domains = [domains]; + domains.some(domain => (hostname === domain || hostname.endsWith('.' + domain)) && (matched_domain = domain)); + return matched_domain; +} + +function urlHost(url) { + if (/^http/.test(url)) { + try { + return new URL(url).hostname; + } catch (e) { + console.log(`url not valid: ${url} error: ${e}`); + } + } + return url; +} + function closeButton() { window.close(); }