From 15148e4ea4898b5cda10a8f0bf9b3ae5031d1000 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Sun, 31 May 2020 07:41:22 +0200 Subject: [PATCH] Fix-update Globe and Mail (premium-only) Premium articles have no video and photo gallery. --- background.js | 14 ++++++++------ contentScript.js | 45 +++++++++++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/background.js b/background.js index 1f8a63d..9316672 100644 --- a/background.js +++ b/background.js @@ -13,7 +13,8 @@ const restrictions = { 'elcomercio.pe': /.+\/elcomercio.pe\/.+((\w)+(\-)+){3,}.+/, 'gestion.pe': /.+\/gestion.pe\/.+((\w)+(\-)+){3,}.+/, 'quora.com': /^((?!quora\.com\/search\?q=).)*$/, - 'seekingalpha.com': /.+seekingalpha\.com\/article\/.+/ + 'seekingalpha.com': /.+seekingalpha\.com\/article\/.+/, + 'theglobeandmail.com': /(.+theglobeandmail\.com\/.+\/article-.+|.+theglobeandmail\.com\/pb\/resources\/scripts\/build\/.+\.js)/ } // Don't remove cookies before page load @@ -195,7 +196,7 @@ var blockedRegexes = { 'theadvocate.com.au': /.+cdn-au\.piano\.io\/api\/tinypass.+\.js/, 'thecourier.com.au': /.+cdn-au\.piano\.io\/api\/tinypass.+\.js/, 'thedailybeast.com': /.+\.tinypass\.com\/.+/, -'theglobeandmail.com': /theglobeandmail\.com\/pb\/resources\/scripts\/build\/chunk-bootstraps\/.+\.js/, +'theglobeandmail.com': /theglobeandmail\.com\/pb\/resources\/scripts\/build\/chunk-common-vendor.+\.js/, 'thenation.com': /.+\.tinypass\.com\/.+/, 'valeursactuelles.com': /.+\.poool\.fr\/.+/ }; @@ -401,11 +402,12 @@ ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) { // check for blocked regular expression: domain enabled, match regex, block on an internal or external regex var blockedDomains = Object.keys(blockedRegexes); var domain = matchUrlDomain(blockedDomains, header_referer); + var block_regex = true; if (domain && details.url.match(blockedRegexes[domain]) && isSiteEnabled({url: header_referer})) { - if (domain == 'theglobeandmail.com' && !(header_referer.includes('/article-'))) { - ext_api.webRequest.handlerBehaviorChanged(); - } - return { cancel: true }; + if (domain === 'theglobeandmail.com' && !(header_referer.includes('?ref=premium'))) { + block_regex = false; + } + if (block_regex) return { cancel: true }; } if (!isSiteEnabled(details)) { diff --git a/contentScript.js b/contentScript.js index 56bd3e8..fc45189 100644 --- a/contentScript.js +++ b/contentScript.js @@ -375,24 +375,33 @@ else if (matchDomain("afr.com")) { } else if (matchDomain("theglobeandmail.com")) { + let paywall = document.querySelector('div.c-article-body__teaser-enabled'); + if (paywall) { + window.setTimeout(function () { + if (!window.location.href.includes('?ref=premium')) + window.location.href = window.location.href + '?ref=premium'; + else + window.location.reload(true); + }, 500); + } document.addEventListener('DOMContentLoaded', () => { - const lazy_image = document.querySelectorAll('.js-lazyimage'); - for (let i = 0; i < lazy_image.length; i++) { - lazy_image[i].classList.remove('js-lazyimage'); - } - const hidden_image = document.querySelectorAll('img'); - for (let i = 0; i < hidden_image.length; i++) { - var src = hidden_image[i].src; - if (src.includes("data:image/gif")) { - var data_src = hidden_image[i].getAttribute("data-src"); - if (data_src) - hidden_image[i].setAttribute('src', data_src); - var data_bg = hidden_image[i].getAttribute("data-bg"); - if (data_bg) - hidden_image[i].setAttribute('src', data_bg); - } - } - }); + const lazy_images = document.querySelectorAll('.js-lazyimage'); + for (let lazy_image of lazy_images) { + lazy_image.classList.remove('js-lazyimage'); + } + const hidden_images = document.querySelectorAll('img'); + for (let hidden_image of hidden_images) { + var src = hidden_image.src; + if (src.includes("data:image/gif")) { + var data_src = hidden_image.getAttribute("data-src"); + if (data_src) + hidden_image.setAttribute('src', data_src); + var data_bg = hidden_image.getAttribute("data-bg"); + if (data_bg) + hidden_image.setAttribute('src', data_bg); + } + } + }); } else if (matchDomain("sofrep.com")) { @@ -667,7 +676,7 @@ else if (matchDomain('spectator.co.uk')) { else if (matchDomain('bostonglobe.com')) { if (!document.cookie.split(';').some(function(item) { return item.trim().indexOf('s_fid=') === 0 })) { - let s_fid = genHexString(16) + '-' + genHexString(16); + let s_fid = genHexString(16) + '-' + genHexString(16); document.cookie = "s_fid=" + s_fid + "; domain=bostonglobe.com; path=/; max-age=1209600"; } }