Skip to content

Instantly share code, notes, and snippets.

@canesin
Forked from thoroc/README.md
Created December 16, 2016 17:42
Show Gist options
  • Save canesin/d43aaec97b36a9983b1eed081ad46fc4 to your computer and use it in GitHub Desktop.
Save canesin/d43aaec97b36a9983b1eed081ad46fc4 to your computer and use it in GitHub Desktop.
Paywall Bitch

Yeah Bitch!

Original Source

This extension modifies the referrer and blocks tracking cookies for any site listed in the manifest.

Changes

  • README
  • SeattleTimes
  • Name
/*
Thank You Isoroku Yamamoto
http://elaineou.com/2016/02/19/how-to-use-chrome-extensions-to-bypass-paywalls/
Try to block all cookies if possible.
Might need to put forbes back into allowed cookies depending on adblocker settings
*/
var ALLOW_COOKIES = ["nytimes", "ft.com"]
function changeRefer(details) {
console.log(details);
foundReferer = false;
foundUA = false
var reqHeaders = details.requestHeaders.filter(function(header) {
// block cookies by default
if (header.name !== "Cookie") {
return header;
}
allowHeader = ALLOW_COOKIES.map(function(url) {
if (details.url.includes(url)) {
return true;
}
return false;
});
if (allowHeader.reduce(function(a, b) { return a || b}, false)) { return header; }
}).map(function(header) {
if (header.name === "Referer") {
header.value = "https://www.google.com/";
foundReferer = true;
}
if (header.name === "User-Agent") {
header.value = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";
foundUA = true;
}
return header;
})
// append referer
if (!foundReferer) {
reqHeaders.push({
"name": "Referer",
"value": "https://www.google.com/"
})
}
if (!foundUA) {
reqHeaders.push({
"name": "User-Agent",
"value": "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
})
}
console.log(reqHeaders);
return {requestHeaders: reqHeaders};
}
function blockCookies(details) {
for (var i = 0; i < details.responseHeaders.length; ++i) {
if (details.responseHeaders[i].name === "Set-Cookie") {
details.responseHeaders.splice(i, 1);
}
}
return {responseHeaders: details.responseHeaders};
}
chrome.webRequest.onBeforeSendHeaders.addListener(changeRefer, {
urls: ["<all_urls>"],
types: ["main_frame"],
}, ["requestHeaders", "blocking"]);
chrome.webRequest.onHeadersReceived.addListener(blockCookies, {
urls: ["<all_urls>"],
types: ["main_frame"],
}, ["responseHeaders", "blocking"]);
{
"name": "Paywall Bitch Chrome Extension",
"version": "0.1",
"description": "Paywall Bitch",
"permissions": ["webRequest", "webRequestBlocking",
"http://ftalphaville.ft.com/*",
"http://www.ft.com/*",
"http://blogs.ft.com/*",
"http://www.glassdoor.com/*",
"https://www.glassdoor.com/*",
"http://blogs.wsj.com/*",
"http://www.wsj.com/*",
"https://www.wsj.com/*",
"http://www.economist.com/*",
"http://www.nytimes.com/*",
"http://*.blogs.nytimes.com/*",
"https://hbr.org/*",
"http://www.newyorker.com/*",
"http://www.forbes.com/*",
"http://online.barrons.com/*",
"http://www.barrons.com/*",
"http://www.investingdaily.com/*",
"http://realmoney.thestreet.com/*",
"http://www.washingtonpost.com/*",
"http://www.seattletimes.com/*",
"https://www.seattletimes.com/*",
"http://http://www.lemonde.fr/*"
],
"background": {
"scripts": ["background.js"]
},
"manifest_version": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment