diff --git a/background.js b/background.js index df70d4b..f09b0b2 100644 --- a/background.js +++ b/background.js @@ -533,7 +533,7 @@ ext_api.storage.onChanged.addListener(function (changes, namespace) { } // Refresh the current tab - ext_api.tabs.reload({bypassCache: true}); + refreshCurrentTab(); } }); @@ -752,10 +752,11 @@ if (typeof browser !== 'object') { let lib_file = 'lib/empty.js'; if (matchUrlDomain(dompurify_sites, url)) lib_file = 'lib/purify.min.js'; - var bg2csData = { - optin_setcookie: optin_setcookie, - amp_unhide: matchUrlDomain(amp_unhide, url) - }; + var bg2csData = {}; + if (optin_setcookie && matchUrlDomain(['crusoe.uol.com.br'], url)) + bg2csData.optin_setcookie = 1; + if (matchUrlDomain(amp_unhide, url)) + bg2csData.amp_unhide = 1; let amp_redirect_domain = ''; if (amp_redirect_domain = matchUrlDomain(Object.keys(amp_redirect), url)) bg2csData.amp_redirect = amp_redirect[amp_redirect_domain]; @@ -773,27 +774,29 @@ if (typeof browser !== 'object') { setTimeout(function () { // run contentScript.js on page ext_api.tabs.executeScript(tabId, { - code: 'var bg2csData = ' + JSON.stringify(bg2csData) + ';' + file: lib_file, + runAt: 'document_start' }, function () { ext_api.tabs.executeScript(tabId, { - file: lib_file, + file: 'contentScript.js', runAt: 'document_start' - }, function () { - ext_api.tabs.executeScript(tabId, { - file: 'contentScript.js', - runAt: 'document_start' - }, function (res) { - if (ext_api.runtime.lastError || res[0]) { - return; - } - }) - }); + }, function (res) { + if (ext_api.runtime.lastError || res[0]) { + return; + } + }) }); + // send bg2csData to contentScript.js + if (Object.keys(bg2csData).length) { + setTimeout(function () { + ext_api.tabs.sendMessage(tabId, {msg: "bg2cs", data: bg2csData}); + }, 500); + } // remove cookies after page load if (rc_domain_enabled) { remove_cookies_fn(rc_domain, true); } - }, n * 1000 / tab_runs); + }, n * 200); } } @@ -1510,3 +1513,19 @@ function randomIP(range_low = 0, range_high = 223) { } return rndmIP.join('.'); } + +// Refresh the current tab (http) +function refreshCurrentTab() { + ext_api.tabs.query({ + active: true, + currentWindow: true + }, function (tabs) { + if (tabs && tabs[0] && /^http/.test(tabs[0].url)) { + if (ext_api.runtime.lastError) + return; + ext_api.tabs.update(tabs[0].id, { + url: tabs[0].url + }); + } + }); +} diff --git a/changelog.txt b/changelog.txt index 6644b58..797efb5 100644 --- a/changelog.txt +++ b/changelog.txt @@ -5,6 +5,7 @@ Post-release Fix MIT Sloan Management Review Update block general paywall script (TownNews & fix Pigeon) Update custom flex sites (identify main domain) +Update custom/updated sites (onMessage in contentScript) * v2.9.7.0 (2022-12-11) Add Handelsblatt diff --git a/contentScript.js b/contentScript.js index 1b2a3b9..61145bf 100644 --- a/contentScript.js +++ b/contentScript.js @@ -46,22 +46,9 @@ if (!matchDomain(arr_localstorage_hold)) { window.localStorage.clear(); } -function getArticleJsonScript() { - let scripts = document.querySelectorAll('script[type="application/ld+json"]'); - let json_script; - for (let script of scripts) { - if (script.innerText.match(/"(articleBody|text)":/)) { - json_script = script; - break; - } - } - return json_script; -} - -var bg2csData; - +function runOnMessage(bg2csData, dompurify_loaded, div_bpc_done) { // custom/updated sites: load text from json -if ((bg2csData !== undefined) && bg2csData.ld_json && dompurify_loaded) { +if (bg2csData.ld_json && dompurify_loaded) { if (bg2csData.ld_json.includes('|')) { window.setTimeout(function () { let ld_json_split = bg2csData.ld_json.split('|'); @@ -92,7 +79,7 @@ if ((bg2csData !== undefined) && bg2csData.ld_json && dompurify_loaded) { } // custom/updated sites: load text from Google webcache -if ((bg2csData !== undefined) && bg2csData.ld_google_webcache && dompurify_loaded) { +if (bg2csData.ld_google_webcache && dompurify_loaded) { if (bg2csData.ld_google_webcache.includes('|')) { window.setTimeout(function () { let url = window.location.href; @@ -109,81 +96,18 @@ if ((bg2csData !== undefined) && bg2csData.ld_google_webcache && dompurify_loade } } -var div_bpc_done = document.querySelector('div#bpc_done'); if (!div_bpc_done) { -if (ext_api.runtime) { - ext_api.runtime.onMessage.addListener( - function(request, sender) { - if (request.msg === 'showExtSrc') { - replaceDomElementExtSrc(request.data.url, request.data.html, true, false, request.data.selector, request.data.text_fail, request.data.selector_source); - } - } - ) -} - // check for opt-in confirmation (from background.js) -if ((bg2csData !== undefined) && bg2csData.optin_setcookie) { +if (bg2csData.optin_setcookie) { if (matchDomain(['crusoe.uol.com.br'])) { if (!cookieExists('crs_subscriber')) setCookie('crs_subscriber', 1, 'crusoe.uol.com.br', '/', 14); } } -function amp_iframes_replace(weblink = false, source = '') { - let amp_iframes = document.querySelectorAll('amp-iframe' + (source ? '[src*="'+ source + '"]' : '')); - let par, elem; - for (let amp_iframe of amp_iframes) { - if (!weblink) { - elem = document.createElement('iframe'); - Object.assign(elem, { - src: amp_iframe.getAttribute('src'), - sandbox: amp_iframe.getAttribute('sandbox'), - height: amp_iframe.getAttribute('height'), - width: 'auto', - style: 'border: 0px;' - }); - amp_iframe.parentNode.replaceChild(elem, amp_iframe); - } else { - par = document.createElement('p'); - elem = document.createElement('a'); - elem.innerText = 'Media-link'; - elem.setAttribute('href', amp_iframe.getAttribute('src')); - elem.setAttribute('target', '_blank'); - par.appendChild(elem); - amp_iframe.parentNode.replaceChild(par, amp_iframe); - } - } -} - -function amp_unhide_subscr_section(amp_ads_sel = 'amp-ad, .ad', replace_iframes = true, amp_iframe_link = false, source = '') { - let preview = document.querySelector('[subscriptions-section="content-not-granted"]'); - removeDOMElement(preview); - let subscr_section = document.querySelectorAll('[subscriptions-section="content"]'); - for (let elem of subscr_section) - elem.removeAttribute('subscriptions-section'); - let amp_ads = document.querySelectorAll(amp_ads_sel); - removeDOMElement(...amp_ads); - if (replace_iframes) - amp_iframes_replace(amp_iframe_link, source); -} - -function amp_unhide_access_hide(amp_access = '', amp_access_not = '', amp_ads_sel = 'amp-ad, .ad', replace_iframes = true, amp_iframe_link = false, source = '') { - let access_hide = document.querySelectorAll('[amp-access' + amp_access + '][amp-access-hide]:not([amp-access="error"], [amp-access^="message"])'); - for (let elem of access_hide) - elem.removeAttribute('amp-access-hide'); - if (amp_access_not) { - let amp_access_not_dom = document.querySelectorAll('[amp-access' + amp_access_not + ']'); - removeDOMElement(...amp_access_not_dom); - } - let amp_ads = document.querySelectorAll(amp_ads_sel); - removeDOMElement(...amp_ads); - if (replace_iframes) - amp_iframes_replace(amp_iframe_link, source); -} - // custom/updated sites: try to unhide text on amp-page -if ((bg2csData !== undefined) && bg2csData.amp_unhide) { +if (bg2csData.amp_unhide) { window.setTimeout(function () { let amp_page_hide = document.querySelector('script[src*="/amp-access-"], script[src*="/amp-subscriptions-"]'); if (amp_page_hide) { @@ -195,7 +119,7 @@ if ((bg2csData !== undefined) && bg2csData.amp_unhide) { } // custom/updated sites: amp-redirect -if ((bg2csData !== undefined) && bg2csData.amp_redirect) { +if (bg2csData.amp_redirect) { window.setTimeout(function () { let amp_script = document.querySelector('script[src^="https://cdn.ampproject.org/"]'); let amphtml = document.querySelector('link[rel="amphtml"]'); @@ -236,12 +160,39 @@ function cs_code_elems(elems) { } // updated sites: cs_code -if ((bg2csData !== undefined) && bg2csData.cs_code) { +if (bg2csData.cs_code) { window.setTimeout(function () { cs_code_elems(bg2csData.cs_code); }, 1000); } +} + +}// runOnMessage + +var div_bpc_done = document.querySelector('div#bpc_done'); +var msg_once = false; +if (ext_api.runtime) { + ext_api.runtime.onMessage.addListener( + function (request, sender) { + if (request.msg === 'bg2cs' && !msg_once) { + msg_once = true; + runOnMessage(request.data, dompurify_loaded, div_bpc_done); + } + }) +} + +if (!div_bpc_done) { + +if (ext_api.runtime) { + ext_api.runtime.onMessage.addListener( + function (request, sender) { + if (request.msg === 'showExtSrc') { + replaceDomElementExtSrc(request.data.url, request.data.html, true, false, request.data.selector, request.data.text_fail, request.data.selector_source); + } + }) +} + // Content workarounds/domain if (matchDomain('medium.com') || matchDomain(medium_custom_domains) || document.querySelector('script[src*=".medium.com/"]')) { @@ -677,6 +628,8 @@ else if (matchDomain(['ksta.de', 'rundschau-online.de'])) { if (span_hidden) span_hidden.removeAttribute('class'); } + let banners = document.querySelectorAll('div.dm-slot'); + removeDOMElement(...banners); } else if (matchDomain(['mz.de', 'volksstimme.de'])) { @@ -4376,7 +4329,7 @@ else csDone = true; } -if ((csDone && (bg2csData !== undefined)) || csDoneOnce) { +if (csDone || csDoneOnce) { addDivBpcDone(); } @@ -4514,6 +4467,58 @@ function replaceTextFail(url, article, proxy, text_fail) { } } +function amp_iframes_replace(weblink = false, source = '') { + let amp_iframes = document.querySelectorAll('amp-iframe' + (source ? '[src*="'+ source + '"]' : '')); + let par, elem; + for (let amp_iframe of amp_iframes) { + if (!weblink) { + elem = document.createElement('iframe'); + Object.assign(elem, { + src: amp_iframe.getAttribute('src'), + sandbox: amp_iframe.getAttribute('sandbox'), + height: amp_iframe.getAttribute('height'), + width: 'auto', + style: 'border: 0px;' + }); + amp_iframe.parentNode.replaceChild(elem, amp_iframe); + } else { + par = document.createElement('p'); + elem = document.createElement('a'); + elem.innerText = 'Media-link'; + elem.setAttribute('href', amp_iframe.getAttribute('src')); + elem.setAttribute('target', '_blank'); + par.appendChild(elem); + amp_iframe.parentNode.replaceChild(par, amp_iframe); + } + } +} + +function amp_unhide_subscr_section(amp_ads_sel = 'amp-ad, .ad', replace_iframes = true, amp_iframe_link = false, source = '') { + let preview = document.querySelector('[subscriptions-section="content-not-granted"]'); + removeDOMElement(preview); + let subscr_section = document.querySelectorAll('[subscriptions-section="content"]'); + for (let elem of subscr_section) + elem.removeAttribute('subscriptions-section'); + let amp_ads = document.querySelectorAll(amp_ads_sel); + removeDOMElement(...amp_ads); + if (replace_iframes) + amp_iframes_replace(amp_iframe_link, source); +} + +function amp_unhide_access_hide(amp_access = '', amp_access_not = '', amp_ads_sel = 'amp-ad, .ad', replace_iframes = true, amp_iframe_link = false, source = '') { + let access_hide = document.querySelectorAll('[amp-access' + amp_access + '][amp-access-hide]:not([amp-access="error"], [amp-access^="message"])'); + for (let elem of access_hide) + elem.removeAttribute('amp-access-hide'); + if (amp_access_not) { + let amp_access_not_dom = document.querySelectorAll('[amp-access' + amp_access_not + ']'); + removeDOMElement(...amp_access_not_dom); + } + let amp_ads = document.querySelectorAll(amp_ads_sel); + removeDOMElement(...amp_ads); + if (replace_iframes) + amp_iframes_replace(amp_iframe_link, source); +} + function ampToHtml() { window.setTimeout(function () { let canonical = document.querySelector('link[rel="canonical"]'); @@ -4588,6 +4593,18 @@ function insert_script(func, insertAfterDom) { } } +function getArticleJsonScript() { + let scripts = document.querySelectorAll('script[type="application/ld+json"]'); + let json_script; + for (let script of scripts) { + if (script.innerText.match(/"(articleBody|text)":/)) { + json_script = script; + break; + } + } + return json_script; +} + function genHexString(len) { let output = ''; for (let i = 0; i < len; i++) diff --git a/custom/sites_custom.json b/custom/sites_custom.json index 81f9b1d..e365989 100644 --- a/custom/sites_custom.json +++ b/custom/sites_custom.json @@ -247,7 +247,7 @@ "Stimme.de": { "allow_cookies": 1, "domain": "stimme.de", - "ld_google_webcache": "div.paywall-product-box|div.art-text" + "ld_google_webcache": "div.paywall-product-box,div.fadeOut|div.art-text" }, "Supchina.com": { "allow_cookies": 1, diff --git a/manifest.json b/manifest.json index 3218743..ba083c4 100644 --- a/manifest.json +++ b/manifest.json @@ -713,5 +713,5 @@ "*://*.wallkit.net/*", "*://webcache.googleusercontent.com/*" ], - "version": "2.9.7.5" + "version": "2.9.7.6" }