From 574b9db5189a2480bf3c61e42819a734457fb3bb Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Sat, 19 Sep 2020 10:15:24 +0200 Subject: [PATCH] Fix-update Globe and Mail Premium articles have no video and photo gallery --- background.js | 7 ++++++- contentScript.js | 24 +++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/background.js b/background.js index 7780ea3..3f3afc1 100755 --- a/background.js +++ b/background.js @@ -217,6 +217,7 @@ var blockedRegexes = { 'telegraph.co.uk': /.+\.tinypass\.com\/.+/, 'theage.com.au': /cdn\.ampproject\.org\/v\d\/amp-subscriptions-.+\.js/, 'thedailybeast.com': /.+\.tinypass\.com\/.+/, +'theglobeandmail.com': /theglobeandmail\.com\/pb\/resources\/scripts\/build\/chunk-common-vendor.+\.js/, 'thehindu.com': /ajax\.cloudflare\.com\/cdn-cgi\/scripts\/.+\/cloudflare-static\/rocket-loader\.min\.js/, 'thenation.com': /.+\.tinypass\.com\/.+/, 'valeursactuelles.com': /.+\.qiota\.com\/.+/, @@ -517,8 +518,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})) { - return { cancel: true }; + if (domain === 'theglobeandmail.com' && !(header_referer.includes('?ref=premium'))) + block_regex = false; + if (block_regex) + return { cancel: true }; } let inkl_site = (matchUrlDomain('cdn.jsdelivr.net', details.url) && matchUrlDomain('inkl.com', header_referer) && isSiteEnabled({url: header_referer})); diff --git a/contentScript.js b/contentScript.js index d958d9a..69bebed 100755 --- a/contentScript.js +++ b/contentScript.js @@ -430,18 +430,32 @@ else if (matchDomain("afr.com")) { } else if (matchDomain("theglobeandmail.com")) { - document.addEventListener('DOMContentLoaded', () => { let subscribed = document.querySelector('html.story-subscribed'); if (subscribed && !window.location.href.includes('?ref=premium')) { window.setTimeout(function () { window.location.href = new URL(window.location.href).pathname + '?ref=premium'; }, 100); } - }); + let lazy_images = document.querySelectorAll('.js-lazyimage'); + for (let lazy_image of lazy_images) { + lazy_image.classList.remove('js-lazyimage'); + } + let 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); + } + } let c_cards = document.querySelectorAll('div.c-card'); - for (c_card of c_cards) { + for (let c_card of c_cards) { var a_link = c_card.querySelector('a'); - var subscr_key = c_card.querySelector('span.c-indicator-icon--key'); + var subscr_key = c_card.querySelector('span.c-indicator-icon--key'); if (subscr_key && a_link && !a_link.href.includes('?ref=premium')) { a_link.href = a_link.href + '?ref=premium'; } @@ -827,7 +841,7 @@ else if (matchDomain('ilfattoquotidiano.it')) { else if (matchDomain('qz.com')) { window.setTimeout(function () { if (pageContains('._33dc2 h2', 'Become a member, and we promise').length) - document.location.reload(true); + window.location.reload(true); }, 500); // Delay (in milliseconds) }