From eed42e016c4c137743c7f6305e23167d4aa14f08 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Mon, 25 Oct 2021 19:05:39 +0200 Subject: [PATCH] Fix Stratfor (forecasts) --- background.js | 6 ++++-- changelog.txt | 1 + contentScript.js | 35 +++++++++++++++++++++++++++++++++++ custom/manifest.json | 2 +- manifest.json | 2 +- 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/background.js b/background.js index d70cd62..8b86c2a 100755 --- a/background.js +++ b/background.js @@ -1300,6 +1300,8 @@ ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) { !(matchUrlDomain('barrons.com', details.url) && enabledSites.includes('#options_disable_gb_barrons')) && !(matchUrlDomain('theaustralian.com.au', details.url) && enabledSites.includes('#options_disable_gb_theaustralian')) && !(matchUrlDomain('wsj.com', details.url) && enabledSites.includes('#options_disable_gb_wsj')); + var bingbotEnabled = matchUrlDomain(use_bing_bot, details.url) && + !(matchUrlDomain('stratfor.com', details.url) && details.url.match(/(\/(\d){4}-([a-z]||-)+-forecast(-([a-z]|-)+)?|-forecast-(\d){4}-([a-z]|[0-9]||-)+)$/)); if (matchUrlDomain(change_headers, details.url) && (!['font', 'image', 'stylesheet'].includes(details.type) || matchUrlDomain(['thetimes.co.uk'], details.url))) { // if referer exists, set it @@ -1353,7 +1355,7 @@ if (matchUrlDomain(change_headers, details.url) && (!['font', 'image', 'styleshe } // override User-Agent to use Bingbot - if (matchUrlDomain(use_bing_bot, details.url)) { + if (bingbotEnabled) { requestHeaders.push({ "name": "User-Agent", "value": useUserAgentMobile ? userAgentMobileB : userAgentDesktopB @@ -1388,7 +1390,7 @@ if (matchUrlDomain(change_headers, details.url) && (!['font', 'image', 'styleshe } if ((!['font', 'stylesheet'].includes(details.type) || matchUrlDomain(cs_limit_except, currentTabUrl)) && !csDone) { let lib_file = 'lib/empty.js'; - if (matchUrlDomain(['bloomberg.com', 'cicero.de', 'economictimes.com', 'lesechos.fr', 'marianne.net', 'newleftreview.org', 'newyorker.com', 'nzherald.co.nz', 'prospectmagazine.co.uk', 'sudouest.fr', 'techinasia.com', 'valor.globo.com', 'washingtonpost.com'].concat(nl_mediahuis_region_domains, no_nhst_media_domains, usa_theathletic_domains), currentTabUrl)) + if (matchUrlDomain(['bloomberg.com', 'cicero.de', 'economictimes.com', 'lesechos.fr', 'marianne.net', 'newleftreview.org', 'newyorker.com', 'nzherald.co.nz', 'prospectmagazine.co.uk', 'stratfor.com', 'sudouest.fr', 'techinasia.com', 'valor.globo.com', 'washingtonpost.com'].concat(nl_mediahuis_region_domains, no_nhst_media_domains, usa_theathletic_domains), currentTabUrl)) lib_file = 'lib/purify.min.js'; var bg2csData = { optin_setcookie: optin_setcookie, diff --git a/changelog.txt b/changelog.txt index 4edd812..f24ec27 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ Changelog Bypass Paywalls Clean - Chrome Post-release +Fix Stratfor (forecasts) * v2.4.1.0 (2021-10-24) Add Elle.fr diff --git a/contentScript.js b/contentScript.js index e12c06b..c649434 100755 --- a/contentScript.js +++ b/contentScript.js @@ -2436,6 +2436,41 @@ else if (matchDomain('stratfor.com')) { let hidden_images = document.querySelectorAll('img[src^="data:image/gif"][data-src]'); for (let hidden_image of hidden_images) hidden_image.setAttribute('src', hidden_image.getAttribute('data-src')); + let url = window.location.href.split('?')[0]; + if (url.match(/(\/(\d){4}-([a-z]|-)+-forecast(-([a-z]|-)+)?|-forecast-(\d){4}-([a-z]|[0-9]|-)+)$/)) { + json_script = document.querySelector('script#__NEXT_DATA__'); + if (json_script && dompurify_loaded) { + let json = JSON.parse(json_script.innerText); + if (json && json.props.pageProps.data) { + let overview_div = document.querySelector('div[class^="overview_overview__"] > div'); + if (overview_div) { + let data = json.props.pageProps.data; + let parser = new DOMParser(); + let doc = parser.parseFromString('
' + DOMPurify.sanitize('

' + data.teaser_body + '

' + data.overview + '

Sections

' ) + '
', 'text/html'); + let content_new = doc.querySelector('div'); + let sections = data.section; + for (let section of sections) { + let section_link = document.createElement('a'); + section_link.innerText = section.title; + section_link.href = 'https://' + window.location.hostname + '/' + section.path_alias; + content_new.appendChild(section_link); + content_new.appendChild(document.createElement('br')); + } + overview_div.parentNode.replaceChild(content_new, overview_div); + csDoneOnce = true; + } + } + } + waitDOMElement('div.paywall-banner', 'DIV', removeDOMElement, false); + } else if (url.match(/\/article\/.+-forecast(-.+)?\//)) { + let next_section_buttons = document.querySelectorAll('div[class^="nextSection_nextSection__"] > button'); + for (let elem of next_section_buttons) { + let section_link = document.createElement('a'); + section_link.innerText = elem.innerText; + section_link.href = url.replace(/[^\/]+$/, '') + elem.innerText.split(': ')[1].toLowerCase().split(' ').filter(x => !['a', 'an', 'of', 'the'].includes(x)).join('-'); + elem.parentNode.replaceChild(section_link, elem); + } + } } else if (matchDomain('study.com')) { diff --git a/custom/manifest.json b/custom/manifest.json index d54ee2f..3b6a7d7 100644 --- a/custom/manifest.json +++ b/custom/manifest.json @@ -39,5 +39,5 @@ "webRequestBlocking", "" ], - "version": "2.4.1.0" + "version": "2.4.1.1" } \ No newline at end of file diff --git a/manifest.json b/manifest.json index 6049762..34d2c32 100755 --- a/manifest.json +++ b/manifest.json @@ -544,5 +544,5 @@ "*://*.wallkit.net/*", "*://*.wsj.net/*" ], - "version": "2.4.1.0" + "version": "2.4.1.1" } \ No newline at end of file