Release latest

This commit is contained in:
magnolia1234
2024-08-10 08:46:14 +02:00
commit 115b78d097
11 changed files with 11378 additions and 0 deletions

1577
userscript/bpc.de.user.js Normal file

File diff suppressed because it is too large Load Diff

4893
userscript/bpc.en.user.js Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,855 @@
// ==UserScript==
// @name Bypass Paywalls Clean - es/pt/south america
// @version 3.9.5.1
// @description Bypass Paywalls of news sites
// @author magnolia1234
// @downloadURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=userscript/bpc.es.pt.user.js
// @updateURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=userscript/bpc.es.pt.user.js
// @homepageURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters
// @supportURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters
// @license MIT; https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=LICENSE
// @match *://*.es/*
// @match *://*.abril.com.br/*
// @match *://*.ara.cat/*
// @match *://*.arabalears.cat/*
// @match *://*.cambiocolombia.com/*
// @match *://*.cartacapital.com.br/*
// @match *://*.clarin.com/*
// @match *://*.correiodopovo.com.br/*
// @match *://*.cronista.com/*
// @match *://*.diaridegirona.cat/*
// @match *://*.diariocordoba.com/*
// @match *://*.diariocorreo.pe/*
// @match *://*.diariovasco.com/*
// @match *://*.dn.pt/*
// @match *://*.elcomercio.pe/*
// @match *://*.elconfidencial.com/*
// @match *://*.elcorreo.com/*
// @match *://*.elespanol.com/*
// @match *://*.elespectador.com/*
// @match *://*.elmercurio.com/*
// @match *://*.elobservador.com.uy/*
// @match *://*.elpais.com/*
// @match *://*.elperiodico.com/*
// @match *://*.elperiodicodearagon.com/*
// @match *://*.elperiodicoextremadura.com/*
// @match *://*.elperiodicomediterraneo.com/*
// @match *://*.eltiempo.com/*
// @match *://*.eltribuno.com/*
// @match *://*.em.com.br/*
// @match *://*.emporda.info/*
// @match *://*.estadao.com.br/*
// @match *://*.exame.com/*
// @match *://*.expansion.com/*
// @match *://*.expresso.pt/*
// @match *://*.gazetadopovo.com.br/*
// @match *://*.gestion.pe/*
// @match *://*.globo.com/*
// @match *://*.lanacion.com.ar/*
// @match *://*.larioja.com/*
// @match *://*.latercera.com/*
// @match *://*.lavoz.com.ar/*
// @match *://*.levante-emv.com/*
// @match *://*.losandes.com.ar/*
// @match *://*.marca.com/*
// @match *://*.nsctotal.com.br/*
// @match *://*.observador.pt/*
// @match *://*.ole.com.ar/*
// @match *://*.politicaexterior.com/*
// @match *://*.record.pt/*
// @match *://*.regio7.cat/*
// @match *://*.revistaoeste.com/*
// @match *://*.sabado.pt/*
// @match *://*.uol.com.br/*
// ==/UserScript==
(function() {
'use strict';
window.setTimeout(function () {
var domain;
var mobile = window.navigator.userAgent.toLowerCase().includes('mobile');
var csDoneOnce;
var overlay = document.querySelector('body.didomi-popup-open');
if (overlay)
overlay.classList.remove('didomi-popup-open');
var ads = 'div.OUTBRAIN, div[id^="taboola-"], div.ad, div.ad-container, div[class*="-ad-container"], div[class*="_ad-container"], div.arc_ad, div[id^="poool-"]';
hideDOMStyle(ads, 10);
var ar_grupo_clarin_domains =['clarin.com', 'lavoz.com.ar', 'losandes.com.ar', 'ole.com.ar'];
var es_epiberica_domains = ['diariodemallorca.es', 'eldia.es', 'elperiodico.com', 'epe.es', 'farodevigo.es', 'informacion.es', 'laprovincia.es', 'levante-emv.com', 'lne.es', 'mallorcazeitung.es', 'superdeporte.es'];
var es_epiberica_custom_domains = ['diaridegirona.cat', 'diariocordoba.com', 'diariodeibiza.es', 'elcorreogallego.es', 'elcorreoweb.es', 'elperiodicodearagon.com', 'elperiodicoextremadura.com', 'elperiodicomediterraneo.com', 'emporda.info', 'laopinioncoruna.es', 'laopiniondemalaga.es', 'laopiniondemurcia.es', 'laopiniondezamora.es', 'regio7.cat'];
var es_grupo_vocento_domains = ['abc.es', 'canarias7.es', 'diariosur.es', 'diariovasco.com', 'elcomercio.es', 'elcorreo.com', 'eldiariomontanes.es', 'elnortedecastilla.es', 'hoy.es', 'ideal.es', 'larioja.com', 'lasprovincias.es', 'laverdad.es', 'lavozdigital.es'];
var es_unidad_domains = ['elmundo.es', 'expansion.com', 'marca.com'];
var pe_grupo_elcomercio_domains = ['diariocorreo.pe', 'elcomercio.pe', 'gestion.pe'];
if (window.location.hostname.match(/\.(es|pt|cat)$/) || matchDomain(['diariocordoba.com', 'diariovasco.com', 'elconfidencial.com', 'elcorreo.com', 'elespanol.com', 'elpais.com', 'elperiodico.com', 'elperiodicodearagon.com', 'elperiodicoextremadura.com', 'elperiodicomediterraneo.com', 'emporda.info', 'expansion.com', 'larioja.com', 'levante-emv.com', 'marca.com', 'politicaexterior.com'])) {//spain/portugal
if (matchDomain(['ara.cat', 'arabalears.cat'])) {
if (!window.location.pathname.endsWith('.amp.html')) {
amp_redirect('div.paywall');
let ads = 'div.advertising';
hideDOMStyle(ads);
}
}
else if (matchDomain('diariodenavarra.es')) {
let paywall = document.querySelector('div#paywall_message');
if (paywall) {
removeDOMElement(paywall);
let json_script = getArticleJsonScript();
if (json_script) {
let json = JSON.parse(json_script.text);
if (json) {
let json_text = json.articleBody;
let article = document.querySelector('div.free-html');
if (json_text && article)
article.innerText = parseHtmlEntities(json_text);
}
}
}
}
else if (matchDomain('dn.pt')) {
if (window.location.pathname.endsWith('/amp/')) {
let amp_list = 'amp-list';
hideDOMStyle(amp_list);
} else {
let ads = document.querySelectorAll('div.sk-pub');
removeDOMElement(...ads);
}
}
else if (matchDomain('elconfidencial.com')) {
let premium = document.querySelector('div.newsType__content--closed');
if (premium)
premium.classList.remove('newsType__content--closed');
let ads = 'div[id^="mega_"], div[id^="roba_"]';
hideDOMStyle(ads);
}
else if (matchDomain('eldiario.es')) {
if (window.location.pathname.endsWith('.amp.html')) {
amp_unhide_access_hide('^="access"', '="NOT access"');
} else {
amp_redirect('aside.paywall');
let ads = 'div.edi-advertising, div.header-ad';
hideDOMStyle(ads);
}
}
else if (matchDomain('elespanol.com')) {
if (window.location.pathname.endsWith('.amp.html')) {
amp_unhide_subscr_section('amp-ad, amp-embed');
} else {
let paywall = document.querySelector('div.full-suscriptor-container');
if (paywall) {
removeDOMElement(paywall);
let content_hidden = document.querySelector('div.content-not-granted-paywall');
if (content_hidden)
content_hidden.classList.remove('content-not-granted-paywall');
}
let ads = '[id*="superior"], [class*="adv"]';
hideDOMStyle(ads);
}
}
else if (matchDomain(es_unidad_domains)) {
if (!window.location.hostname.match(/^amp(-[a-z]{2})?\./)) {
let url = window.location.href;
if (!window.location.pathname.startsWith('/mejores-colegios')) {
amp_redirect('div.ue-c-article__premium', '', url.replace('/www.', '/amp.'));
} else if (matchDomain('elmundo.es')) {
header_nofix('main p', 'div.ue-c-article__premium');
header_nofix('table', 'div.ue-c-paywall');
}
} else {
amp_unhide_access_hide('="authorized=true"', '="authorized!=true"');
amp_unhide_subscr_section('amp-ad, amp-embed, .advertising, div.ue-c-ad');
}
}
else if (matchDomain('elpais.com')) {
if (window.location.pathname.endsWith('.amp.html') || window.location.search.match(/(\?|&)outputType=amp/)) {
amp_unhide_access_hide('="vip"], [amp-access="success"', '="NOT vip"], [amp-access="NOT success"');
} else {
let paywall = document.querySelector('div#ctn_freemium_article, div#ctn_premium_article');
removeDOMElement(paywall);
}
}
else if (matchDomain(es_grupo_vocento_domains)) {
let paywall_sel = 'div.voc-paywall, div.container-wall-exclusive__content-login';
let paywall = document.querySelector(paywall_sel);
if (!window.location.pathname.endsWith('_amp.html')) {
if (!matchDomain(['eldiariomontanes.es'])) {
amp_redirect(paywall_sel, '', window.location.pathname.replace('.html', '_amp.html'));
} else {
if (paywall) {
let url = window.location.href;
paywall.before(archiveLink(url));
removeDOMElement(paywall);
}
}
let banners = 'div.voc-advertising, div.voc-ob-wrapper, div.voc-discounts, div.ev-em-modal, span.mega-superior, div.v-adv';
hideDOMStyle(banners);
} else {
amp_unhide_access_hide('="result=\'ALLOW_ACCESS\'"', '="result!=\'ALLOW_ACCESS\'"', 'amp-ad, amp-embed, div.v-adv');
let body_top = document.querySelector('body#top');
if (body_top)
body_top.removeAttribute('id');
}
}
else if (matchDomain(es_epiberica_domains) || matchDomain(es_epiberica_custom_domains)) {
let paywall = document.querySelector('div.ft-helper-closenews');
if (paywall) {
paywall.removeAttribute('class');
let hidden_pars = paywall.querySelectorAll('.closeContentEnd');
for (let elem of hidden_pars)
elem.classList.remove('closeContentEnd');
}
if (window.location.pathname.endsWith('.amp.html') || ['amp.elperiodico.com', 'amp.epe.es'].includes(window.location.hostname)) {
let amp_images = document.querySelectorAll('figure > amp-img[src]');
for (let amp_image of amp_images) {
let elem = document.createElement('img');
elem.src = amp_image.getAttribute('src');
elem.style = 'width: 75%; margin: 0px 50px;';
amp_image.parentNode.replaceChild(elem, amp_image);
}
let ads = 'amp-ad, amp-embed, amp-next-page, span.ad-signature';
hideDOMStyle(ads);
} else {
let ads = 'div.commercial-up-full__wrapper, aside.ft-ad, div[class^="_mo_recs"]';
hideDOMStyle(ads);
}
}
else if (matchDomain('expresso.pt')) {
if (!window.location.hostname.startsWith('amp.')) {
let article_sel = 'div.article-content';
let paywall = document.querySelector(article_sel + ' > div.g-premium-blocker');
if (paywall) {
removeDOMElement(paywall);
let article = document.querySelector(article_sel);
if (article) {
let url = window.location.href.split(/[#\?]/)[0];
fetch(url)
.then(response => {
if (response.ok) {
response.text().then(html => {
if (html.match(/window\.__INITIAL_DATA__\s?=\s?/)) {
try {
article.innerHTML = '';
let json = JSON.parse(html.split(/window\.__INITIAL_DATA__\s?=\s?/)[1].split(';window.')[0].replace(/":undefined([,}])/g, "\":\"undefined\"$1")).nodes;
let pars = [];
for (let elem in json) {
let item = json[elem];
if (item.type === 'Layout') {
for (let elem of item.nodes) {
if (elem.type === 'MainBody')
pars = elem.nodes[0].data.content.contents;
}
break;
}
}
let parser = new DOMParser();
for (let par of pars) {
let par_new;
if (par.html) {
let doc = parser.parseFromString('<div>' + par.html + '</div>', 'text/html');
par_new = doc.querySelector('div');
} else if (par.type === 'PICTURE') {
if (par.urlOriginal) {
par_new = makeFigure(par.urlOriginal, par.caption, {style: 'width:100%'});
}
} else if (par.link && par.title) {
if (par.contents) {
par_new = document.createElement('div');
for (let elem of par.contents) {
let elem_new;
if (elem.html) {
let doc = parser.parseFromString('<div>' + elem.html + '</div>', 'text/html');
elem_new = doc.querySelector('div');
} else if (elem.urlOriginal) {
elem_new = makeFigure(elem.urlOriginal, elem.caption, {style: 'width:100%'});
}
if (elem_new)
par_new.appendChild(elem_new);
}
} else {
par_new = document.createElement('p');
let art_link = document.createElement('a');
art_link.innerText = par.title;
art_link.href = par.link;
par_new.appendChild(art_link);
}
}
if (par_new)
article.appendChild(par_new);
else
console.log(par);
}
} catch (err) {
console.log(err);
}
}
});
}
}).catch(function (err) {
false;
});
}
}
} else
ampToHtml();
}
else if (matchDomain(['lavanguardia.com', 'mundodeportivo.com'])) {
let ads = 'span.content-ad, span.hidden-ad, span.ad-unit, div.ad-div';
hideDOMStyle(ads);
}
else if (matchDomain('observador.pt')) {
let ads = 'div.obs-ad-placeholder';
hideDOMStyle(ads);
}
else if (matchDomain('politicaexterior.com')) {
let paywall = document.querySelector('div[class^="paywall-"]');
if (paywall) {
let article = document.querySelector('div.entry-content-text');
let json = document.querySelector('script[type="application/ld+json"]:not([class])');
if (json) {
let json_text = JSON.parse(json.text).description.replace(/&amp;nbsp;/g, '');
let article_new = document.createElement('div');
article_new.setAttribute('class', 'entry-content-text');
article_new.innerText = '\r\n' + json_text;
article.parentNode.replaceChild(article_new, article);
}
removeDOMElement(paywall);
}
}
else if (matchDomain('publico.es')) {
let ads = 'div.pb-ads';
hideDOMStyle(ads);
}
else if (matchDomain(['record.pt', 'sabado.pt'])) {
if (!window.location.pathname.includes('/amp/'))
amp_redirect('.bloqueio_exclusivos, .container_assinatura, .bloco_bloqueio', '', window.location.href.replace('/detalhe/', '/amp/'));
else
amp_unhide_access_hide('="subscriber"', '="NOT subscriber"', 'amp-ad, amp-embed, amp-consent, .detalheAds, .exclusivos_bar');
}
else if (window.location.hostname.endsWith('.es')) {// Sport Life Ibérica sites
if (document.querySelector('div > ul > li > a[href="https://www.sportlife.es/"]')) {
let paywall = document.querySelector('div.c-paywall');
if (paywall) {
let article = document.querySelector('div.c-mainarticle__body');
let json_script = getArticleJsonScript();
if (json_script) {
let json_text = JSON.parse(json_script.text).articleBody;
let article_new = document.createElement('div');
article_new.innerText = json_text;
article.parentNode.replaceChild(article_new, article);
}
removeDOMElement(paywall);
}
}
}
} else if (window.location.hostname.match(/\.(ar|br|cl|pe|uy)$/) || matchDomain(['cambiocolombia.com', 'clarin.com', 'cronista.com', 'elespectador.com', 'elmercurio.com', 'eltiempo.com', 'eltribuno.com', 'exame.com', 'globo.com', 'latercera.com', 'revistaoeste.com'])) {//south america
if (matchDomain('abril.com.br')) {
if (window.location.pathname.endsWith('/amp/')) {
let paywall = document.querySelector('.piano-modal');
removeDOMElement(paywall);
let ads = 'amp-ad, amp-embed';
hideDOMStyle(ads);
} else {
let ads = 'div.ads, div[class^="ads-"], div.MGID';
hideDOMStyle(ads);
}
}
else if (matchDomain(ar_grupo_clarin_domains)) {
let ads = 'div.ad-slot, div.box-adv, div.wrapperblock, div.banner, div[id^="div-gpt-ad-flotante"]';
hideDOMStyle(ads);
let ads_inline = document.querySelectorAll('div > div.sticky, div > div.SRA, div > div[id^="div-gpt-ad-inread"], div > div[id^="div-gpt-ad-caja"], div > div[id^="div-gpt-ad-horizontal"]');
for (let ad of ads_inline)
hideDOMElement(ad.parentNode);
}
else if (matchDomain('cambiocolombia.com')) {
if (!window.location.pathname.startsWith('/amp/')) {
let paywall = document.querySelector('div#require-access');
if (paywall) {
removeDOMElement(paywall);
window.location.href = '/amp' + window.location.pathname;
}
} else {
amp_unhide_subscr_section('amp-ad, amp-embed');
}
}
else if (matchDomain('cartacapital.com.br')) {
if (!window.location.pathname.endsWith('/amp/')) {
let paywall = document.querySelector('aside.paywall');
if (paywall) {
removeDOMElement(paywall);
let json_script = getArticleJsonScript();
if (json_script) {
try {
let json = JSON.parse(json_script.text);
if (json) {
let json_text = json[1].articleBody.replace(/\s{2,}/g, '\r\n\r\n');
let content = document.querySelector('section.s-content__text');
if (json_text && content) {
content.innerHTML = '';
let article_new = document.createElement('p');
article_new.innerText = json_text;
content.appendChild(article_new);
}
}
} catch (err) {
console.log(err);
}
}
} else {
let content_soft = document.querySelector('div.contentSoft');
if (content_soft) {
content_soft.removeAttribute('class');
let freemium = document.querySelectorAll('div[class^="s-freemium"], div.maggazine-add');
removeDOMElement(...freemium);
}
}
let ads = 'div.div_ros_topo';
hideDOMStyle(ads);
} else
ampToHtml();
}
else if (matchDomain('cronista.com')) {
let ads = 'div#ad-slot-header, div.ad-slot-intext, div#selectMediaNota, div.b-suscription-container';
hideDOMStyle(ads);
}
else if (matchDomain(pe_grupo_elcomercio_domains)) {
let paywall = document.querySelector('.paywall');
if (paywall) {
paywall.removeAttribute('class');
paywall.removeAttribute('style');
let fade = document.querySelector('p.story-contents--fade');
if (fade)
fade.classList.remove('story-contents--fade');
}
let ads = 'div[class^="content_gpt"]';
hideDOMStyle(ads);
}
else if (matchDomain('elespectador.com')) {
if (window.location.search.match(/(\?|&)outputType=amp/)) {
amp_unhide_subscr_section('amp-ad, amp-embed, [class^="Widget"], amp-fx-flying-carpet', false);
} else {
amp_redirect('div.exclusive_validation');
}
}
else if (matchDomain('elobservador.com.uy')) {
if (window.location.pathname.endsWith('/amp')) {
amp_unhide_access_hide('="observador.mostrarNota"');
let amp_images = document.querySelectorAll('div.fixed-container > amp-img.null');
for (let amp_image of amp_images) {
let elem = document.createElement('img');
Object.assign(elem, {
src: amp_image.getAttribute('src'),
alt: amp_image.getAttribute('alt'),
title: amp_image.getAttribute('title')
});
amp_image.parentNode.replaceChild(elem, amp_image);
}
} else {
let paywall = document.querySelector('div.mensaje_member');
if (paywall) {
removeDOMElement(paywall);
window.location.href = window.location.pathname + '/amp';
}
}
}
else if (matchDomain('eltiempo.com')) {
let modulos = document.querySelector('div.modulos');
if (modulos)
modulos.classList.remove('modulos');
let ads = '[class^="c-add"]';
hideDOMStyle(ads);
}
else if (matchDomain('eltribuno.com')) {
let lazy_images = document.querySelectorAll('img.lazyload[data-src]:not([src])');
for (let elem of lazy_images) {
elem.src = elem.getAttribute('data-src');
elem.classList.remove('lazyload');
}
}
else if (matchDomain('em.com.br')) {
if (!window.location.pathname.endsWith('/amp.html')) {
amp_redirect('.news-blocked-content');
hideDOMStyle(ads);
} else {
amp_unhide_subscr_section('amp-ad, amp-embed, amp-fx-flying-carpet');
let compress_text = document.querySelector('div.compress-text');
if (compress_text)
compress_text.classList.remove('compress-text');
}
}
else if (matchDomain('estadao.com.br')) {
if (window.location.pathname.match(/(\.amp$|^\/amp\/)/) || window.location.search.startsWith('?amp')) {
amp_unhide_access_hide('="outputValue=\'hide_paywall\'"', '="outputValue=\'show_paywall\'"', 'amp-ad, amp-embed, amp-fx-flying-carpet, div[class^="pAd"], div.ads-container');
} else {
let paywall = document.getElementById('paywall-wrapper-iframe-estadao');
removeDOMElement(paywall);
let ads = 'div[class^="styles__Container-sc-"]';
hideDOMStyle(ads);
}
}
else if (matchDomain('exame.com')) {
window.localStorage.removeItem('pywllcount');
let ads = 'div[id^="ads_"]';
hideDOMStyle(ads);
}
else if (matchDomain('uol.com.br')) {
if (matchDomain('folha.uol.com.br')) {
if (window.location.pathname.startsWith('/amp/')) {
amp_unhide_subscr_section('amp-ad, amp-sticky-ad, amp-embed');
} else {
let signup = document.querySelector('.c-top-signup');
removeDOMElement(signup);
}
}
let ads = 'div[class*="advertising"], div.jupiter-ads, div.up-floating, div[data-cp-id$="asfads"]';
hideDOMStyle(ads);
}
else if (matchDomain('gazetadopovo.com.br')) {
if (window.location.pathname.endsWith('/amp/')) {
amp_unhide_subscr_section('div.ads-amp, amp-embed, div.tpl-wrapper', false);
} else {
let ads = 'div.c-ads';
hideDOMStyle(ads);
}
}
else if (matchDomain('globo.com')) {
if (matchDomain('valor.globo.com')) {
if (!window.location.pathname.startsWith('/google/amp/')) {
amp_redirect('div.paywall');
} else {
amp_unhide_subscr_section('amp-ad, amp-embed');
amp_images_replace();
}
} else if (window.location.pathname.includes('/amp/'))
ampToHtml();
if (!window.location.pathname.includes('/amp/')) {
let ads = 'div[id^="ad-container"], div.content-ads, div[class^="block__advertising"], div#pub-in-text-wrapper, div.area_publicidade_container';
hideDOMStyle(ads);
}
}
else if (matchDomain('lanacion.com.ar')) {
setCookie(/^metering_arc/, '', 'lanacion.com.ar', '/', 0);
let ads = 'div.ln-banner-container';
hideDOMStyle(ads);
}
else if (matchDomain('latercera.com')) {
let paywall = document.querySelector('div.pw-frontier');
if (paywall)
removeDOMElement(paywall);
let ads = 'div.spm';
hideDOMStyle(ads);
}
else if (matchDomain('nsctotal.com.br')) {
let ads = 'div.ad, div[id^="floater"]';
hideDOMStyle(ads);
}
else if (matchDomain('revistaoeste.com')) {
if (window.location.pathname.startsWith('/revista/')) {
let loading_content = document.querySelector('div.loading_content');
if (loading_content)
loading_content.removeAttribute('class');
let spinner = document.querySelector('svg.spinner-eclipse');
removeDOMElement(spinner);
let lazy_images = document.querySelectorAll('img[src^="data:image/"][data-src]');
for (let elem of lazy_images)
elem.src = elem.getAttribute('data-src');
} else {
let div_expandable = document.querySelector('div.expandable');
if (div_expandable)
div_expandable.classList.remove('expandable');
let ads = 'section.ad-wrapper, div.autozep-outer';
hideDOMStyle(ads);
}
}
}
if (document.querySelector('head > link[href*="/leaky-paywall"], script[src*="/leaky-paywall"], div[id^="issuem-leaky-paywall-"]')) {
let js_cookie = document.querySelector('script#leaky_paywall_cookie_js-js-extra');
if (js_cookie && js_cookie.text.includes('"post_container":"')) {
let post_sel = js_cookie.text.split('"post_container":"')[1].split('"')[0];
if (post_sel) {
let post = document.querySelector(post_sel);
if (post)
post.removeAttribute('class');
}
}
}
}, 1000);
// General Functions
function matchDomain(domains, hostname) {
var matched_domain = false;
if (!hostname)
hostname = window.location.hostname;
if (typeof domains === 'string')
domains = [domains];
domains.some(domain => (hostname === domain || hostname.endsWith('.' + domain)) && (matched_domain = domain));
return matched_domain;
}
function matchCookies(name) {
return document.cookie.split(';').filter(x => x.trim().match(name)).map(y => y.split('=')[0].trim())
}
function setCookie(names, value, domain = '', path = '/', days = 0) {
var max_age = days * 24 * 60 * 60;
let ck_names = Array.isArray(names) ? names : [];
if (names instanceof RegExp)
ck_names = matchCookies(names);
else if (typeof names === 'string')
ck_names = [names];
for (let ck_name of ck_names) {
document.cookie = ck_name + "=" + (value || "") + (domain ? "; domain=" + domain : '') + (path ? "; path=" + path : '') + "; max-age=" + max_age;
}
window.localStorage.clear();
}
function cookieExists(name) {
return document.cookie.split(';').some(ck => ck.trim().indexOf(name + '=') === 0)
}
function removeDOMElement(...elements) {
for (let element of elements) {
if (element)
element.remove();
}
}
function hideDOMElement(...elements) {
for (let element of elements) {
if (element)
element.style = 'display:none !important;';
}
}
function hideDOMStyle(selector, id = 1) {
let style = document.querySelector('head > style#ext'+ id);
if (!style && document.head) {
let sheet = document.createElement('style');
sheet.id = 'ext' + id;
sheet.innerText = selector + ' {display: none !important;}';
document.head.appendChild(sheet);
}
}
function addStyle(css, id = 1) {
let style = document.querySelector('head > style#add'+ id);
if (!style && document.head) {
let sheet = document.createElement('style');
sheet.id = 'add' + id;
sheet.innerText = css;
document.head.appendChild(sheet);
}
}
function clearPaywall(paywall, paywall_action) {
if (paywall) {
if (!paywall_action)
removeDOMElement(...paywall);
else {
for (let elem of paywall) {
if (paywall_action.rm_class)
elem.classList.remove(paywall_action.rm_class);
else if (paywall_action.rm_attrib)
elem.removeAttribute(paywall_action.rm_attrib);
}
}
}
}
function makeFigure(url, caption_text, img_attrib = {}, caption_attrib = {}) {
let elem = document.createElement('figure');
let img = document.createElement('img');
img.src = url;
for (let attrib in img_attrib)
if (img_attrib[attrib])
img.setAttribute(attrib, img_attrib[attrib]);
elem.appendChild(img);
if (caption_text) {
let caption = document.createElement('figcaption');
for (let attrib in caption_attrib)
if (caption_attrib[attrib])
caption.setAttribute(attrib, caption_attrib[attrib]);
let cap_par = document.createElement('p');
cap_par.innerText = caption_text;
caption.appendChild(cap_par);
elem.appendChild(caption);
}
return elem;
}
function header_nofix(header, cond_sel = '', msg = 'BPC > no fix') {
if (header && typeof header === 'string')
header = document.querySelector(header);
if (header && !document.querySelector('div#bpc_nofix')) {
if (cond_sel) {
let elem = document.querySelectorAll(cond_sel);
if (elem.length)
removeDOMElement(...elem);
else
return false;
}
let nofix_div = document.createElement('div');
nofix_div.id = 'bpc_nofix';
nofix_div.style = 'margin: 20px; font-size: 20px; font-weight: bold; color: red;';
nofix_div.innerText = msg;
header.before(nofix_div);
}
}
function amp_images_replace() {
window.setTimeout(function () {
let amp_images = document.querySelectorAll('figure amp-img[src^="http"]');
for (let amp_image of amp_images) {
let elem = document.createElement('img');
elem.src = amp_image.getAttribute('src');
elem.alt = amp_image.getAttribute('alt');
elem.style = 'width: 100%;';
amp_image.parentNode.replaceChild(elem, amp_image);
}
}, 1000);
}
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) {
if (amp_iframe.offsetHeight > 10) {
elem = document.createElement('iframe');
elem.src = amp_iframe.getAttribute('src').replace(/^http:/, 'https:');
elem.style = 'height: ' + amp_iframe.offsetHeight + 'px; width: 100%; border: 0px;';
if (amp_iframe.getAttribute('sandbox'))
elem.sandbox = amp_iframe.getAttribute('sandbox');
amp_iframe.parentNode.replaceChild(elem, amp_iframe);
}
} else {
par = document.createElement('p');
par.style = 'margin: 20px 0px;';
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_redirect_not_loop(amphtml) {
let amp_redirect_date = Number(sessionStorage.getItem('###_amp_redirect'));
if (!(amp_redirect_date && Date.now() - amp_redirect_date < 2000)) {
sessionStorage.setItem('###_amp_redirect', Date.now());
window.location.href = amphtml.href;
} else {
let header = (document.body && document.body.firstChild) || document.documentElement;
header_nofix(header, '', 'BPC > redirect to amp failed (disable amp-to-html extension/add-on or browser setting)');
}
}
function amp_redirect(paywall_sel, paywall_action = '', amp_url = '') {
let paywall = document.querySelectorAll(paywall_sel);
let amphtml = document.querySelector('head > link[rel="amphtml"]');
if (!amphtml && amp_url)
amphtml = {href: amp_url};
if (paywall.length && amphtml) {
clearPaywall(paywall, paywall_action);
amp_redirect_not_loop(amphtml);
}
}
function amp_unhide_subscr_section(amp_ads_sel = 'amp-ad', replace_iframes = true, amp_iframe_link = false, source = '') {
let preview = document.querySelectorAll('[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');
hideDOMStyle(amp_ads_sel, 5);
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', 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"], .piano)');
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);
}
hideDOMStyle(amp_ads_sel, 6);
if (replace_iframes)
amp_iframes_replace(amp_iframe_link, source);
}
function ampToHtml() {
window.setTimeout(function () {
let canonical = document.querySelector('head > link[rel="canonical"][href]');
if (canonical)
window.location.href = canonical.href;
}, 1000);
}
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)":/i)) {
json_script = script;
break;
}
}
return json_script;
}
function parseHtmlEntities(encodedString) {
let parser = new DOMParser();
let doc = parser.parseFromString('<textarea>' + encodedString + '</textarea>', 'text/html');
let dom = doc.querySelector('textarea');
return dom.value;
}
})();

View File

@@ -0,0 +1,138 @@
// ==UserScript==
// @name Bypass Paywalls Clean - fi/se
// @version 3.8.8.0
// @description Bypass Paywalls of news sites
// @author magnolia1234
// @downloadURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=userscript/bpc.fi.se.user.js
// @updateURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=userscript/bpc.fi.se.user.js
// @homepageURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters
// @supportURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters
// @license MIT; https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=LICENSE
// @match *://*.etc.se/*
// @match *://*.suomensotilas.fi/*
// ==/UserScript==
(function() {
'use strict';
window.setTimeout(function () {
var domain;
var mobile = window.navigator.userAgent.toLowerCase().includes('mobile');
var csDoneOnce;
var overlay = document.querySelector('body.didomi-popup-open');
if (overlay)
overlay.classList.remove('didomi-popup-open');
var ads = 'div.OUTBRAIN, div[id^="taboola-"], div.ad, div.ad-container, div[class*="-ad-container"], div[class*="_ad-container"], div.arc_ad';
hideDOMStyle(ads, 10);
if (matchDomain('etc.se')) {
let paywall = document.querySelector('div.paywalled');
if (paywall) {
paywall.removeAttribute('class');
let gradient = document.querySelector('div.bg-gradient-white');
if (gradient)
gradient.removeAttribute('class');
let footer = document.querySelector('section > footer');
if (footer)
removeDOMElement(footer.parentNode);
}
let ads = 'div[class$="-ad"]';
hideDOMStyle(ads);
let video_iframes = document.querySelectorAll('div.embed-block > iframe[width][height]');
for (let elem of video_iframes) {
if (elem.width > 1000) {
let ratio = elem.width / (mobile ? 320 : 640);
elem.width = elem.width / ratio;
elem.height = elem.height / ratio;
}
}
}
else if (matchDomain('suomensotilas.fi')) {
let obscured = document.querySelector('div.epfl-pw-obscured');
if (obscured)
obscured.classList.remove('epfl-pw-obscured');
}
}, 1000);
// General Functions
function matchDomain(domains, hostname) {
var matched_domain = false;
if (!hostname)
hostname = window.location.hostname;
if (typeof domains === 'string')
domains = [domains];
domains.some(domain => (hostname === domain || hostname.endsWith('.' + domain)) && (matched_domain = domain));
return matched_domain;
}
function removeDOMElement(...elements) {
for (let element of elements) {
if (element)
element.remove();
}
}
function hideDOMElement(...elements) {
for (let element of elements) {
if (element)
element.style = 'display:none !important;';
}
}
function hideDOMStyle(selector, id = 1) {
let style = document.querySelector('head > style#ext'+ id);
if (!style && document.head) {
let sheet = document.createElement('style');
sheet.id = 'ext' + id;
sheet.innerText = selector + ' {display: none !important;}';
document.head.appendChild(sheet);
}
}
function addStyle(css, id = 1) {
let style = document.querySelector('head > style#add'+ id);
if (!style && document.head) {
let sheet = document.createElement('style');
sheet.id = 'add' + id;
sheet.innerText = css;
document.head.appendChild(sheet);
}
}
function archiveLink(url, text_fail = 'BPC > Try for full article text (no need to report issue for external site):\r\n') {
return externalLink(['archive.today', 'archive.is'], 'https://{domain}?run=1&url={url}', url, text_fail);
}
function nftLink(url, text_fail = 'BPC > Full article text:\r\n') {
return externalLink(['1ft.io'], 'https://{domain}/{url}', url, text_fail);
}
function externalLink(domains, ext_url_templ, url, text_fail = 'BPC > Full article text:\r\n') {
let text_fail_div = document.createElement('div');
text_fail_div.id = 'bpc_archive';
text_fail_div.setAttribute('style', 'margin: 20px; font-size: 20px; font-weight: bold; color: red;');
let parser = new DOMParser();
text_fail = text_fail.replace(/\[(?<url>[^\]]+)\]/g, function (match, url) {
return "<a href='" + url + "' target='_blank' style='color: red'>" + new URL(url).hostname + "</a>";
});
let doc = parser.parseFromString('<span>' + text_fail + '</span>', 'text/html');
let elem = doc.querySelector('span');
text_fail_div.appendChild(elem);
for (let domain of domains) {
let ext_url = ext_url_templ.replace('{domain}', domain).replace('{url}', url.split('?')[0]);
let a_link = document.createElement('a');
a_link.innerText = domain;
a_link.href = ext_url;
a_link.target = '_blank';
text_fail_div.appendChild(document.createTextNode(' | '));
text_fail_div.appendChild(a_link);
}
return text_fail_div;
}
})();

1167
userscript/bpc.fr.user.js Normal file

File diff suppressed because it is too large Load Diff

526
userscript/bpc.it.user.js Normal file
View File

@@ -0,0 +1,526 @@
// ==UserScript==
// @name Bypass Paywalls Clean - it
// @version 3.9.5.0
// @description Bypass Paywalls of news sites
// @author magnolia1234
// @downloadURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=userscript/bpc.it.user.js
// @updateURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=userscript/bpc.it.user.js
// @homepageURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters
// @supportURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters
// @license MIT; https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=LICENSE
// @match *://*.it/*
// @match *://*.eastwest.eu/*
// @match *://*.italian.tech/*
// @match *://*.quotidiano.net/*
// @match *://*.tuttosport.com/*
// ==/UserScript==
(function() {
'use strict';
window.setTimeout(function () {
var domain;
var mobile = window.navigator.userAgent.toLowerCase().includes('mobile');
var csDoneOnce;
var overlay = document.querySelector('body.didomi-popup-open');
if (overlay)
overlay.classList.remove('didomi-popup-open');
var ads = 'div.OUTBRAIN, div[id^="taboola-"], div.ad, div.ad-container, div[class*="-ad-container"], div[class*="_ad-container"], div.arc_ad';
hideDOMStyle(ads, 10);
var it_gedi_domains = ['huffingtonpost.it', 'italian.tech', 'lastampa.it', 'lescienze.it', 'moda.it'];
var it_ilmessaggero_domains = ['corriereadriatico.it', 'ilgazzettino.it', 'ilmattino.it', 'ilmessaggero.it', 'quotidianodipuglia.it'];
var it_quotidiano_domains = ['ilgiorno.it', 'ilrestodelcarlino.it', 'iltelegrafolivorno.it', 'lanazione.it', 'quotidiano.net'];
if (matchDomain('corriere.it')) {
if (window.location.pathname.endsWith('_amp.html')) {
amp_unhide_subscr_section('amp-ad, amp-embed');
} else {
if (window.location.pathname.includes('_preview.shtml') && !window.location.pathname.startsWith('/podcast/')) {
window.setTimeout(function () {
window.location.href = window.location.pathname.replace('_preview.shtml', '.shtml');
}, 500);
}
}
}
else if (matchDomain('corrieredellosport.it')) {
if (!window.location.pathname.startsWith('/amp/')) {
amp_redirect('div[class^="MainTextTruncated_paragraph__"]');
let ads = 'div[class^="AdUnit_placeholder"]';
hideDOMStyle(ads);
} else {
let ads = 'amp-ad, amp-embed';
hideDOMStyle(ads);
}
}
else if (matchDomain('eastwest.eu')) {
let paywall = document.querySelector('.paywall');
if (paywall) {
paywall.removeAttribute('style');
paywall.classList.remove('paywall');
let intro = document.querySelectorAll('div#testo_articolo > p, div#testo_articolo > h3');
let offerta = document.querySelectorAll('div.offerta_abbonamenti');
removeDOMElement(...intro, ...offerta);
}
}
else if (matchDomain('editorialedomani.it')) {
if (window.location.search.startsWith('?amp=1'))
ampToHtml();
}
else if (matchDomain('gazzetta.it')) {
if (window.location.pathname.endsWith('_preview.shtml')) {
let paywall = document.querySelector('section.bck-freemium__wall');
if (paywall) {
removeDOMElement(paywall);
if (!window.location.search.startsWith('?reason=unauthenticated')) {
window.location.href = window.location.pathname.replace('_preview', '') + '?gaa_at=g';
} else {
let json_script = getArticleJsonScript();
let header = 'div.content > h2';
if (json_script) {
let json = JSON.parse(json_script.text);
if (json) {
let json_text = json.articleBody.replace(/(\s{3}|&nbsp;)/g, '\r\n\r\n');
let content = document.querySelector('div.content > p.has-first-letter');
if (json_text && content) {
let content_new = document.createElement('p');
content_new.innerText = json_text;
content.parentNode.replaceChild(content_new, content);
let article_body = document.querySelector('section.body-article');
if (article_body)
article_body.style = 'height: auto;';
} else
header_nofix(header);
}
} else
header_nofix(header);
}
}
} else if (window.location.pathname.endsWith('_amp.shtml'))
ampToHtml();
}
else if (matchDomain('ilfattoquotidiano.it')) {
if (window.location.pathname.endsWith('/amp/')) {
amp_unhide_subscr_section('amp-ad, amp-embed, div#_4sVideoContainer, div#post-consent-ui');
let comments = document.querySelector('div.content.comments');
removeDOMElement(comments);
let logo = document.querySelector('a > amp-img[src$="/logo-tablet.svg"]');
if (logo) {
let logo_new = document.createElement('img');
logo_new.src = logo.getAttribute('src').replace('logo-tablet.svg', 'logo-desktop.svg');
logo_new.height = logo.getAttribute('height');
logo_new.width = logo.getAttribute('width');
logo.parentNode.replaceChild(logo_new, logo);
}
} else if (window.location.pathname.match(/\/\d{4}\/\d{2}\/\d{2}\//)) {
let paywall = document.querySelector('div.read-more');
if (paywall) {
removeDOMElement(paywall);
window.location.href = window.location.pathname + 'amp';
}
}
}
else if (matchDomain('ilfoglio.it')) {
if (window.location.pathname.endsWith('/amp/')) {
amp_unhide_subscr_section('amp-ad, [class^="adv-"], div#gmpVideoContainer');
} else {
amp_redirect('div.paywall');
let ads = '.advertisement';
hideDOMStyle(ads);
}
}
else if (matchDomain('ilmanifesto.it')) {
let paywall = document.querySelector('div[class*="before:bg-gradient-to-t"]');
if (paywall) {
removeDOMElement(paywall);
let article = document.querySelector('article div.prose');
if (article) {
let filter = /^self\.__next_f\.push\(\[1,"/;
let scripts = document.querySelectorAll('script:not([src], [type])');
for (let script of scripts) {
if (script.text.match(filter) && script.text.includes('canonical_url')) {
if (!script.text.includes(window.location.href))
refreshCurrentTab();
break;
}
}
let source_script = getSourceJsonScript(/^self\.__next_f\.push\(\[1,"\\u003c/);
if (source_script) {
let source_text = source_script.text.split(filter)[1].split('"])')[0].replace(/\\u003c/g, '<').replace(/\\u003e/g, '>').replace(/\\"/g, '"').replace(/\\n/g, '');
let parser = new DOMParser();
let doc = parser.parseFromString('<div>' + source_text + '</div>', 'text/html');
let article_new = doc.querySelector('div');
let figures = article_new.querySelectorAll('figure[style]');
for (let elem of figures)
elem.removeAttribute('style');
article.innerHTML = '';
article.appendChild(article_new);
}
}
}
}
else if (domain = matchDomain(['iltirreno.it', 'lanuovasardegna.it']) || matchDomain(['gazzettadimodena.it', 'gazzettadireggio.it', 'lanuovaferrara.it'])) {
if (window.location.pathname.includes('/news/')) {
let paywall = document.querySelector('span > img[alt*="Paywall"]');
if (paywall) {
let header = paywall.parentNode.parentNode;
header_nofix(header);
removeDOMElement(paywall.parentNode);
}
window.setTimeout(function () {
let banners = document.querySelectorAll('div.MuiSnackbar-root, div.css-16cchgy');
removeDOMElement(...banners);
}, 1000);
}
setCookie(/__mtr$/, '', domain, '/', 0);
}
else if (matchDomain(it_ilmessaggero_domains)) {
if (window.location.pathname.toLowerCase().includes('/amp/')) {
amp_unhide_subscr_section('amp-ad, amp-embed');
} else {
let noscroll = document.querySelector('html[style]');
if (noscroll)
noscroll.removeAttribute('style');
let ads = 'div.adv_banner, div.inread_adv, div#outbrain';
hideDOMStyle(ads);
}
}
else if (matchDomain(it_quotidiano_domains)) {
if (window.location.pathname.endsWith('/amp') || window.location.search.startsWith('?amp')) {
amp_unhide_access_hide('="c.customGranted"', '="NOT c.customGranted"', 'amp-ad, amp-embed, amp-fx-flying-carpet, .watermark-adv, .amp__watermark');
} else {
amp_redirect('div[data-testid="paywall-container"], div[class^="Paywall_paywall_"]', '', window.location.pathname + '/amp');
let ads = 'div[id^="div-gpt-ad"]';
hideDOMStyle(ads);
}
}
else if (matchDomain('italiaoggi.it')) {
let paywall = document.querySelector('div.boxAbb');
if (paywall) {
let overlay = document.querySelector('div.article-locked-overlay');
removeDOMElement(paywall, overlay);
let article_locked = document.querySelector('div.article-locked');
if (article_locked) {
article_locked.classList.remove('article-locked');
let json_script = getArticleJsonScript();
if (json_script) {
let json = JSON.parse(json_script.text);
if (json) {
let json_text = json.articleBody;
let content = article_locked.querySelector('section');
if (json_text && content) {
if (json_text && content) {
let parser = new DOMParser();
json_text = json_text.replace(/&amp;apos;/g, "'").replace(/;/g, '');
let doc = parser.parseFromString('<div><section>' + json_text + '</section></div>', 'text/html');
let content_new = doc.querySelector('div');
content.parentNode.replaceChild(content_new, content);
}
}
}
}
}
}
}
else if (domain = matchDomain(it_gedi_domains)) {
if (matchDomain(['huffingtonpost.it', 'lastampa.it'])) {
if (window.location.pathname.includes('/news/')) {
if (!window.location.pathname.match(/\amp(\/)?$/)) {
let paywall = document.querySelector('iframe#__limio_frame');
if (paywall) {
setCookie(/blaize_session/, '', domain, '/', 0);
refreshCurrentTab();
}
let modal = document.querySelector('aside#widgetDP');
removeDOMElement(modal);
} else
ampToHtml();
}
} else {
if (!window.location.pathname.match(/\amp(\/)?$/)) {
let paywall = document.querySelector('div#ph-paywall');
removeDOMElement(paywall);
setCookie(/blaize_session/, '', domain, '/', 0);
} else
ampToHtml();
}
let ads = 'div[id^="adv"]';
hideDOMStyle(ads);
}
else if (matchDomain('sport.sky.it')) {
let paywall = document.querySelector('div.c-paywall');
if (paywall) {
paywall.removeAttribute('class');
let json_script = getArticleJsonScript();
if (json_script) {
try {
let json = JSON.parse(json_script.text);
if (json) {
let json_text = json[0].articleBody;
if (json_text)
paywall.innerText = json_text;
}
} catch (err) {
console.log(err);
}
}
}
}
else if (matchDomain('tuttosport.com')) {
if (!window.location.pathname.startsWith('/amp/')) {
let paywall = document.querySelector('div[class^="MainTextTruncated_premium"]');
if (paywall) {
removeDOMElement(paywall);
let article = document.querySelector('div > div[class^="MainTextTruncated_truncatedContent"]');
if (article) {
let json_script = document.querySelector('script#__NEXT_DATA__');
if (json_script) {
try {
let json = JSON.parse(json_script.text);
if (json && json.props.pageProps.news && json.props.pageProps.news.content) {
let url_next = json.props.pageProps.news.href;
if (url_next && !window.location.pathname.includes(url_next))
window.location.href = window.location.pathname;
let parser = new DOMParser();
let doc = parser.parseFromString('<div>' + json.props.pageProps.news.content + '</div>', 'text/html');
let article_new = doc.querySelector('div');
article.parentNode.replaceChild(article_new, article);
} else
refreshCurrentTab();
} catch (err) {
console.log(err);
}
}
}
}
let ads = 'div[class^="AdUnit_"]';
hideDOMStyle(ads);
} else {
let ads = 'amp-ad, amp-embed';
hideDOMStyle(ads);
}
}
}, 1000);
// General Functions
function matchDomain(domains, hostname) {
var matched_domain = false;
if (!hostname)
hostname = window.location.hostname;
if (typeof domains === 'string')
domains = [domains];
domains.some(domain => (hostname === domain || hostname.endsWith('.' + domain)) && (matched_domain = domain));
return matched_domain;
}
function matchCookies(name) {
return document.cookie.split(';').filter(x => x.trim().match(name)).map(y => y.split('=')[0].trim())
}
function setCookie(names, value, domain = '', path = '/', days = 0) {
var max_age = days * 24 * 60 * 60;
let ck_names = Array.isArray(names) ? names : [];
if (names instanceof RegExp)
ck_names = matchCookies(names);
else if (typeof names === 'string')
ck_names = [names];
for (let ck_name of ck_names) {
document.cookie = ck_name + "=" + (value || "") + (domain ? "; domain=" + domain : '') + (path ? "; path=" + path : '') + "; max-age=" + max_age;
}
window.localStorage.clear();
}
function removeDOMElement(...elements) {
for (let element of elements) {
if (element)
element.remove();
}
}
function hideDOMElement(...elements) {
for (let element of elements) {
if (element)
element.style = 'display:none !important;';
}
}
function hideDOMStyle(selector, id = 1) {
let style = document.querySelector('head > style#ext'+ id);
if (!style && document.head) {
let sheet = document.createElement('style');
sheet.id = 'ext' + id;
sheet.innerText = selector + ' {display: none !important;}';
document.head.appendChild(sheet);
}
}
function addStyle(css, id = 1) {
let style = document.querySelector('head > style#add'+ id);
if (!style && document.head) {
let sheet = document.createElement('style');
sheet.id = 'add' + id;
sheet.innerText = css;
document.head.appendChild(sheet);
}
}
function clearPaywall(paywall, paywall_action) {
if (paywall) {
if (!paywall_action)
removeDOMElement(...paywall);
else {
for (let elem of paywall) {
if (paywall_action.rm_class)
elem.classList.remove(paywall_action.rm_class);
else if (paywall_action.rm_attrib)
elem.removeAttribute(paywall_action.rm_attrib);
}
}
}
}
function header_nofix(header, cond_sel = '', msg = 'BPC > no fix') {
if (header && typeof header === 'string')
header = document.querySelector(header);
if (header && !document.querySelector('div#bpc_nofix')) {
if (cond_sel) {
let elem = document.querySelectorAll(cond_sel);
if (elem.length)
removeDOMElement(...elem);
else
return false;
}
let nofix_div = document.createElement('div');
nofix_div.id = 'bpc_nofix';
nofix_div.style = 'margin: 20px; font-size: 20px; font-weight: bold; color: red;';
nofix_div.innerText = msg;
header.before(nofix_div);
}
}
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) {
if (amp_iframe.offsetHeight > 10) {
elem = document.createElement('iframe');
elem.src = amp_iframe.getAttribute('src').replace(/^http:/, 'https:');
elem.style = 'height: ' + amp_iframe.offsetHeight + 'px; width: 100%; border: 0px;';
if (amp_iframe.getAttribute('sandbox'))
elem.sandbox = amp_iframe.getAttribute('sandbox');
amp_iframe.parentNode.replaceChild(elem, amp_iframe);
}
} else {
par = document.createElement('p');
par.style = 'margin: 20px 0px;';
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_redirect_not_loop(amphtml) {
let amp_redirect_date = Number(sessionStorage.getItem('###_amp_redirect'));
if (!(amp_redirect_date && Date.now() - amp_redirect_date < 2000)) {
sessionStorage.setItem('###_amp_redirect', Date.now());
window.location.href = amphtml.href;
} else {
let header = (document.body && document.body.firstChild) || document.documentElement;
header_nofix(header, '', 'BPC > redirect to amp failed (disable amp-to-html extension/add-on or browser setting)');
}
}
function amp_redirect(paywall_sel, paywall_action = '', amp_url = '') {
let paywall = document.querySelectorAll(paywall_sel);
let amphtml = document.querySelector('head > link[rel="amphtml"]');
if (!amphtml && amp_url)
amphtml = {href: amp_url};
if (paywall.length && amphtml) {
clearPaywall(paywall, paywall_action);
amp_redirect_not_loop(amphtml);
}
}
function amp_unhide_subscr_section(amp_ads_sel = 'amp-ad', replace_iframes = true, amp_iframe_link = false, source = '') {
let preview = document.querySelectorAll('[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');
hideDOMStyle(amp_ads_sel, 5);
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', 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"], .piano)');
for (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);
}
hideDOMStyle(amp_ads_sel, 6);
if (replace_iframes)
amp_iframes_replace(amp_iframe_link, source);
}
function ampToHtml() {
window.setTimeout(function () {
let canonical = document.querySelector('head > link[rel="canonical"][href]');
if (canonical)
window.location.href = canonical.href;
}, 1000);
}
function refreshCurrentTab() {
window.location.reload(true);
}
function getSourceJsonScript(filter, attributes = ':not([src], [type])') {
if (typeof filter === 'string')
filter = new RegExp(filter);
let scripts = document.querySelectorAll('script' + attributes);
for (let script of scripts) {
if (script.text.match(filter))
return script;
}
return false;
}
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)":/i)) {
json_script = script;
break;
}
}
return json_script;
}
})();

884
userscript/bpc.nl.user.js Normal file
View File

@@ -0,0 +1,884 @@
// ==UserScript==
// @name Bypass Paywalls Clean - nl/be
// @version 3.9.4.1
// @description Bypass Paywalls of news sites
// @author magnolia1234
// @downloadURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=userscript/bpc.nl.user.js
// @updateURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=userscript/bpc.nl.user.js
// @homepageURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters
// @supportURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters
// @license MIT; https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=LICENSE
// @match *://*.nl/*
// @match *://*.artsenkrant.com/*
// @match *://*.businessam.be/*
// @match *://*.demorgen.be/*
// @match *://*.doorbraak.be/*
// @match *://*.gva.be/*
// @match *://*.hbvl.be/*
// @match *://*.hln.be/*
// @match *://*.humo.be/*
// @match *://*.knack.be/*
// @match *://*.kw.be/*
// @match *://*.libelle.be/*
// @match *://*.nieuwsblad.be/*
// @match *://*.projectcargojournal.com/*
// @match *://*.railfreight.cn/*
// @match *://*.railfreight.com/*
// @match *://*.railtech.be/*
// @match *://*.railtech.com/*
// @match *://*.standaard.be/*
// @match *://*.taxipro.be/*
// @connect archive.fo
// @connect archive.is
// @connect archive.li
// @connect archive.md
// @connect archive.ph
// @connect archive.vn
// @grant GM.xmlHttpRequest
// ==/UserScript==
(function() {
'use strict';
var domain;
var mobile = window.navigator.userAgent.toLowerCase().includes('mobile');
var csDoneOnce = true;
var func_post;
window.setTimeout(function () {
var overlay = document.querySelector('body.didomi-popup-open');
if (overlay)
overlay.classList.remove('didomi-popup-open');
var ads = 'div.OUTBRAIN, div[id^="taboola-"], div.ad-container, div[class*="-ad-container"], div[class*="_ad-container"], div.arc_ad, div[id^="poool-"]';
hideDOMStyle(ads, 10);
var be_mediahuis_domains = ['gva.be', 'hbvl.be', 'nieuwsblad.be', 'standaard.be'];
var be_roularta_domains = ['artsenkrant.com', 'beleggersbelangen.nl', 'flair.be', 'knack.be', 'kw.be', 'libelle.be'];
var nl_dpg_adr_domains = ['ad.nl', 'bd.nl', 'bndestem.nl', 'destentor.nl', 'ed.nl', 'gelderlander.nl', 'pzc.nl', 'tubantia.nl'];
var nl_dpg_media_domains = ['demorgen.be', 'flair.nl', 'humo.be', 'libelle.nl', 'margriet.nl', 'parool.nl', 'trouw.nl', 'volkskrant.nl'];
if (matchDomain(be_mediahuis_domains.concat(['limburger.nl']))) {
window.setTimeout(function () {
let video = document.querySelector('div.video');
func_post = function () {
if (video) {
let video_new = document.querySelector('div[id$="-streamone"], div[id^="video-player-"]') || document.querySelector('article div[style^="background-color"]');
if (!video_new) {
let empty_div = document.querySelector('div > div[aria-hidden="true"]:empty:not([class])');
if (empty_div)
video_new = empty_div.parentNode;
}
if (video_new && video_new.parentNode)
video_new.parentNode.replaceChild(video, video_new);
}
if (mobile) {
let lazy_images = document.querySelectorAll('figure img[loading="lazy"][style]');
for (let elem of lazy_images)
elem.style = 'width: 95%;';
let figures = document.querySelectorAll('figure div');
for (let elem of figures) {
elem.removeAttribute('style');
let svg = elem.querySelector('svg');
removeDOMElement(svg);
}
}
let article = document.querySelector(article_sel);
if (article) {
let pars = article.querySelectorAll('div[style*="font-size"]');
if (pars.length < 5)
header_nofix(article.querySelector('header'), '', 'BPC > no archive-fix');
}
}
let url = window.location.href;
let article_sel = 'article div[id], section div[id]:not([id^="warning"], [id^="ad_overlayer"]), main div[id]:not([id^="warning"], [id^="ad_overlayer"])';
getArchive(url, 'head > meta[name$="article_ispaidcontent"][content="true"]', '', article_sel);
}, 1500);
}
else if (matchDomain('businessam.be')) {
let paywall = document.querySelector('div.paywall');
if (paywall) {
removeDOMElement(paywall);
let article = document.querySelector('div.text-gradient');
if (article) {
let scripts = document.querySelectorAll('script:not([src]):not([type])');
let content_script;
for (let script of scripts) {
if (script.text.match(/window\.fullcontent64\s?=\s?"/)) {
content_script = script;
break;
}
}
if (content_script) {
try {
let content = decode_utf8(atob(content_script.text.split(/window\.fullcontent64\s?=\s?"/)[1].split('";')[0]));
let parser = new DOMParser();
let doc = parser.parseFromString('<div>' + content + '</div>', 'text/html');
let content_new = doc.querySelector('div');
article.parentNode.replaceChild(content_new, article);
} catch (err) {
console.log(err);
}
}
}
}
}
else if (matchDomain('businessinsider.nl')) {
getJsonUrl('div.piano-article__paywall', '', 'div.piano-article__content');
}
else if (matchDomain('doorbraak.be')) {
let paywall_sel = 'div.paywall';
let paywall = document.querySelector(paywall_sel);
if (paywall) {
removeDOMElement(paywall);
waitDOMElement(paywall_sel, 'DIV', removeDOMElement, false);
let json_script = document.querySelector('script#__NUXT_DATA__');
if (json_script) {
try {
if (!json_script.text.substr(0, 500).includes(window.location.pathname))
refreshCurrentTab();
let json = JSON.parse(json_script.text);
json = json.filter(x => typeof x === 'string' && x.startsWith('<p>'));
let json_text = json[0];
if (json_text) {
let parser = new DOMParser();
let doc = parser.parseFromString('<div>' + json_text + '</div>', 'text/html');
let content_new = doc.querySelector('div');
let article = document.querySelector('div > div.prose');
if (article) {
article.appendChild(content_new);
}
}
} catch (err) {
console.log(err);
}
}
}
}
else if (matchDomain(be_roularta_domains)) {
if (matchDomain('beleggersbelangen.nl')) {
let paywall = document.querySelector('div.unlimited-access');
if (paywall) {
removeDOMElement(paywall);
let no_account = document.querySelector('div.no-account');
if (no_account)
no_account.classList.remove('no-account');
let content_inner = document.querySelector('div.content-inner[style]');
if (content_inner)
content_inner.removeAttribute('style');
}
} else {
let paywall = document.querySelector('div[id*="wall-modal"]');
if (paywall) {
removeDOMElement(paywall);
let html = document.querySelector('html[class]');
if (html)
html.removeAttribute('class');
function roularta_noscroll(node) {
node.removeAttribute('style');
node.removeAttribute('class');
}
waitDOMAttribute('html', 'html', 'class', roularta_noscroll, true);
let intro = document.querySelectorAll('div.article-body > p, div.article-body > style');
removeDOMElement(...intro);
let locked = document.querySelector('body.locked');
if (locked)
locked.classList.remove('locked');
}
if (!window.navigator.userAgent.toLowerCase().includes('chrome') && !matchDomain(['artsenkrant.com', 'kw.be']) && window.location.href.match(/\/(\w+-){2,}/)) {
let lazy_images = document.querySelectorAll('img[src^="data:image/"][data-lazy-src]');
for (let elem of lazy_images) {
elem.src = elem.getAttribute('data-lazy-src');
}
}
}
let ads = 'div.rmgAd, div.c-header__ad';
hideDOMStyle(ads);
}
else if (matchDomain('groene.nl')) {
let url = window.location.href;
getArchive(url, 'div#closed-block', '', 'article');
let more = pageContains('div.wrapper > h2', 'Verder lezen?');
if (more.length) {
let link_text = 'https://www.groene.nl/populair';
let a_link = document.createElement('a');
a_link.href = link_text;
a_link.innerText = 'BPC > ' + link_text.split('www.')[1];
more[0].parentNode.append(document.createElement('br'), a_link);
}
}
else if (matchDomain(['lc.nl', 'dvhn.nl']) || document.querySelector('head > link[href*=".ndcmediagroep.nl/"]')) {
let ads = 'div.top__ad, div.marketingblock-article';
hideDOMStyle(ads);
}
else if (matchDomain('linda.nl')) {
window.setTimeout(function () {
let paywall = document.querySelector('div.premium-login-box_login-box');
if (paywall) {
removeDOMElement(paywall);
let article = document.querySelector('article');
if (article) {
let filter = /^window\.__INITIAL_PROPS__\s?=\s?/;
let json_script = getSourceJsonScript(filter);
if (json_script) {
try {
let json = JSON.parse(json_script.text.split(filter)[1]);
if (json) {
let slug = json.slug;
if ((slug && !window.location.pathname.includes(slug)) || !json.viewData)
refreshCurrentTab();
if (json && json.viewData.article && json.viewData.article.modules) {
let modules = json.viewData.article.modules;
for (let elem of modules) {
let type = elem.acf_fc_layout;
if (type) {
let item = document.createElement('div');
if (['body_text', 'intro', 'quote'].includes(type)) {
if (elem.text) {
let parser = new DOMParser();
let doc = parser.parseFromString('<div style="margin: 20px;">' + (elem.title ? elem.title : '') + elem.text.replace(/\r\n/g, '<br>') + '</div>', 'text/html');
item = doc.querySelector('div');
if (type === 'intro') {
let intro = item.querySelector('p');
if (intro)
intro.style = 'font-weight: bold; ';
} else if (type === 'quote')
item.style['text-align'] = 'center';
article.append(item);
}
} else if (type === 'image') {
let elem_images = elem.images_portrait || elem.images_landscape;
if (elem_images && elem_images.length) {
for (let img of elem_images) {
let url = img.image.sizes.large;
let caption_text = img.credits ? img.credits.replace(/(\n|<[^<]*>)/g, '') : '';
item = makeFigure(url, caption_text, {style: 'width: 100%;'});
article.append(item);
}
}
} else
console.log(elem);
}
}
} else
header_nofix('div.article-content_base');
}
} catch (err) {
console.log(err);
}
}
}
}
}, 1000);
}
else if (matchDomain(nl_dpg_adr_domains.concat(['hln.be']))) {
let sub_sel = 'article[id^="PURCHASE"]';
let sub = document.querySelector(sub_sel + ' > button');
if (sub)
sub.click();
func_post = function () {
let shades = document.querySelectorAll('div[style*="background-color"][style*=";width"]');
for (let elem of shades)
elem.style.width = '85%';
let lazy_images = document.querySelectorAll('picture img[loading="lazy"][style]');
for (let elem of lazy_images)
elem.style = 'width: 95%;';
header_nofix('footer', sub_sel, 'BPC > no archive-fix');
}
let article_sel = 'div#remaining-paid-content';
let url = window.location.href;
getArchive(url, article_sel + '[data-reduced="true"]', {rm_attrib: 'data-reduced'}, article_sel);
}
else if (matchDomain(nl_dpg_media_domains)) {
setCookie('TID_ID', '', '', '/', 0);
let banners = 'aside[data-temptation-position^="ARTICLE_"], div[data-temptation-position^="PAGE_"], div[class^="ad--"], div[id^="article_paragraph_"]';
hideDOMStyle(banners);
window.setTimeout(function () {
let elem_hidden = document.querySelectorAll('[class^="artstyle__"][style="display: none;"]');
for (let elem of elem_hidden)
elem.removeAttribute('style');
}, 500);
}
else if (matchDomain('nrc.nl')) {
setCookie('counter', '', '', '/', 0, true);
let banners = document.querySelectorAll('div[id$="modal__overlay"], div.header__subscribe-bar, div.banner');
removeDOMElement(...banners);
}
else if (matchDomain('telegraaf.nl')) {
let premium = document.querySelector('div[class^="Article__premium"] > label, div.PopupWrapper__paywall');
let paywall = document.querySelector('data-hydrate[data-name="PaywallHandler"]');
let article = document.querySelector('section > div.DetailArticleImage') || document.querySelector('section > p.Article__intro');
if (paywall && window.location.pathname.startsWith('/video/'))
removeDOMElement(paywall);
if (premium && paywall && article) {
let div_main = document.createElement('div');
div_main.style = 'margin: 20px 0px;';
let div_elem = document.createElement('div');
let par_style = 'font-weight: normal; font-size: 16px; line-height: 1.5;';
function show_text(window_text, div_main) {
window_text = window_text.split('window.telegraaf.')[0].replace(/(^\s?=\s?"|";$|\\")/gm, '').replace(/\\\\u003c/gm, '<');
let parser = new DOMParser();
let doc = parser.parseFromString('<div>' + window_text + '</div>', 'text/html');
let article_new = doc.querySelector('div');
let pars = article_new.querySelectorAll('p');
for (let par of pars)
par.style = 'margin: 10px 0px;';
let placeholders = article_new.querySelectorAll('div.TeaserImage__placeholder');
for (let elem of placeholders)
elem.removeAttribute('class');
let media = article_new.querySelectorAll('div.NewsletterForm, div.DetailArticleVideo');
removeDOMElement(...media);
let twitter_quotes = article_new.querySelectorAll('blockquote.twitter-tweet > a[href]');
for (let elem of twitter_quotes) {
if (!elem.innerText) {
elem.innerText = elem.href;
elem.target = '_blank';
}
}
if (mobile) {
let art_images = article_new.querySelectorAll('div.DetailArticleImage > div > img');
for (let elem of art_images)
elem.style.width = '95%';
}
div_main.appendChild(article_new);
}
let window_script = document.querySelector('script#scr-tlg-body');
if (window_script && window_script.text.includes('window.telegraaf.articleBodyBlocks')) {
removeDOMElement(paywall);
let window_text = window_script.text.split('window.telegraaf.articleBodyBlocks')[1];
if (window_text)
show_text(window_text, div_main);
} else {
removeDOMElement(paywall);
let url = window.location.href.split(/[#\?]/)[0];
fetch(url)
.then(response => {
if (response.ok) {
response.text().then(html => {
if (html.includes('window.telegraaf.articleBodyBlocks')) {
let window_text = html.split('window.telegraaf.articleBodyBlocks')[1].split('</script>')[0];
if (window_text)
show_text(window_text, div_main);
}
})
}
})
}
article.after(div_main);
}
let ads = 'div.WebpushOptin, div[data-ad-position]';
hideDOMStyle(ads);
}
else if (matchDomain('vn.nl')) {
let paywall = document.querySelectorAll('section[class^="c-paywall"]');
if (paywall.length) {
removeDOMElement(...paywall);
let article = document.querySelector('div.c-article-content__container');
if (article) {
let json_script = document.querySelector('script#__NEXT_DATA__');
if (json_script) {
try {
let json = JSON.parse(json_script.text);
if (json && json.props.pageProps.article && json.props.pageProps.article.content) {
let parser = new DOMParser();
let doc = parser.parseFromString('<div>' + json.props.pageProps.article.content + '</div>', 'text/html');
let content_new = doc.querySelector('div');
article.innerHTML = '';
article.appendChild(content_new);
} else
refreshCurrentTab();
} catch (err) {
console.log(err);
}
}
}
let noscroll = document.querySelector('html[class]');
if (noscroll)
noscroll.removeAttribute('class');
}
}
}, 1000);
// General Functions
function matchDomain(domains, hostname) {
var matched_domain = false;
if (!hostname)
hostname = window.location.hostname;
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 matchUrlDomain(domains, url) {
return matchDomain(domains, urlHost(url));
}
function setCookie(name, value, domain, path, days, localstorage_hold = false) {
var max_age = days * 24 * 60 * 60;
document.cookie = name + "=" + (value || "") + "; domain=" + domain + "; path=" + path + "; max-age=" + max_age;
if (!localstorage_hold)
window.localStorage.clear();
}
function removeDOMElement(...elements) {
for (let element of elements) {
if (element)
element.remove();
}
}
function hideDOMElement(...elements) {
for (let element of elements) {
if (element)
element.style = 'display:none !important;';
}
}
function hideDOMStyle(selector, id = 1) {
let style = document.querySelector('head > style#ext'+ id);
if (!style && document.head) {
let sheet = document.createElement('style');
sheet.id = 'ext' + id;
sheet.innerText = selector + ' {display: none !important;}';
document.head.appendChild(sheet);
}
}
function addStyle(css, id = 1) {
let style = document.querySelector('head > style#add'+ id);
if (!style && document.head) {
let sheet = document.createElement('style');
sheet.id = 'add' + id;
sheet.innerText = css;
document.head.appendChild(sheet);
}
}
function clearPaywall(paywall, paywall_action) {
if (paywall) {
if (!paywall_action)
removeDOMElement(...paywall);
else {
for (let elem of paywall) {
if (paywall_action.rm_class)
elem.classList.remove(paywall_action.rm_class);
else if (paywall_action.rm_attrib)
elem.removeAttribute(paywall_action.rm_attrib);
}
}
}
}
function waitDOMElement(selector, tagName = '', callback, multiple = false) {
new window.MutationObserver(function (mutations) {
for (let mutation of mutations) {
for (let node of mutation.addedNodes) {
if (!tagName || (node.tagName === tagName)) {
if (node.matches(selector)) {
callback(node);
if (!multiple)
this.disconnect();
}
}
}
}
}).observe(document, {
subtree: true,
childList: true
});
}
function waitDOMAttribute(selector, tagName = '', attributeName = '', callback, multiple = false) {
let targetNode = document.querySelector(selector);
if (!targetNode)
return;
new window.MutationObserver(function (mutations) {
for (let mutation of mutations) {
if (mutation.target.attributes[attributeName]) {
callback(mutation.target);
if (!multiple)
this.disconnect();
}
}
}).observe(targetNode, {
attributes: true,
attributeFilter: [attributeName]
});
}
function getSelectorLevel(selector) {
if (selector.replace(/,\s+/g, ',').match(/[>\s]+/))
selector = selector.replace(/,\s+/g, ',').split(',').map(x => x.match(/[>\s]+/) ? x + ', ' + x.split(/[>\s]+/).pop() : x).join(', ');
return selector;
}
function getArticleSrc(url, url_src, proxy, base64, selector, text_fail = '', selector_source = selector, selector_archive = selector) {
let url_fetch = url_src || url;
GM.xmlHttpRequest({
method: "GET",
url: url_fetch,
onload: function (response) {
let html = response.responseText;
if (proxy && base64) {
html = decode_utf8(atob(html));
selector_source = 'body';
}
let recursive;
if (url.startsWith('https://archive.')) {
if (url_fetch.includes('/https')) {
if (html.includes('<div class="TEXT-BLOCK"')) {
url_src = html.split('<div class="TEXT-BLOCK"')[1].split('</div>')[0].split('href="')[1].split('"')[0];
getArticleSrc(url, url_src, proxy, base64, selector, text_fail, selector_source, selector_archive);
recursive = true;
} else
html = '';
}
}
if (!recursive)
replaceDomElementExtSrc(url, url_src, html, proxy, base64, selector, text_fail, selector_source, selector_archive);
}
});
}
function replaceDomElementExt(url, proxy, base64, selector, text_fail = '', selector_source = selector, selector_archive = selector) {
let article = document.querySelector(selector);
if (!article)
return;
if (proxy) {
if (!text_fail) {
if (url.startsWith('https://archive.'))
text_fail = 'BPC > Try for full article text (no need to report issue for external site):\r\n';
else if (!matchUrlDomain(window.location.hostname, url))
text_fail = 'BPC > failed to load from external site:\r\n';
}
getArticleSrc(url, '', proxy, base64, selector, text_fail, selector_source, selector_archive);
} else {
let options = {};
fetch(url, options)
.then(response => {
let article = document.querySelector(selector);
if (response.ok) {
response.text().then(html => {
replaceDomElementExtSrc(url, '', html, false, base64, selector, text_fail, selector_source);
});
} else {
replaceTextFail(url, article, proxy, text_fail);
}
}).catch(function (err) {
false;
});
}
}
var selector_level = false;
function replaceDomElementExtSrc(url, url_src, html, proxy, base64, selector, text_fail = '', selector_source = selector, selector_archive = selector) {
let article = document.querySelector(selector);
let article_link = document.querySelector(selector_archive);
let no_content_msg = '&nbsp;| no article content found! | :';
if (html) {
if (!proxy && base64) {
html = decode_utf8(atob(html));
selector_source = 'body';
}
let parser = new DOMParser();
window.setTimeout(function () {
if (url.startsWith('https://archive.') && url_src) {
let domain_archive = url.match(/^https:\/\/(archive\.\w{2})/)[1];
let pathname = new URL(url_src).pathname;
html = html.replace(new RegExp('https:\\/\\/' + domain_archive.replace('.', '\\.') + '\\/o\\/\\w+\\/', 'g'), '').replace(new RegExp("(src=\"|background-image:url\\(')" + pathname.replace('/', '\\/'), 'g'), "$1" + 'https://' + domain_archive + pathname);
}
let doc = parser.parseFromString(html, 'text/html');
if (selector_level)
selector_source = getSelectorLevel(selector_source);
let article_new = doc.querySelector(selector_source);
if (article_new) {
if (article && article.parentNode) {
if (url.startsWith('https://archive.')) {
let arch_dom = (selector_archive !== selector) ? (article_new.querySelector(selector_archive) || document.querySelector(selector_archive)) : article_new;
if (arch_dom) {
if (arch_dom.firstChild)
arch_dom = arch_dom.firstChild;
let arch_div = document.createElement('div');
arch_div.appendChild(archiveLink_renew(url_src));
arch_div.appendChild(archiveLink(window.location.href, 'BPC > Full article text fetched from (no need to report issue for external site):\r\n'));
arch_div.style = 'margin: 0px 0px 50px;';
arch_dom.before(arch_div);
}
let targets = article_new.querySelectorAll('a[target="_blank"][href^="' + window.location.origin + '"]');
for (let elem of targets)
elem.removeAttribute('target');
let invalid_links = article_new.querySelectorAll('link[rel*="preload"]:not([href])');
removeDOMElement(...invalid_links);
}
window.setTimeout(function () {
if (article.parentNode) {
article.parentNode.replaceChild(article_new, article);
if (func_post)
func_post();
}
}, 200);
}
} else
replaceTextFail(url, article_link, proxy, text_fail.replace(':', no_content_msg));
}, 200);
} else {
replaceTextFail(url, article_link, proxy, url_src ? text_fail.replace(':', no_content_msg) : text_fail);
}
}
function replaceTextFail(url, article, proxy, text_fail) {
if (text_fail && article) {
let text_fail_div = document.createElement('div');
text_fail_div.id = 'bpc_fail';
text_fail_div.setAttribute('style', 'margin: 0px 50px; font-weight: bold; color: red;');
text_fail_div.appendChild(document.createTextNode(text_fail));
if (proxy) {
if (url.startsWith('https://archive.')) {
text_fail_div = archiveLink(url.replace(/^https:\/\/archive\.\w{2}\//, ''), text_fail);
} else {
let a_link = document.createElement('a');
a_link.innerText = url;
a_link.href = url;
a_link.target = '_blank';
text_fail_div.appendChild(a_link);
}
}
if (article.firstChild)
article.firstChild.before(text_fail_div);
else
article.appendChild(text_fail_div);
}
}
function randomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
function archiveRandomDomain() {
let tld_array = ['fo', 'is', 'li', 'md', 'ph', 'vn'];
let tld = tld_array[randomInt(6)];
return 'archive.' + tld;
}
function getArchive(url, paywall_sel, paywall_action = '', selector, text_fail = '', selector_source = selector, selector_archive = selector) {
let url_archive = 'https://' + archiveRandomDomain() + '/' + url.split(/[#\?]/)[0];
let paywall = document.querySelectorAll(paywall_sel);
if (paywall.length) {
clearPaywall(paywall, paywall_action);
replaceDomElementExt(url_archive, true, false, selector, text_fail, selector_source, selector_archive);
}
}
function archiveLink(url, text_fail = 'BPC > Try for full article text (no need to report issue for external site):\r\n') {
return externalLink(['archive.today', archiveRandomDomain()], 'https://{domain}?run=1&url={url}', url, text_fail);
}
function archiveLink_renew(url, text_fail = 'BPC > Only use to renew if text is incomplete or updated:\r\n') {
return externalLink([new URL(url).hostname], '{url}/again?url=' + window.location.href, url, text_fail);
}
function nftLink(url, text_fail = 'BPC > Full article text:\r\n') {
return externalLink(['1ft.io'], 'https://{domain}/{url}', url, text_fail);
}
function externalLink(domains, ext_url_templ, url, text_fail = 'BPC > Full article text:\r\n') {
let text_fail_div = document.createElement('div');
text_fail_div.id = 'bpc_archive';
text_fail_div.setAttribute('style', 'margin: 20px; font-size: 20px; font-weight: bold; color: red;');
let parser = new DOMParser();
text_fail = text_fail.replace(/\[(?<url>[^\]]+)\]/g, function (match, url) {
return "<a href='" + url + "' target='_blank' style='color: red'>" + new URL(url).hostname + "</a>";
});
let doc = parser.parseFromString('<span>' + text_fail + '</span>', 'text/html');
let elem = doc.querySelector('span');
text_fail_div.appendChild(elem);
for (let domain of domains) {
let ext_url = ext_url_templ.replace('{domain}', domain).replace('{url}', url.split('?')[0]);
let a_link = document.createElement('a');
a_link.innerText = domain;
a_link.href = ext_url;
a_link.target = '_blank';
text_fail_div.appendChild(document.createTextNode(' | '));
text_fail_div.appendChild(a_link);
}
return text_fail_div;
}
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)":/i)) {
json_script = script;
break;
}
}
return json_script;
}
function getNestedKeys(obj, key) {
if (key in obj)
return obj[key];
let keys = key.split('.');
let value = obj;
for (let i = 0; i < keys.length; i++) {
value = value[keys[i]];
if (value === undefined)
break;
}
return value;
}
function getJsonUrlText(article, callback, article_id = '', key = '', url_rest = false, url_slash = false) {
let json_url_dom = document.querySelector('head > link[rel="alternate"][type="application/json"][href]');
let json_url;
if (json_url_dom)
json_url = json_url_dom.href;
if (!json_url && article_id)
json_url = window.location.origin + '/wp-json/wp/v2/posts/' + article_id;
if (url_rest)
json_url = json_url.replace('/wp-json/', '/?rest_route=/');
else if (url_slash)
json_url = json_url.replace('/wp-json/', '//wp-json/');
if (json_url) {
fetch(json_url)
.then(response => {
if (response.ok) {
response.json().then(json => {
try {
let json_text = parseHtmlEntities(!key ? json.content.rendered : getNestedKeys(json, key));
callback(json_text, article);
} catch (err) {
console.log(err);
}
});
}
});
}
}
function getJsonUrlAdd(json_text, article, art_options = {}) {
let art_type = 'div';
let art_attrib = '';
if (Object.keys(art_options).length) {
if (art_options.art_type)
art_type = art_options.art_type;
if (art_options.art_class)
art_attrib += ' class="' + art_options.art_class + '"';
if (art_options.art_id)
art_attrib += ' id="' + art_options.art_id + '"';
if (art_options.art_style)
art_attrib += ' style="' + art_options.art_style + '"';
if (art_options.func_text)
json_text = art_options.func_text(json_text);
}
let parser = new DOMParser();
let doc = parser.parseFromString('<' + art_type + art_attrib + '>' + json_text + '</' + art_type + '>', 'text/html');
let article_new = doc.querySelector(art_type);
if (art_options.art_append || !article.parentNode) {
if (!art_options.art_hold)
article.innerHTML = '';
article.appendChild(article_new);
} else
article.parentNode.replaceChild(article_new, article);
if (func_post)
func_post();
}
function getJsonUrl(paywall_sel, paywall_action = '', article_sel, art_options = {}, article_id = '', key = '', url_rest = false, url_slash = false) {
let paywall = document.querySelectorAll(paywall_sel);
let article = document.querySelector(article_sel);
if (paywall.length && article) {
clearPaywall(paywall, paywall_action);
getJsonUrlText(article, (json_text, article) => {
if (json_text && article)
getJsonUrlAdd(json_text, article, art_options);
}, article_id, key, url_rest, url_slash);
}
}
function header_nofix(header, cond_sel = '', msg = 'BPC > no fix') {
if (header && typeof header === 'string')
header = document.querySelector(header);
if (header && !document.querySelector('div#bpc_nofix')) {
if (cond_sel) {
let elem = document.querySelectorAll(cond_sel);
if (elem.length)
removeDOMElement(...elem);
else
return false;
}
let nofix_div = document.createElement('div');
nofix_div.id = 'bpc_nofix';
nofix_div.style = 'margin: 20px; font-size: 20px; font-weight: bold; color: red;';
nofix_div.innerText = msg;
header.before(nofix_div);
}
}
function pageContains(selector, text) {
let elements = document.querySelectorAll(selector);
return Array.prototype.filter.call(elements, function (element) {
return RegExp(text).test(element.textContent);
});
}
function parseHtmlEntities(encodedString) {
let translate_re = /&(nbsp|amp|quot|lt|gt|deg|hellip|laquo|raquo|ldquo|rdquo|lsquo|rsquo|mdash);/g;
let translate = {"nbsp": " ", "amp": "&", "quot": "\"", "lt": "<", "gt": ">", "deg": "°", "hellip": "…",
"laquo": "«", "raquo": "»", "ldquo": "“", "rdquo": "”", "lsquo": "", "rsquo": "", "mdash": "—"};
return encodedString.replace(translate_re, function (match, entity) {
return translate[entity];
}).replace(/&#(\d+);/gi, function (match, numStr) {
let num = parseInt(numStr, 10);
return String.fromCharCode(num);
});
}
function encode_utf8(str) {
return unescape(encodeURIComponent(str));
}
function decode_utf8(str) {
return decodeURIComponent(escape(str));
}
function ampToHtml() {
window.setTimeout(function () {
let canonical = document.querySelector('head > link[rel="canonical"][href]');
if (canonical)
window.location.href = canonical.href;
}, 1000);
}
function refreshCurrentTab() {
window.location.reload(true);
}
})();

506
userscript/bpc.pl.user.js Normal file
View File

@@ -0,0 +1,506 @@
// ==UserScript==
// @name Bypass Paywalls Clean - pl
// @version 3.9.2.0
// @description Bypass Paywalls of news sites
// @author magnolia1234
// @downloadURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=userscript/bpc.pl.user.js
// @updateURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=userscript/bpc.pl.user.js
// @homepageURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters
// @supportURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters
// @license MIT; https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=LICENSE
// @match *://*.auto-swiat.pl/*
// @match *://*.businessinsider.com.pl/*
// @match *://*.forbes.pl/*
// @match *://*.komputerswiat.pl/*
// @match *://*.magazyn-kuchnia.pl/*
// @match *://*.newsweek.pl/*
// @match *://*.onet.pl/*
// @match *://*.parkiet.com/*
// @match *://*.pb.pl/*
// @match *://*.rp.pl/*
// @match *://*.wyborcza.biz/*
// @match *://*.wyborcza.pl/*
// @match *://*.wysokieobcasy.pl/*
// @connect archive.fo
// @connect archive.is
// @connect archive.li
// @connect archive.md
// @connect archive.ph
// @connect archive.vn
// @grant GM.xmlHttpRequest
// ==/UserScript==
(function() {
'use strict';
window.setTimeout(function () {
var domain;
var mobile = window.navigator.userAgent.toLowerCase().includes('mobile');
var csDoneOnce = true;
var func_post;
var overlay = document.querySelector('body.didomi-popup-open');
if (overlay)
overlay.classList.remove('didomi-popup-open');
var ads = 'div.OUTBRAIN, div[id^="taboola-"], div.ad-container, div[class*="-ad-container"], div[class*="_ad-container"], div.arc_ad, div[id^="poool-"]';
hideDOMStyle(ads, 10);
var pl_ringier_domains = ['auto-swiat.pl', 'businessinsider.com.pl', 'forbes.pl', 'komputerswiat.pl', 'newsweek.pl', 'onet.pl'];
if (matchDomain('pb.pl')) {
let paywall = document.querySelector('div.paywall');
if (paywall) {
paywall.classList.remove('paywall');
let article_hidden = paywall.querySelector('section.o-article-content');
if (article_hidden)
article_hidden.removeAttribute('class');
let loader = document.querySelector('div.o-piano-template-loader-box');
removeDOMElement(loader);
}
}
else if (matchDomain(pl_ringier_domains)) {
if (matchDomain('businessinsider.com.pl')) {
let paywall = document.querySelector('div#content-premium-offer');
removeDOMElement(paywall);
}
let premium = document.querySelector('div.contentPremium[style]');
if (premium) {
premium.removeAttribute('class');
premium.removeAttribute('style');
}
let ads = 'div.adPlaceholder , div[class^="Ad"][class*="Placeholder_"], div[data-placeholder-caption], div[data-run-module$=".floatingAd"], aside[data-ad-container], aside.adsContainer, [class^="pwAds"], .hide-for-paying, div.onet-ad, div.bottomBar, ad-default';
hideDOMStyle(ads);
}
else if (matchDomain(['rp.pl', 'parkiet.com'])) {
let paywall = document.querySelector('div.paywallComp');
if (paywall) {
removeDOMElement(paywall);
let article = document.querySelector('div.article--content');
if (article) {
let url = window.location.href;
article.firstChild.before(googleSearchToolLink(url));
}
}
}
else if (matchDomain(['wyborcza.biz', 'wyborcza.pl', 'wysokieobcasy.pl', 'magazyn-kuchnia.pl'])) {
let url = window.location.href;
func_post = function () {
let empty_spans = document.querySelectorAll('figure > a > span:empty');
removeDOMElement(...empty_spans);
}
if (matchDomain(['wyborcza.biz', 'wyborcza.pl']))
getArchive(url, 'div.article--content-fadeout', {rm_attrib: 'class'}, 'div.container[class*="pt"]', '', 'div.body > div:not([style*="background-color:"]):not([old-position])');
else
getArchive(url, 'section.fade-out-article', {rm_attrib: 'class'}, 'article');
let ads = 'div[id^="adUnit"], div[id^="ads-"]';
hideDOMStyle(ads);
}
}, 1000);
// General Functions
function matchDomain(domains, hostname) {
var matched_domain = false;
if (!hostname)
hostname = window.location.hostname;
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 matchUrlDomain(domains, url) {
return matchDomain(domains, urlHost(url));
}
function setCookie(name, value, domain, path, days, localstorage_hold = false) {
var max_age = days * 24 * 60 * 60;
document.cookie = name + "=" + (value || "") + "; domain=" + domain + "; path=" + path + "; max-age=" + max_age;
if (!localstorage_hold)
window.localStorage.clear();
}
function removeDOMElement(...elements) {
for (let element of elements) {
if (element)
element.remove();
}
}
function hideDOMElement(...elements) {
for (let element of elements) {
if (element)
element.style = 'display:none !important;';
}
}
function hideDOMStyle(selector, id = 1) {
let style = document.querySelector('head > style#ext'+ id);
if (!style && document.head) {
let sheet = document.createElement('style');
sheet.id = 'ext' + id;
sheet.innerText = selector + ' {display: none !important;}';
document.head.appendChild(sheet);
}
}
function addStyle(css, id = 1) {
let style = document.querySelector('head > style#add'+ id);
if (!style && document.head) {
let sheet = document.createElement('style');
sheet.id = 'add' + id;
sheet.innerText = css;
document.head.appendChild(sheet);
}
}
function clearPaywall(paywall, paywall_action) {
if (paywall) {
if (!paywall_action)
removeDOMElement(...paywall);
else {
for (let elem of paywall) {
if (paywall_action.rm_class)
elem.classList.remove(paywall_action.rm_class);
else if (paywall_action.rm_attrib)
elem.removeAttribute(paywall_action.rm_attrib);
}
}
}
}
function waitDOMElement(selector, tagName = '', callback, multiple = false) {
new window.MutationObserver(function (mutations) {
for (let mutation of mutations) {
for (let node of mutation.addedNodes) {
if (!tagName || (node.tagName === tagName)) {
if (node.matches(selector)) {
callback(node);
if (!multiple)
this.disconnect();
}
}
}
}
}).observe(document, {
subtree: true,
childList: true
});
}
function waitDOMAttribute(selector, tagName = '', attributeName = '', callback, multiple = false) {
let targetNode = document.querySelector(selector);
if (!targetNode)
return;
new window.MutationObserver(function (mutations) {
for (let mutation of mutations) {
if (mutation.target.attributes[attributeName]) {
callback(mutation.target);
if (!multiple)
this.disconnect();
}
}
}).observe(targetNode, {
attributes: true,
attributeFilter: [attributeName]
});
}
function getSelectorLevel(selector) {
if (selector.replace(/,\s+/g, ',').match(/[>\s]+/))
selector = selector.replace(/,\s+/g, ',').split(',').map(x => x.match(/[>\s]+/) ? x + ', ' + x.split(/[>\s]+/).pop() : x).join(', ');
return selector;
}
function getArticleSrc(url, url_src, proxy, base64, selector, text_fail = '', selector_source = selector, selector_archive = selector) {
let url_fetch = url_src || url;
GM.xmlHttpRequest({
method: "GET",
url: url_fetch,
onload: function (response) {
let html = response.responseText;
if (proxy && base64) {
html = decode_utf8(atob(html));
selector_source = 'body';
}
let recursive;
if (url.startsWith('https://archive.')) {
if (url_fetch.includes('/https')) {
if (html.includes('<div class="TEXT-BLOCK"')) {
url_src = html.split('<div class="TEXT-BLOCK"')[1].split('</div>')[0].split('href="')[1].split('"')[0];
getArticleSrc(url, url_src, proxy, base64, selector, text_fail, selector_source, selector_archive);
recursive = true;
} else
html = '';
}
}
if (!recursive)
replaceDomElementExtSrc(url, url_src, html, proxy, base64, selector, text_fail, selector_source, selector_archive);
}
});
}
function replaceDomElementExt(url, proxy, base64, selector, text_fail = '', selector_source = selector, selector_archive = selector) {
let article = document.querySelector(selector);
if (!article)
return;
if (proxy) {
if (!text_fail) {
if (url.startsWith('https://archive.'))
text_fail = 'BPC > Try for full article text (no need to report issue for external site):\r\n';
else if (!matchUrlDomain(window.location.hostname, url))
text_fail = 'BPC > failed to load from external site:\r\n';
}
getArticleSrc(url, '', proxy, base64, selector, text_fail, selector_source, selector_archive);
} else {
let options = {};
fetch(url, options)
.then(response => {
let article = document.querySelector(selector);
if (response.ok) {
response.text().then(html => {
replaceDomElementExtSrc(url, '', html, false, base64, selector, text_fail, selector_source);
});
} else {
replaceTextFail(url, article, proxy, text_fail);
}
}).catch(function (err) {
false;
});
}
}
var selector_level = false;
function replaceDomElementExtSrc(url, url_src, html, proxy, base64, selector, text_fail = '', selector_source = selector, selector_archive = selector) {
let article = document.querySelector(selector);
let article_link = document.querySelector(selector_archive);
let no_content_msg = '&nbsp;| no article content found! | :';
if (html) {
if (!proxy && base64) {
html = decode_utf8(atob(html));
selector_source = 'body';
}
let parser = new DOMParser();
window.setTimeout(function () {
if (url.startsWith('https://archive.') && url_src) {
let domain_archive = url.match(/^https:\/\/(archive\.\w{2})/)[1];
let pathname = new URL(url_src).pathname;
html = html.replace(new RegExp('https:\\/\\/' + domain_archive.replace('.', '\\.') + '\\/o\\/\\w+\\/', 'g'), '').replace(new RegExp("(src=\"|background-image:url\\(')" + pathname.replace('/', '\\/'), 'g'), "$1" + 'https://' + domain_archive + pathname);
}
let doc = parser.parseFromString(html, 'text/html');
if (selector_level)
selector_source = getSelectorLevel(selector_source);
let article_new = doc.querySelector(selector_source);
if (article_new) {
if (article && article.parentNode) {
if (url.startsWith('https://archive.')) {
let arch_dom = (selector_archive !== selector) ? (article_new.querySelector(selector_archive) || document.querySelector(selector_archive)) : article_new;
if (arch_dom) {
if (arch_dom.firstChild)
arch_dom = arch_dom.firstChild;
let arch_div = document.createElement('div');
arch_div.appendChild(archiveLink_renew(url_src));
arch_div.appendChild(archiveLink(window.location.href, 'BPC > Full article text fetched from (no need to report issue for external site):\r\n'));
arch_div.style = 'margin: 0px 0px 50px;';
arch_dom.before(arch_div);
}
let targets = article_new.querySelectorAll('a[target="_blank"][href^="' + window.location.origin + '"]');
for (let elem of targets)
elem.removeAttribute('target');
let invalid_links = article_new.querySelectorAll('link[rel*="preload"]:not([href])');
removeDOMElement(...invalid_links);
}
window.setTimeout(function () {
if (article.parentNode) {
article.parentNode.replaceChild(article_new, article);
if (func_post)
func_post();
}
}, 200);
}
} else
replaceTextFail(url, article_link, proxy, text_fail.replace(':', no_content_msg));
}, 200);
} else {
replaceTextFail(url, article_link, proxy, url_src ? text_fail.replace(':', no_content_msg) : text_fail);
}
}
function replaceTextFail(url, article, proxy, text_fail) {
if (text_fail && article) {
let text_fail_div = document.createElement('div');
text_fail_div.id = 'bpc_fail';
text_fail_div.setAttribute('style', 'margin: 0px 50px; font-weight: bold; color: red;');
text_fail_div.appendChild(document.createTextNode(text_fail));
if (proxy) {
if (url.startsWith('https://archive.')) {
text_fail_div = archiveLink(url.replace(/^https:\/\/archive\.\w{2}\//, ''), text_fail);
} else {
let a_link = document.createElement('a');
a_link.innerText = url;
a_link.href = url;
a_link.target = '_blank';
text_fail_div.appendChild(a_link);
}
}
if (article.firstChild)
article.firstChild.before(text_fail_div);
else
article.appendChild(text_fail_div);
}
}
function randomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
function archiveRandomDomain() {
let tld_array = ['fo', 'is', 'li', 'md', 'ph', 'vn'];
let tld = tld_array[randomInt(6)];
return 'archive.' + tld;
}
function getArchive(url, paywall_sel, paywall_action = '', selector, text_fail = '', selector_source = selector, selector_archive = selector) {
let url_archive = 'https://' + archiveRandomDomain() + '/' + url.split(/[#\?]/)[0];
let paywall = document.querySelectorAll(paywall_sel);
if (paywall.length) {
clearPaywall(paywall, paywall_action);
replaceDomElementExt(url_archive, true, false, selector, text_fail, selector_source, selector_archive);
}
}
function archiveLink(url, text_fail = 'BPC > Try for full article text (no need to report issue for external site):\r\n') {
return externalLink(['archive.today', archiveRandomDomain()], 'https://{domain}?run=1&url={url}', url, text_fail);
}
function archiveLink_renew(url, text_fail = 'BPC > Only use to renew if text is incomplete or updated:\r\n') {
return externalLink([new URL(url).hostname], '{url}/again?url=' + window.location.href, url, text_fail);
}
function googleSearchToolLink(url, text_fail = 'BPC > Try for full article text (test url & copy html (tab) code to [https://codebeautify.org/htmlviewer]):\r\n') {
return externalLink(['search.google.com'], 'https://search.google.com/test/rich-results?url={url}', encodeURIComponent(url), text_fail);
}
function externalLink(domains, ext_url_templ, url, text_fail = 'BPC > Full article text:\r\n') {
let text_fail_div = document.createElement('div');
text_fail_div.id = 'bpc_archive';
text_fail_div.setAttribute('style', 'margin: 20px; font-size: 20px; font-weight: bold; color: red;');
let parser = new DOMParser();
text_fail = text_fail.replace(/\[(?<url>[^\]]+)\]/g, function (match, url) {
return "<a href='" + url + "' target='_blank' style='color: red'>" + new URL(url).hostname + "</a>";
});
let doc = parser.parseFromString('<span>' + text_fail + '</span>', 'text/html');
let elem = doc.querySelector('span');
text_fail_div.appendChild(elem);
for (let domain of domains) {
let ext_url = ext_url_templ.replace('{domain}', domain).replace('{url}', url.split('?')[0]);
let a_link = document.createElement('a');
a_link.innerText = domain;
a_link.href = ext_url;
a_link.target = '_blank';
text_fail_div.appendChild(document.createTextNode(' | '));
text_fail_div.appendChild(a_link);
}
return text_fail_div;
}
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)":/i)) {
json_script = script;
break;
}
}
return json_script;
}
function getNestedKeys(obj, key) {
if (key in obj)
return obj[key];
let keys = key.split('.');
let value = obj;
for (let i = 0; i < keys.length; i++) {
value = value[keys[i]];
if (value === undefined)
break;
}
return value;
}
function header_nofix(header, cond_sel = '', msg = 'BPC > no fix') {
if (header && typeof header === 'string')
header = document.querySelector(header);
if (header && !document.querySelector('div#bpc_nofix')) {
if (cond_sel) {
let elem = document.querySelectorAll(cond_sel);
if (elem.length)
removeDOMElement(...elem);
else
return false;
}
let nofix_div = document.createElement('div');
nofix_div.id = 'bpc_nofix';
nofix_div.style = 'margin: 20px; font-size: 20px; font-weight: bold; color: red;';
nofix_div.innerText = msg;
header.before(nofix_div);
}
}
function pageContains(selector, text) {
let elements = document.querySelectorAll(selector);
return Array.prototype.filter.call(elements, function (element) {
return RegExp(text).test(element.textContent);
});
}
function parseHtmlEntities(encodedString) {
let translate_re = /&(nbsp|amp|quot|lt|gt|deg|hellip|laquo|raquo|ldquo|rdquo|lsquo|rsquo|mdash);/g;
let translate = {"nbsp": " ", "amp": "&", "quot": "\"", "lt": "<", "gt": ">", "deg": "°", "hellip": "…",
"laquo": "«", "raquo": "»", "ldquo": "“", "rdquo": "”", "lsquo": "", "rsquo": "", "mdash": "—"};
return encodedString.replace(translate_re, function (match, entity) {
return translate[entity];
}).replace(/&#(\d+);/gi, function (match, numStr) {
let num = parseInt(numStr, 10);
return String.fromCharCode(num);
});
}
function encode_utf8(str) {
return unescape(encodeURIComponent(str));
}
function decode_utf8(str) {
return decodeURIComponent(escape(str));
}
function ampToHtml() {
window.setTimeout(function () {
let canonical = document.querySelector('head > link[rel="canonical"][href]');
if (canonical)
window.location.href = canonical.href;
}, 1000);
}
function refreshCurrentTab() {
window.location.reload(true);
}
})();