//"use strict"; var ext_api = (typeof browser === 'object') ? browser : chrome; var domain; // clean local storage of sites (with an exemption for hold-list) var arr_localstorage_hold = ['elmundo.es', 'kurier.at', 'nknews.org', 'nrz.de', 'seekingalpha.com', 'sfchronicle.com', 'thehindu.com', 'thetimes.co.uk', 'waz.de', 'wp.de', 'wr.de']; var es_grupo_vocento_domains = ['diariosur.es', 'diariovasco.com', 'elcorreo.com', 'eldiariomontanes.es', 'elnortedecastilla.es', 'hoy.es', 'larioja.com', 'laverdad.es']; arr_localstorage_hold = arr_localstorage_hold.concat(es_grupo_vocento_domains); if (!matchDomain(arr_localstorage_hold)){ window.localStorage.clear(); } // listen to responses from background script ext_api.runtime.onMessage.addListener(function (message, sender) { // setCookie opt-in if (message.optIn) { let hostname = window.location.hostname; if (hostname.endsWith(".com.au") || hostname.endsWith(".net.au")) { // Australian Provincial Newspapers domain = window.location.hostname.replace('www.', ''); let au_apn_script = document.querySelector('script[src^="https://media.apnarm.net.au/"]'); if (au_apn_script || (domain = matchDomain(['news-mail.com.au', 'frasercoastchronicle.com.au', 'gladstoneobserver.com.au', 'dailyexaminer.com.au', 'dailymercury.com.au', 'themorningbulletin.com.au', 'sunshinecoastdaily.com.au', 'gympietimes.com.au', 'northernstar.com.au', 'qt.com.au', 'thechronicle.com.au', 'warwickdailynews.com.au']))) if (!cookieExists('subscribed')) setCookie('subscribed', 'true', domain, '/', 14); } else { if (matchDomain('bostonglobe.com')) { if (!cookieExists('s_fid')) { let s_fid = genHexString(16) + '-' + genHexString(16); setCookie('s_fid', s_fid, 'bostonglobe.com', '/', 14); } } else if (domain = matchDomain(['independent.ie', 'belfasttelegraph.co.uk'])) { if (!cookieExists('subscriber')) setCookie('subscriber', '{"subscriptionStatus": true}', domain, '/', 14); } } } }); // ask for opt-in confirmation ext_api.runtime.sendMessage({request: 'optin'}); // Content workarounds/domain if (matchDomain("thesaturdaypaper.com.au")) { let paywall = document.querySelector('div.paywall-hard-always-show'); removeDOMElement(paywall); } else if (domain = matchDomain(["brisbanetimes.com.au", "smh.com.au", "theage.com.au", "watoday.com.au"])) { let url = window.location.href; let for_subscribers = document.querySelector('meta[content^="FOR SUBSCRIBERS"]'); if (for_subscribers) { window.setTimeout(function () { window.location.href = url.replace('www.', 'amp.'); }, 500); // Delay (in milliseconds) } else if (url.includes('amp.' + domain)) { let subscr_sections = document.querySelectorAll('div[subscriptions-section="content"]'); for (let subscr_section of subscr_sections) { subscr_section.removeAttribute('subscriptions-section'); } } } else if (window.location.hostname.endsWith(".com.au") || window.location.hostname.endsWith(".net.au")) { // Australian Community Media newspapers let au_cm_sites = ['bendigoadvertiser.com.au', 'bordermail.com.au', 'canberratimes.com.au', 'centralwesterndaily.com.au', 'dailyadvertiser.com.au', 'dailyliberal.com.au', 'examiner.com.au', 'illawarramercury.com.au', 'newcastleherald.com.au', 'northerndailyleader.com.au', 'portnews.com.au', 'standard.net.au', 'theadvocate.com.au', 'thecourier.com.au', 'westernadvocate.com.au']; let au_piano_script = document.querySelector('script[src="https://cdn-au.piano.io/api/tinypass.min.js"]'); if (matchDomain(au_cm_sites) || au_piano_script) { const subscribe_truncate = document.querySelector('.subscribe-truncate'); if (subscribe_truncate) subscribe_truncate.classList.remove('subscribe-truncate'); const subscriber_hiders = document.querySelectorAll('.subscriber-hider'); for (let subscriber_hider of subscriber_hiders) { subscriber_hider.classList.remove('subscriber-hider'); } } else if (window.location.hostname.endsWith(".com.au")) { // Australia News Corp let au_nc_sites = ['adelaidenow.com.au', 'cairnspost.com.au', 'couriermail.com.au', 'dailytelegraph.com.au', 'geelongadvertiser.com.au', 'goldcoastbulletin.com.au', 'heraldsun.com.au', 'ntnews.com.au', 'theaustralian.com.au', 'themercury.com.au', 'townsvillebulletin.com.au', 'weeklytimesnow.com.au']; if (matchDomain(au_nc_sites) && window.location.hostname.startsWith('amp.')) { let div_hidden_all = document.querySelectorAll('div[amp-access="access AND subscriber"]'); for (let div_hidden of div_hidden_all) div_hidden.removeAttribute('amp-access-hide'); } else { // Australian Seven West Media let swm_script = document.querySelector('script[src^="https://s.thewest.com.au"]'); if (matchDomain("thewest.com.au") || swm_script) { window.setTimeout(function () { let breach_screen = document.querySelector('div[data-testid*="BreachScreen"]'); if (breach_screen) { let scripts = document.querySelectorAll('script'); let json_script; for (let script of scripts) { if (script.innerText.includes('window.PAGE_DATA =')) json_script = script; continue; } if (json_script) { let json_text = json_script.innerHTML.split('window.PAGE_DATA =')[1].split('' + par.text + '
'; } else if (par.kind === 'subhead') { article = article + '' + par.text + '
'; console.log(par.kind); } } let content = document.querySelector('div[class*="StyledArticleContent"]'); let parser = new DOMParser(); let par_html = parser.parseFromString('' + elem.text + '
' + par.content + '
' + par_key + '
', 'text/html'); par_elem = par_html.querySelector('p'); } else par_elem.innerText = par_key; if (key === 'subhead') par_elem.setAttribute('style', 'font-weight: bold;'); } else if (key === 'image') { par_elem = document.createElement("img"); par_elem.src = par_key.url; } else if (key === 'bullet_list') { par_elem = document.createElement('ul'); for (let bullet of par_key) { par_html = parser.parseFromString('' + par_key + '
', 'text/html'); par_elem = par_html.querySelector('p'); } if (!['streamone', 'legacy-ml'].includes(key)) par_elem.setAttribute('class', 'gva-3ee037ad_root gva-3ee037ad_paragraph gva-68d24f7d_none gva-ef7ba41a_system gva-6c6ea21_marginbottom5 gva-6c6ea21_margintop0 gva-21a3e72f_inherit'); div_content.appendChild(par_elem); } } } } }); window.setTimeout(function () { let overlay = document.querySelector('div.cj-root'); removeDOMElement(overlay); let noscroll = document.querySelector('html.is-dialog-active'); if (noscroll) noscroll.classList.remove('is-dialog-active'); }, 500); // Delay (in milliseconds) } else if (matchDomain('deutsche-wirtschafts-nachrichten.de')) { window.setTimeout(function () { let hardpay = document.querySelector('.hardpay'); if (hardpay) { window.location.reload(true); } }, 500); // Delay (in milliseconds) } else if (matchDomain("alternatives-economiques.fr")) { window.setTimeout(function () { let paywall = document.querySelector('#temp-paywall'); removeDOMElement(paywall); let data_ae_poool = document.querySelector('div[data-ae-poool]'); if (data_ae_poool) data_ae_poool.removeAttribute('style'); }, 500); // Delay (in milliseconds) } else if (matchDomain("hs.fi")) { let url = window.location.href; if (!url.includes('https://dynamic.hs.fi')) { let iframe = document.querySelector('iframe[src^="https://dynamic.hs.fi/a/"]'); if (iframe && url.includes('.html')) { window.setTimeout(function () { window.location.href = iframe.src; }, 500); // Delay (in milliseconds) } } else { let paywall = document.querySelector('.paywall-container'); if (paywall) { let scripts = document.querySelectorAll('script'); let json_script; for (let script of scripts) { if (script.innerText.includes('window.__NUXT__=')) json_script = script; continue; } let json_text = json_script.innerHTML.replace(/\r\n/g, '').split('amlData:[')[1].split('metaData')[0].split('paywallComponents:[')[1].slice(0, -4); let main = document.querySelector('main'); if (main) { let pars = json_text.split('{type:'); let type, value, slides, src, elem, img, caption, caption_text, par_html, par_text; let parser = new DOMParser(); for (let par of pars) { type = par.split(',')[0]; if (type === 'i') { // text value = par.split('value:')[1].split('}')[0]; par_html = parser.parseFromString('' + value + '
', 'text/html'); elem = par_html.querySelector('p'); elem.setAttribute('class', 'article-body px-16 mb-24'); main.appendChild(elem); } else if (type === 'j') { // quote value = par.split('text:')[1].split(',position:')[0]; par_html = parser.parseFromString('' + value + '
', 'text/html'); elem = par_html.querySelector('p'); elem.setAttribute('class', 'article-body px-16 mb-24'); elem.setAttribute('style', 'font-style: italic;'); main.appendChild(elem); } else if (type === 'h') { // image src = par.split('src:"')[1].split('",')[0]; elem = document.createElement('p'); elem.setAttribute('class', 'article-body px-16 mb-24'); img = document.createElement('img'); img.setAttribute('src', 'https://arkku.mediadelivery.fi/img/468/' + src); img.setAttribute('style', 'width:468px !important'); elem.appendChild(img); caption = document.createElement('figcaption'); caption_text = par.split('caption:')[1].split(',credits:')[0]; if (caption_text.length) caption_text = caption_text.slice(1, caption_text.length - 1); caption.innerText = caption_text; elem.appendChild(caption); main.appendChild(elem); } else if (type === 'r') { // slides slides = par.split('src:'); for (let slide of slides) { if (slide.includes('.jpg')) { src = slide.split(',')[0].replace(/"/g, ''); elem = document.createElement('p'); elem.setAttribute('class', 'article-body px-16 mb-24'); img = document.createElement('img'); img.setAttribute('src', 'https://arkku.mediadelivery.fi/img/468/' + src); img.setAttribute('style', 'width:468px !important'); elem.appendChild(img); caption = document.createElement('figcaption'); caption_text = slide.split('text:')[1].split(',"text-style"')[0]; if (caption_text.length) caption_text = caption_text.slice(1, caption_text.length - 1); caption.innerText = caption_text; elem.appendChild(caption); main.appendChild(elem); } } } else false; //console.log('type: ' + type + ' par: ' + par); } main.appendChild(document.createElement('br')); } removeDOMElement(paywall); } } } else if (matchDomain("latercera.com")) { let subscr_banner = document.querySelector('.empty'); removeDOMElement(subscr_banner); } else if (matchDomain(es_grupo_vocento_domains)) { let url = window.location.href; let content_exclusive_bg = document.querySelector('.content-exclusive-bg '); let amphtml = document.querySelector('link[rel="amphtml"]'); if (content_exclusive_bg && amphtml) { window.setTimeout(function () { window.location.href = url.replace('.html', '_amp.html'); }, 500); // Delay (in milliseconds) } else if (url.includes('_amp.html')) { let voc_advers = document.querySelectorAll('.voc-adver, amp-embed'); removeDOMElement(...voc_advers); let container_wall_exclusive = document.querySelector('.container-wall-exclusive'); if (container_wall_exclusive) { let non_subscr_section = document.querySelector('[amp-access="result!=\'ALLOW_ACCESS\'"]'); removeDOMElement(container_wall_exclusive, non_subscr_section); let subscr_section = document.querySelector('[amp-access="result=\'ALLOW_ACCESS\'"]'); if (subscr_section) subscr_section.removeAttribute('amp-access-hide'); } } } else if (matchDomain("corriere.it")) { let url = window.location.href; if (url.includes('_preview.shtml')) { window.setTimeout(function () { window.location.href = url.replace('_preview.shtml', '.shtml').split('?')[0]; }, 500); // Delay (in milliseconds) } } else if (matchDomain("elperiodico.com")) { let url = window.location.href; if (!url.includes('amp.elperiodico.com')) { let paywall = document.querySelector('.ep-masPeriodico-info-login'); if (paywall) { window.setTimeout(function () { window.location.href = url.replace('www.', 'amp.'); }, 500); // Delay (in milliseconds) } } else { let not_logged = document.querySelector('.ep-masPeriodico-info-login'); if (not_logged) { let non_subscr_section = document.querySelector('div[amp-access="NOT logged"]'); removeDOMElement(not_logged, non_subscr_section); let subscr_section = document.querySelector('div[amp-access="logged"]'); if (subscr_section) subscr_section.removeAttribute('amp-access-hide'); } } } // General Functions function removeDOMElement(...elements) { for (let element of elements) { if (element) element.remove(); } } 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 removeClassesByPrefix(el, prefix) { let el_classes = el.classList; for (let el_class of el_classes) { if (el_class.startsWith(prefix)) { el_classes.remove(el_class); } } } function cookieExists(name) { return document.cookie.split(';').some(function(item) { return item.trim().indexOf(name + '=') === 0 }) } function setCookie(name, value, domain, path, days) { var max_age = days * 24 * 60 * 60; document.cookie = name + "=" + (value || "") + "; domain=" + domain + "; path=" + path + "; max-age=" + max_age; } function insert_script(func, insertAfterDom) { let bpc_script = document.querySelector('script#bpc_script'); if (!bpc_script) { let script = document.createElement('script'); script.setAttribute('id', 'bpc_script'); script.appendChild(document.createTextNode('(' + func + ')();')); let insertAfter = insertAfterDom ? insertAfterDom : (document.body || document.head || document.documentElement); insertAfter.appendChild(script); } } function genHexString(len) { let output = ''; for (let i = 0; i < len; i++) { output += (Math.floor(Math.random() * 16)).toString(16); } return output; } function makeRandomNumber(len) { let result = ''; var characters = '123456789'; var charactersLength = characters.length; for (var i = 0; i < len; i++) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } 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) { var translate_re = /&(nbsp|amp|quot|lt|gt|deg|hellip|laquo|raquo|ldquo|rdquo|lsquo|rsquo|mdash);/g; var 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) { var num = parseInt(numStr, 10); return String.fromCharCode(num); }); }