From 420411bf761e4e3a8c64d5dc23d24b86ec3835b6 Mon Sep 17 00:00:00 2001 From: Kemel Zaidan Date: Sat, 21 Oct 2023 16:19:07 -0300 Subject: [PATCH 1/2] fixes ft.com --- src/burlesco.user.js | 94 ++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 52 deletions(-) diff --git a/src/burlesco.user.js b/src/burlesco.user.js index c438a48..2566cdb 100644 --- a/src/burlesco.user.js +++ b/src/burlesco.user.js @@ -208,17 +208,7 @@ document.addEventListener('DOMContentLoaded', function() { } else if (/ft\.com/.test(document.location.host) - && document.querySelector('.barrier-banner')) { - - eraseAllCookies(); - - document.cookie = ''; - localStorage.clear(); - sessionStorage.clear(); - indexedDB.deleteDatabase('next-flags'); - indexedDB.deleteDatabase('next:ads'); - - document.querySelector('.o-cookie-message').remove(); + && document.querySelector('.barrier-banner')) { GM_xmlhttpRequest({ method: 'GET', @@ -228,8 +218,8 @@ document.addEventListener('DOMContentLoaded', function() { }, anonymous: true, onload: function(response) { - var parser = new DOMParser(); - var newDocument = parser.parseFromString(response.responseText,'text/html'); + let parser = new DOMParser(); + let newDocument = parser.parseFromString(response.responseText,'text/html'); if (newDocument.getElementsByClassName('article__content')[0]) { document.open(); document.write(newDocument.getElementsByTagName('html')[0].innerHTML); @@ -237,6 +227,16 @@ document.addEventListener('DOMContentLoaded', function() { } } }); + + const cookies = ['FTConsent=false', 'FTCookieConsentGDPR=true']; + document.cookie = cookies[0]; + document.cookie = cookies[1]; + localStorage.clear(); + sessionStorage.clear(); + indexedDB.deleteDatabase('next-flags'); + indexedDB.deleteDatabase('next:ads'); + eraseAllCookiesExcept(cookies); + document.querySelector('.o-banner').remove(); } else if (/foreignpolicy\.com/.test(document.location.host)) { @@ -458,48 +458,38 @@ document.addEventListener('DOMContentLoaded', function() { } }); +// Helper functions +function eraseCookie (cookieName) { + try { + document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:00 UTC'; + } catch (error) { + console.error(`Could not erase cookie ${cookieName}. Error:` + error.message); + } +} + function eraseAllCookies() { - var cookieList = document.cookie.split (/;\s*/); - for (var J = cookieList.length - 1; J >= 0; --J) { - var cookieName = cookieList[J].replace (/\s*(\w+)=.+$/, '$1'); - eraseCookie (cookieName); + let cookies = document.cookie.split(';'); + + for (let i = 0; i < cookies.length; i++) { + let cookie = cookies[i]; + let eqPos = cookie.indexOf('='); + let cookieName = eqPos > -1 ? cookie.substring(0, eqPos) : cookie; + eraseCookie(cookieName); } } -function eraseCookie (cookieName) { - // https://stackoverflow.com/a/28081337/1840019 - //--- ONE-TIME INITS: - //--- Set possible domains. Omits some rare edge cases.?. - var domain = document.domain; - var domain2 = document.domain.replace (/^www\./, ''); - var domain3 = document.domain.replace (/^(\w+\.)+?(\w+\.\w+)$/, '$2'); - - //--- Get possible paths for the current page: - var pathNodes = location.pathname.split ('/').map ( function (pathWord) { - return '/' + pathWord; - } ); - var cookPaths = [''].concat (pathNodes.map ( function (pathNode) { - if (this.pathStr) { - this.pathStr += pathNode; +// receives an array of cookies names as argument +function eraseAllCookiesExcept(cookieArray) { + let cookies = document.cookie.split(';'); + + for (let i = 0; i < cookies.length; i++) { + let cookie = cookies[i]; + let eqPos = cookie.indexOf('='); + let cookieName = eqPos > -1 ? cookie.substring(0, eqPos) : cookie; + + if (!cookieArray.includes(cookieName)) { + eraseCookie(cookieName); } - else { - this.pathStr = '; path='; - return (this.pathStr + pathNode); - } - return (this.pathStr); - } ) ); - - // eslint-disable-next-line no-func-assign - ( eraseCookie = function (cookieName) { - //--- For each path, attempt to delete the cookie. - cookPaths.forEach ( function (pathStr) { - //--- To delete a cookie, set its expiration date to a past value. - var diagStr = cookieName + '=' + pathStr + '; expires=Thu, 01-Jan-1970 00:00:01 GMT;'; - document.cookie = diagStr; - - document.cookie = cookieName + '=' + pathStr + '; domain=' + domain + '; expires=Thu, 01-Jan-1970 00:00:01 GMT;'; - document.cookie = cookieName + '=' + pathStr + '; domain=' + domain2 + '; expires=Thu, 01-Jan-1970 00:00:01 GMT;'; - document.cookie = cookieName + '=' + pathStr + '; domain=' + domain3 + '; expires=Thu, 01-Jan-1970 00:00:01 GMT;'; - } ); - } ) (cookieName); + } } +/* eslint max-len: "off" */ \ No newline at end of file From 20d1057814abf74b16d4b38e6ed357767c783b31 Mon Sep 17 00:00:00 2001 From: Kemel Zaidan Date: Wed, 5 Jun 2024 15:41:29 -0300 Subject: [PATCH 2/2] fixes paywall for Super Interessante and Abril --- src/burlesco.user.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/burlesco.user.js b/src/burlesco.user.js index 2566cdb..c088a47 100644 --- a/src/burlesco.user.js +++ b/src/burlesco.user.js @@ -94,7 +94,7 @@ // @webRequestItem {"selector":"*://*.diarinho.com.br/wp-admin/admin-ajax.php","action":"cancel"} // @webRequestItem {"selector":"*://diarinho.com.br/wp-admin/admin-ajax.php","action":"cancel"} // @webRequestItem {"selector":"*://static.infoglobo.com.br/paywall/js/tiny.js","action":"cancel"} -// @webRequestItem {"selector":"*://*.abril.com.br/wp-content/plugins/abril-plugins/abril-paywall/js/paywall.js*","action":"cancel"} +// @webRequestItem {"selector":"*://*.abril.com.br/wp-content/plugins/abril-plugins/abril-paywall/js/abril-firebase-auth/paywall.js*","action":"cancel"} // @webRequestItem {"selector":"*://exame.com/wp-content/themes/exame-new/js/pywll.js","action":"cancel"} // @webRequestItem {"selector":"*://prisa-el-pais-brasil-prod.cdn.arcpublishing.com/arc/subs/p.js","action":"cancel"} // @webRequestItem {"selector":"*://prisa-el-pais-prod.cdn.arcpublishing.com/arc/subs/p.js","action":"cancel"} @@ -264,6 +264,7 @@ document.addEventListener('DOMContentLoaded', function() { document.querySelector('body').classList.remove('disabledByPaywall') document.querySelector('.piano-offer-overlay').remove() document.querySelector('#piano_offer').remove() + document.querySelector('.ads-footer').remove() }, 10000) `; @@ -492,4 +493,4 @@ function eraseAllCookiesExcept(cookieArray) { } } } -/* eslint max-len: "off" */ \ No newline at end of file +/* eslint max-len: "off" */