From a95e0bef501d74b359cefb700d28453469836a59 Mon Sep 17 00:00:00 2001 From: Augusto Resende Date: Tue, 7 Nov 2017 10:45:39 -0300 Subject: [PATCH] Atualiza GauchaZH --- src/background.js | 16 ++++++--------- src/content-start.js | 37 ++++++++++++++++++++++++++++++++++ src/content.js | 47 -------------------------------------------- src/manifest.json | 9 ++++++--- 4 files changed, 49 insertions(+), 60 deletions(-) create mode 100644 src/content-start.js diff --git a/src/background.js b/src/background.js index 1a06307..96b9445 100644 --- a/src/background.js +++ b/src/background.js @@ -43,7 +43,10 @@ chrome.webRequest.onBeforeRequest.addListener( "*://cdn.tinypass.com/api/tinypass.min.js", // UOL - "*://tm.jsuol.com.br/modules/content-gate.js" + "*://tm.jsuol.com.br/modules/content-gate.js", + + // GauchaZH + "*://gauchazh.clicrbs.com.br/static/main*" ], types: ["script"] }, @@ -101,16 +104,12 @@ chrome.webRequest.onBeforeRequest.addListener( chrome.webRequest.onBeforeRequest.addListener( function(details) { console.log(details); - removeCookies('https://gauchazh.clicrbs.com.br'); removeCookies('https://www.ft.com'); }, { urls: [ // Financial Times - "*://*.ft.com/*", - - // Zero Hora - "*://*.clicrbs.com.br/*" + "*://*.ft.com/*" ] } ); @@ -141,10 +140,7 @@ chrome.webRequest.onHeadersReceived.addListener( { urls: [ // Financial Times - "*://*.ft.com/*", - - // Zero Hora - "*://*.clicrbs.com.br/*" + "*://*.ft.com/*" ] }, ['blocking', 'responseHeaders'] diff --git a/src/content-start.js b/src/content-start.js new file mode 100644 index 0000000..41a997c --- /dev/null +++ b/src/content-start.js @@ -0,0 +1,37 @@ +// run_at: document_start +var code = null; + +if (/gauchazh.clicrbs.com.br/.test(document.location.host)) { + code = ` + function patchJs(jsurl) { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + var injectme = this.responseText; + injectme = injectme.replace('showSignwall:e.showLoginPaywall','showSignwall:false'); + injectme = injectme.replace('showPaywall:e.showPaywall','showPaywall:false'); + injectme = injectme.replace('requestCPF:e.requestCPF || !1','requestCPF:false'); + injectme = injectme.replace('!e.showLoginPaywall&&!e.showPaywall||!1','true'); + var script = document.createElement("script"); + script.type = "text/javascript"; + var textNode = document.createTextNode(injectme); + script.appendChild(textNode); + document.head.appendChild(script); + } + }; + xhttp.open("GET", jsurl, true); + xhttp.send(); + } + + document.addEventListener("DOMContentLoaded", function(event) { + patchJs(document.getElementsByTagName('script')[1].src); + }); + `; +} + +if (code !== null) { + var script = document.createElement('script'); + script.textContent = code; + (document.head||document.documentElement).appendChild(script); + script.parentNode.removeChild(script); +} diff --git a/src/content.js b/src/content.js index 1f838bf..2357a99 100644 --- a/src/content.js +++ b/src/content.js @@ -31,53 +31,6 @@ else if (/ft.com/.test(document.location.host)) { indexedDB.deleteDatabase("next:ads");'; } -else if (/gauchazh.clicrbs.com.br/.test(document.location.host)) { - code = ` - function loadArticle() { - var xhttp = new XMLHttpRequest(); - xhttp.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - var parser = new DOMParser(); - var htmlDoc = parser.parseFromString(this.responseText,'text/html'); - var injectme = htmlDoc.getElementsByClassName('paid-content-apply')[0].innerHTML; - document.getElementsByClassName('paid-content-apply')[0].innerHTML = injectme; - } - }; - xhttp.open('GET', window.location.href, true); - xhttp.send(); - } - - function checkPaywall() { - setInterval(function() { - var paywall = document.getElementsByClassName('wrapper-paid-content')[0]; - if (paywall) { - localStorage.clear(); - loadArticle(); - } - }, 1000); - } - - function deleteAllCookies() { - var cookies = document.cookie.split(";"); - for (var i = 0; i < cookies.length; i++) { - var cookie = cookies[i]; - var eqPos = cookie.indexOf("="); - var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie; - document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT"; - } - } - - function clearPersistentData() { - localStorage.clear(); - sessionStorage.clear(); - deleteAllCookies(); - } - - checkPaywall(); - document.getElementsByTagName('html')[0].onclick = clearPersistentData(); - `; -} - if (code !== null) { var script = document.createElement('script'); script.textContent = code; diff --git a/src/manifest.json b/src/manifest.json index d4d0992..8435e7d 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "burlesco", - "version": "5.3", + "version": "5.4", "description": "Leia notícias sem ser assinante, burle o paywall", "homepage_url": "http://burles.co", "author": "rodorgas", @@ -23,9 +23,12 @@ "*://foreignpolicy.com/*", "*://*.folha.uol.com.br/*", "*://*.folha.com.br/*", - "*://*.ft.com/*", - "*://gauchazh.clicrbs.com.br/*" + "*://*.ft.com/*" ] + },{ + "js": ["content-start.js"], + "run_at": "document_start", + "matches": ["*://gauchazh.clicrbs.com.br/*"] }], "permissions": [