Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes bug #46 #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 44 additions & 53 deletions src/burlesco.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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',
Expand All @@ -228,15 +218,25 @@ 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);
document.close();
}
}
});

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)) {
Expand Down Expand Up @@ -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)
`;

Expand Down Expand Up @@ -458,48 +459,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" */