mirror of
https://gitlab.com/magnolia1234/bypass-paywalls-firefox-clean.git
synced 2024-11-10 07:57:48 +01:00
Update custom/updated sites (onMessage in contentScript)
This commit is contained in:
parent
57fcfa7f0e
commit
2e41b49c1c
5 changed files with 141 additions and 104 deletions
|
@ -533,7 +533,7 @@ ext_api.storage.onChanged.addListener(function (changes, namespace) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh the current tab
|
// 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';
|
let lib_file = 'lib/empty.js';
|
||||||
if (matchUrlDomain(dompurify_sites, url))
|
if (matchUrlDomain(dompurify_sites, url))
|
||||||
lib_file = 'lib/purify.min.js';
|
lib_file = 'lib/purify.min.js';
|
||||||
var bg2csData = {
|
var bg2csData = {};
|
||||||
optin_setcookie: optin_setcookie,
|
if (optin_setcookie && matchUrlDomain(['crusoe.uol.com.br'], url))
|
||||||
amp_unhide: matchUrlDomain(amp_unhide, url)
|
bg2csData.optin_setcookie = 1;
|
||||||
};
|
if (matchUrlDomain(amp_unhide, url))
|
||||||
|
bg2csData.amp_unhide = 1;
|
||||||
let amp_redirect_domain = '';
|
let amp_redirect_domain = '';
|
||||||
if (amp_redirect_domain = matchUrlDomain(Object.keys(amp_redirect), url))
|
if (amp_redirect_domain = matchUrlDomain(Object.keys(amp_redirect), url))
|
||||||
bg2csData.amp_redirect = amp_redirect[amp_redirect_domain];
|
bg2csData.amp_redirect = amp_redirect[amp_redirect_domain];
|
||||||
|
@ -773,27 +774,29 @@ if (typeof browser !== 'object') {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
// run contentScript.js on page
|
// run contentScript.js on page
|
||||||
ext_api.tabs.executeScript(tabId, {
|
ext_api.tabs.executeScript(tabId, {
|
||||||
code: 'var bg2csData = ' + JSON.stringify(bg2csData) + ';'
|
file: lib_file,
|
||||||
|
runAt: 'document_start'
|
||||||
}, function () {
|
}, function () {
|
||||||
ext_api.tabs.executeScript(tabId, {
|
ext_api.tabs.executeScript(tabId, {
|
||||||
file: lib_file,
|
file: 'contentScript.js',
|
||||||
runAt: 'document_start'
|
runAt: 'document_start'
|
||||||
}, function () {
|
}, function (res) {
|
||||||
ext_api.tabs.executeScript(tabId, {
|
if (ext_api.runtime.lastError || res[0]) {
|
||||||
file: 'contentScript.js',
|
return;
|
||||||
runAt: 'document_start'
|
}
|
||||||
}, 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
|
// remove cookies after page load
|
||||||
if (rc_domain_enabled) {
|
if (rc_domain_enabled) {
|
||||||
remove_cookies_fn(rc_domain, true);
|
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('.');
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ Post-release
|
||||||
Fix MIT Sloan Management Review
|
Fix MIT Sloan Management Review
|
||||||
Update block general paywall script (TownNews & fix Pigeon)
|
Update block general paywall script (TownNews & fix Pigeon)
|
||||||
Update custom flex sites (identify main domain)
|
Update custom flex sites (identify main domain)
|
||||||
|
Update custom/updated sites (onMessage in contentScript)
|
||||||
|
|
||||||
* v2.9.7.0 (2022-12-11)
|
* v2.9.7.0 (2022-12-11)
|
||||||
Add Handelsblatt
|
Add Handelsblatt
|
||||||
|
|
185
contentScript.js
185
contentScript.js
|
@ -46,22 +46,9 @@ if (!matchDomain(arr_localstorage_hold)) {
|
||||||
window.localStorage.clear();
|
window.localStorage.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getArticleJsonScript() {
|
function runOnMessage(bg2csData, dompurify_loaded, div_bpc_done) {
|
||||||
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;
|
|
||||||
|
|
||||||
// custom/updated sites: load text from json
|
// 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('|')) {
|
if (bg2csData.ld_json.includes('|')) {
|
||||||
window.setTimeout(function () {
|
window.setTimeout(function () {
|
||||||
let ld_json_split = bg2csData.ld_json.split('|');
|
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
|
// 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('|')) {
|
if (bg2csData.ld_google_webcache.includes('|')) {
|
||||||
window.setTimeout(function () {
|
window.setTimeout(function () {
|
||||||
let url = window.location.href;
|
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 (!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)
|
// 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 (matchDomain(['crusoe.uol.com.br'])) {
|
||||||
if (!cookieExists('crs_subscriber'))
|
if (!cookieExists('crs_subscriber'))
|
||||||
setCookie('crs_subscriber', 1, 'crusoe.uol.com.br', '/', 14);
|
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
|
// custom/updated sites: try to unhide text on amp-page
|
||||||
if ((bg2csData !== undefined) && bg2csData.amp_unhide) {
|
if (bg2csData.amp_unhide) {
|
||||||
window.setTimeout(function () {
|
window.setTimeout(function () {
|
||||||
let amp_page_hide = document.querySelector('script[src*="/amp-access-"], script[src*="/amp-subscriptions-"]');
|
let amp_page_hide = document.querySelector('script[src*="/amp-access-"], script[src*="/amp-subscriptions-"]');
|
||||||
if (amp_page_hide) {
|
if (amp_page_hide) {
|
||||||
|
@ -195,7 +119,7 @@ if ((bg2csData !== undefined) && bg2csData.amp_unhide) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom/updated sites: amp-redirect
|
// custom/updated sites: amp-redirect
|
||||||
if ((bg2csData !== undefined) && bg2csData.amp_redirect) {
|
if (bg2csData.amp_redirect) {
|
||||||
window.setTimeout(function () {
|
window.setTimeout(function () {
|
||||||
let amp_script = document.querySelector('script[src^="https://cdn.ampproject.org/"]');
|
let amp_script = document.querySelector('script[src^="https://cdn.ampproject.org/"]');
|
||||||
let amphtml = document.querySelector('link[rel="amphtml"]');
|
let amphtml = document.querySelector('link[rel="amphtml"]');
|
||||||
|
@ -236,12 +160,39 @@ function cs_code_elems(elems) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// updated sites: cs_code
|
// updated sites: cs_code
|
||||||
if ((bg2csData !== undefined) && bg2csData.cs_code) {
|
if (bg2csData.cs_code) {
|
||||||
window.setTimeout(function () {
|
window.setTimeout(function () {
|
||||||
cs_code_elems(bg2csData.cs_code);
|
cs_code_elems(bg2csData.cs_code);
|
||||||
}, 1000);
|
}, 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
|
// Content workarounds/domain
|
||||||
|
|
||||||
if (matchDomain('medium.com') || matchDomain(medium_custom_domains) || document.querySelector('script[src*=".medium.com/"]')) {
|
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)
|
if (span_hidden)
|
||||||
span_hidden.removeAttribute('class');
|
span_hidden.removeAttribute('class');
|
||||||
}
|
}
|
||||||
|
let banners = document.querySelectorAll('div.dm-slot');
|
||||||
|
removeDOMElement(...banners);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (matchDomain(['mz.de', 'volksstimme.de'])) {
|
else if (matchDomain(['mz.de', 'volksstimme.de'])) {
|
||||||
|
@ -4376,7 +4329,7 @@ else
|
||||||
csDone = true;
|
csDone = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((csDone && (bg2csData !== undefined)) || csDoneOnce) {
|
if (csDone || csDoneOnce) {
|
||||||
addDivBpcDone();
|
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() {
|
function ampToHtml() {
|
||||||
window.setTimeout(function () {
|
window.setTimeout(function () {
|
||||||
let canonical = document.querySelector('link[rel="canonical"]');
|
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) {
|
function genHexString(len) {
|
||||||
let output = '';
|
let output = '';
|
||||||
for (let i = 0; i < len; i++)
|
for (let i = 0; i < len; i++)
|
||||||
|
|
|
@ -247,7 +247,7 @@
|
||||||
"Stimme.de": {
|
"Stimme.de": {
|
||||||
"allow_cookies": 1,
|
"allow_cookies": 1,
|
||||||
"domain": "stimme.de",
|
"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": {
|
"Supchina.com": {
|
||||||
"allow_cookies": 1,
|
"allow_cookies": 1,
|
||||||
|
|
|
@ -713,5 +713,5 @@
|
||||||
"*://*.wallkit.net/*",
|
"*://*.wallkit.net/*",
|
||||||
"*://webcache.googleusercontent.com/*"
|
"*://webcache.googleusercontent.com/*"
|
||||||
],
|
],
|
||||||
"version": "2.9.7.5"
|
"version": "2.9.7.6"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue