//"use strict"; var ext_api = (typeof browser === 'object') ? browser : chrome; var domain; var csDone = false; var ca_torstar_domains = ['niagarafallsreview.ca', 'stcatharinesstandard.ca', 'thepeterboroughexaminer.com', 'therecord.com', 'thespec.com', 'thestar.com', 'wellandtribune.ca']; var de_funke_media_domains = ['abendblatt.de', 'braunschweiger-zeitung.de', 'morgenpost.de', 'nrz.de', 'waz.de', 'wp.de', 'wr.de']; var de_madsack_domains = ['haz.de', 'kn-online.de', 'ln-online.de', 'lvz.de', 'maz-online.de', 'neuepresse.de', 'ostsee-zeitung.de']; var es_grupo_vocento_domains = ['diariosur.es', 'diariovasco.com', 'elcomercio.es', 'elcorreo.com', 'eldiariomontanes.es', 'elnortedecastilla.es', 'hoy.es', 'ideal.es', 'larioja.com', 'laverdad.es', 'lavozdigital.es']; var fr_groupe_ebra_domains = ['bienpublic.com', 'dna.fr', 'estrepublicain.fr', 'lalsace.fr', 'ledauphine.com', 'lejsl.com', 'leprogres.fr', 'republicain-lorrain.fr', 'vosgesmatin.fr']; var fr_groupe_la_depeche_domains = ['centrepresseaveyron.fr', 'ladepeche.fr', 'lindependant.fr', 'midi-olympique.fr', 'midilibre.fr', 'nrpyrenees.fr', 'petitbleu.fr']; // clean local storage of sites (with an exemption for hold-list) var arr_localstorage_hold = ['charliehebdo.fr', 'cmjornal.pt', 'elmundo.es', 'expansion.com', 'kurier.at', 'nknews.org', 'seekingalpha.com', 'sfchronicle.com', 'thehindu.com', 'thetimes.co.uk']; arr_localstorage_hold = arr_localstorage_hold.concat(de_funke_media_domains, es_grupo_vocento_domains); if (!matchDomain(arr_localstorage_hold)){ window.localStorage.clear(); } // listen to responses from background script if (ext_api.runtime && (matchDomain(['belfasttelegraph.co.uk', 'bostonglobe.com', 'independent.ie']) || window.location.hostname.match(/\.(com|net)\.au$/))) { ext_api.runtime.onMessage.addListener(function (message, sender) { // setCookie opt-in if (message.optIn) { let hostname = window.location.hostname; if (hostname.match(/\.(com|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(['belfasttelegraph.co.uk', 'independent.ie'])) { if (!cookieExists('subscriber')) setCookie('subscriber', '{"subscriptionStatus": true}', domain, '/', 14); if (hostname.includes('amp.')) { let subscriber = document.querySelector('section[amp-access="subscriber"]'); if (subscriber) subscriber.removeAttribute('amp-access-hide'); let not_subscriber = document.querySelector('section[amp-access="NOT subscriber"]'); let amp_ads = document.querySelectorAll('amp-ad, amp-embed'); removeDOMElement(not_subscriber, ...amp_ads); } } } } }); // 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'); } let amp_ads = document.querySelectorAll('amp-ad'); removeDOMElement(...amp_ads); } } 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'); } let story_generic_iframe = document.querySelector('.story-generic__iframe'); removeDOMElement(story_generic_iframe); } 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)) { let header_ads = document.querySelector('.header_ads-container'); removeDOMElement(header_ads); if (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 if (window.location.href.includes('?amp')) { //window.setTimeout(function () { let div_hidden = document.querySelector('div[amp-access="subscriber AND status=\'logged-in\'"]'); if (div_hidden) div_hidden.removeAttribute('amp-access-hide'); //}, 500); // Delay (in milliseconds) } let amp_iframes = document.querySelectorAll('amp-iframe'); let elem; for (let amp_iframe of amp_iframes) { elem = document.createElement('a'); elem.innerText = 'Video-link'; elem.setAttribute('href', amp_iframe.getAttribute('src')); elem.setAttribute('target', '_blank'); amp_iframe.parentElement.insertBefore(elem, amp_iframe); removeDOMElement(amp_iframe); } } 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:not([src], [type])'); let json_script; for (let script of scripts) { if (script.innerText.includes('window.PAGE_DATA =')) { json_script = script; break; } } 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('' + 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("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, #cierre_suscripcion'); let amphtml = document.querySelector('link[rel="amphtml"]'); if (content_exclusive_bg && amphtml) { removeDOMElement(content_exclusive_bg); window.location.href = url.replace('.html', '_amp.html'); } 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'); } //lavozdigital.es let paywall = document.querySelector('span[subscriptions-section="content"]'); if (paywall) { paywall.classList.remove('paywall'); paywall.removeAttribute('subscriptions-section'); } } } 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'); removeDOMElement(paywall); if (paywall) window.location.href = url.replace('www.', 'amp.'); } 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'); } window.setTimeout(function () { let amp_img = document.querySelectorAll('amp-img > img'); for (let elem of amp_img) { if (elem.src) elem.src = elem.src.replace('amp.elperiodico.com/clip/', 'estaticos-cdn.elperiodico.com/clip/'); } }, 3000); // Delay (in milliseconds) } } else if (matchDomain('la-croix.com')) { let url = window.location.href; if (!url.includes('la-croix.com/amp/')) { let paywall_host_param = document.querySelector('#paywall-host-param'); removeDOMElement(paywall_host_param); if (paywall_host_param) csDone = true; } else { let paywall_block = document.querySelector('#paywall_block'); let amp_ads = document.querySelectorAll('amp-ad, amp-embed'); removeDOMElement(paywall_block, ...amp_ads); } } else if (matchDomain('lasegunda.com')) { let url = window.location.href; if (url.includes('digital.lasegunda.com/mobile')) { let lessreadmore = document.querySelectorAll('article.lessreadmore'); for (let article of lessreadmore) article.classList.remove('lessreadmore'); let bt_readmore = document.querySelectorAll('div[id*="bt_readmore_"]'); removeDOMElement(...bt_readmore); } } else if (matchDomain("telegraph.co.uk")) { let url = window.location.href; if (new URL(url).pathname.endsWith('/amp/')) { let paywall = document.querySelector('.premium-paywall'); if (paywall) { let truncated_content = document.querySelector('.truncated-content'); removeDOMElement(paywall, truncated_content); let subscr_section = document.querySelector('.notAccessibleForFree'); if (subscr_section) subscr_section.removeAttribute('amp-access-hide'); } } } else if (matchDomain('esprit.presse.fr')) { let paywall = document.querySelector('.panel-popup-paywall'); removeDOMElement(paywall); } else if ((domain = matchDomain(fr_groupe_ebra_domains)) && window.location.href.match(/\/\d{4}\/\d{2}\/\d{2}\//)) { let url = window.location.href; let url_new = url.replace(domain + '/', domain + '/amp/'); if (!url.includes(domain + '/amp/')) { let free = document.querySelector('[class^="paywall"]'); if (!free) { window.setTimeout(function () { window.location.href = url_new; }, 500); // Delay (in milliseconds) } } else { let amp_access_hide = document.querySelector('[amp-access-hide]'); if (amp_access_hide) { let not_access_section = document.querySelector('section[amp-access="NOT access"]'); removeDOMElement(not_access_section); amp_access_hide.removeAttribute('amp-access-hide'); } let amp_ads = document.querySelectorAll('amp-ad'); removeDOMElement(...amp_ads); } } else if (matchDomain(de_funke_media_domains)) { sessionStorage.setItem('deobfuscate', 'true'); } else if (matchDomain('krautreporter.de')) { let paywall = document.querySelector('.article-paywall'); if (paywall) { let paywall_divider = document.querySelector('.js-paywall-divider'); let steady_checkout = document.querySelector('#steady-checkout'); removeDOMElement(paywall, paywall_divider, steady_checkout); let blurred = document.querySelectorAll('.blurred'); for (let elem of blurred) elem.classList.remove('blurred', 'json-ld-paywall-marker', 'hidden@print'); } } else if (matchDomain('nouvelobs.com')) { let paywall = document.querySelector('.paywall'); removeDOMElement(paywall); } else if (matchDomain('freiepresse.de')) { let url = window.location.href; let article_teaser = document.querySelector('div.article-teaser'); if (article_teaser && url.match(/(\-artikel)(\d){6,}/)) { window.setTimeout(function () { window.location.href = url.replace('-artikel', '-amp'); }, 500); // Delay (in milliseconds) } else if (url.match(/(\-amp)(\d){6,}/)) { let amp_ads = document.querySelectorAll('amp-fx-flying-carpet, amp-ad, amp-embed'); let pw_layer = document.querySelector('.pw-layer'); removeDOMElement(...amp_ads, pw_layer); } } else if (matchDomain('seekingalpha.com')) { let url = window.location.href; let locked = document.querySelector('div[data-test-id="post-locked-banner"]'); if (locked && !url.includes('/amp/')) { window.setTimeout(function () { window.location.href = url.replace('seekingalpha.com/', 'seekingalpha.com/amp/'); }, 500); // Delay (in milliseconds) } else if (url.includes('/amp/')) { let div_hidden_all = document.querySelectorAll('[amp-access*="premium_access OR"]'); for (let div_hidden of div_hidden_all) div_hidden.removeAttribute('amp-access-hide'); let paywall = document.querySelector('[class*="paywall-container"]'); if (paywall) paywall.setAttribute('style', 'display:none;'); let adverts = document.querySelectorAll('.ad-wrap'); removeDOMElement(...adverts); } } else if (matchDomain('cicero.de')) { let url = window.location.href; if (!url.includes('?amp')) { let paywall = document.querySelector('.plenigo-paywall'); if (paywall) { removeDOMElement(paywall); let url_amp = url + '?amp'; replaceDomElementExt(url_amp, false, false, '.field-name-field-cc-body'); } } else { let teasered_content = document.querySelector('.teasered-content'); if (teasered_content) teasered_content.classList.remove('teasered-content'); let teasered_content_fader = document.querySelector('.teasered-content-fader'); let btn_read_more = document.querySelector('.btn--read-more'); let amp_ads = document.querySelectorAll('amp-ad'); removeDOMElement(teasered_content_fader, btn_read_more, ...amp_ads); } let urban_ad_sign = document.querySelectorAll('.urban-ad-sign'); removeDOMElement(...urban_ad_sign); } else if (matchDomain('newleftreview.org')) { let url = window.location.href; let paywall = document.querySelector('div.promo-wrapper'); if (paywall) { removeDOMElement(paywall); let url_cache = 'https://webcache.googleusercontent.com/search?q=cache:' + url.split('//')[1]; replaceDomElementExt(url_cache, true, false, 'div.article-page', 'Failed to load from Google webcache: '); } } else if (matchDomain('lavanguardia.com')) { let paywall = document.querySelector('[class*="ev-open-modal-paywall"]'); let infinite_loading = document.querySelector('#infinite-loading'); removeDOMElement(paywall, infinite_loading); } else if (matchDomain('svz.de')) { let paywall = document.querySelector('.paywall'); removeDOMElement(paywall); let url = window.location.href; if (!url.includes('-amp.html')) { if (paywall) window.location.href = url.replace('.html', '-amp.html'); } else { let div_hidden = document.querySelector('div[amp-access="NOT data.reduced"]'); if (div_hidden) div_hidden.removeAttribute('amp-access-hide'); } let amp_ads = document.querySelectorAll('amp-ad, amp-embed, #flying-carpet-wrapper'); removeDOMElement(...amp_ads); } else if (matchDomain('sudouest.fr')) { let url = window.location.href; let paywall = document.querySelector('.article-premium-footer'); if (paywall) { let premium = document.querySelector('meta[name="gsoi:premium-content"]'); if (premium) { if (premium.content) { let url_premium = window.location.origin + premium.content; replaceDomElementExt(url_premium, false, true, 'div.full-content'); } } removeDOMElement(paywall); } } else if (matchDomain('ruhrnachrichten.de')) { let paywall = document.querySelector('.PianoContent'); if (paywall) paywall.classList.remove('PianoContent'); } else if (matchDomain('observador.pt')) { let paywall = document.querySelector('.premium-article'); if (paywall) paywall.classList.remove('premium-article'); } else if (matchDomain('cmjornal.pt')) { let paywall = document.querySelector('.bloqueio_exclusivos'); let amphtml = document.querySelector('link[rel="amphtml"]'); let url = window.location.href; if (!url.includes('/amp/')) { if (paywall && amphtml) { removeDOMElement(paywall); window.location.href = amphtml.href; } } else { let section_hidden = document.querySelectorAll('section[amp-access="subscriber"]'); for (let elem of section_hidden) elem.removeAttribute('amp-access-hide'); let not_subscriber = document.querySelector('section[amp-access="NOT subscriber"]'); removeDOMElement(not_subscriber); let amp_ads = document.querySelectorAll('amp-ad, amp-embed, .detalheAds'); removeDOMElement(...amp_ads); let amp_links = document.querySelectorAll('a[href^="https://www-cmjornal-pt.cdn.ampproject.org/c/s/"]'); for (let amp_link of amp_links) amp_link.href = amp_link.href.replace('www-cmjornal-pt.cdn.ampproject.org/c/s/', ''); } } else if (matchDomain('prospectmagazine.co.uk')) { let url = window.location.href; document.addEventListener('DOMContentLoaded', () => { let paywall = document.querySelector('div.paywall_overlay_blend, div.paywall'); if (paywall) { removeDOMElement(paywall); let url_cache = 'https://webcache.googleusercontent.com/search?q=cache:' + url.split('//')[1]; replaceDomElementExt(url_cache, true, false, 'main', 'Failed to load from Google webcache: '); } }); } else if (matchDomain('thepointmag.com')) { let overlay = document.querySelectorAll('div.overlay, div#tpopup-'); for (let elem of overlay) removeDOMElement(elem); } else if (matchDomain('lne.es')) { let premium = document.querySelector('body.premium'); let url = window.location.href; if (!url.includes('.amp.html')) { if (premium) { window.location.href = url.replace('.html', '.amp.html'); premium.classList.remove('premium'); } } else { let section_hidden = document.querySelectorAll('div[amp-access="access"]'); for (let elem of section_hidden) elem.removeAttribute('amp-access-hide'); let not_subscriber = document.querySelector('div[amp-access="NOT access"]'); removeDOMElement(not_subscriber); } } else if (matchDomain('marketwatch.com')) { let premium = document.querySelector('html.is-paywall'); let url = window.location.href; if (!url.includes('/amp/')) { if (premium) { premium.classList.remove('is-paywall'); window.location.href = url.replace('.marketwatch.com/', '.marketwatch.com/amp/'); } } else { let meter = document.querySelector('div.meter'); let container_sponsored = document.querySelector('div.container--sponsored'); let amp_ads = document.querySelectorAll('.display-ad'); removeDOMElement(meter, container_sponsored, ...amp_ads); } let ads = document.querySelectorAll('div.element--ad, div.j-ad'); removeDOMElement(...ads); } else if (matchDomain('elconfidencial.com')) { let premium = document.querySelector('div.newsType__content--closed'); if (premium) premium.classList.remove('newsType__content--closed'); } else if (matchDomain('jpost.com')) { let premium_banners = document.querySelectorAll('.hide-for-premium, #hiddenPremiumForm, #hiddenLink'); removeDOMElement(...premium_banners); } else if (matchDomain('adweek.com')) { let url = window.location.href; let body_single = document.querySelector('body.single'); let amphtml = document.querySelector('link[rel="amphtml"]'); if (body_single && amphtml) { body_single.classList.remove('single'); window.location.href = amphtml.href; } } else if (!matchDomain(['belfasttelegraph.co.uk', 'independent.ie'])) csDone = true; if (csDone) ext_api.runtime.sendMessage({csDone: true}); // 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 replaceDomElementExt(url, proxy, base64, selector, text_fail = '') { let proxyurl = proxy ? 'https://cors-anywhere.herokuapp.com/' : ''; fetch(proxyurl + url, { headers: {"Content-Type": "text/plain", "X-Requested-With": "XMLHttpRequest" } }) .then(response => { let article = document.querySelector(selector); if (response.ok) { response.text().then(html => { if (base64) { html = atob(html); selector = 'body'; } let parser = new DOMParser(); let doc = parser.parseFromString(html, 'text/html'); let article_new = doc.querySelector(selector); if (article_new) { if (article) article.parentNode.replaceChild(article_new, article); } }); } else if (text_fail) { if (article) { let text_fail_div = document.createElement('div'); text_fail_div.appendChild(document.createTextNode(text_fail)); if (proxy) { let a_link = document.createElement('a'); a_link.innerText = url; a_link.href = url; a_link.target = '_blank'; text_fail_div.appendChild(a_link); } article.insertBefore(text_fail_div, article.firstChild); } } }); } 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); }); }