Initial commit

This commit is contained in:
ghost 2017-07-08 14:16:27 -07:00
commit 6b1eb227e1
12 changed files with 439 additions and 0 deletions

1
README.md Normal file
View File

@ -0,0 +1 @@
"# Bypass Paywalls for Chrome"

220
background.js Normal file
View File

@ -0,0 +1,220 @@
'use strict';
var defaultSites = {
'The Age': 'theage.com.au',
'The Australian': 'theaustralian.com.au',
'Baltimore Sun': 'baltimoresun.com',
'Barron\'s': 'barrons.com',
'Crain\'s Chicago Business': 'chicagobusiness.com',
'Chicago Tribune': 'chicagotribune.com',
'Daily Press': 'dailypress.com',
'The Economist': 'economist.com',
'Financial Times': 'ft.com',
'Glassdoor': 'glassdoor.com',
'Hartford Courant': 'courant.com',
'Harvard Business Review': 'hbr.org',
'Inc.com': 'inc.com',
'Los Angeles Times': 'latimes.com',
'Medscape': 'medscape.com',
'MIT Technology Review': 'technologyreview.com',
'Nikkei Asian Review': 'asia.nikkei.com',
'NRC': 'nrc.nl',
'The Courier Mail': 'couriermail.com.au',
'The Morning Call': 'mcall.com',
'The Nation': 'thenation.com',
'The New York Times': 'nytimes.com',
'The New Yorker': 'newyorker.com',
'OrlandoSentinel': 'orlandosentinel.com',
'Quora': 'quora.com',
'SunSentinel': 'sun-sentinel.com',
'The Seattle Times': 'seattletimes.com',
'The Sydney Morning Herald': 'smh.com.au',
'The Telegraph': 'telegraph.co.uk',
'The Washington Post': 'washingtonpost.com',
'The Wall Street Journal': 'wsj.com'
};
var restrictions = {
'barrons.com': 'barrons.com/articles'
}
// Don't remove cookies before page load
var allow_cookies = [
'theaustralian.com.au',
'asia.nikkei.com',
'nytimes.com',
'wsj.com',
'couriermail.com.au'
]
// Removes cookies after page load
var remove_cookies = [
'theaustralian.com.au',
'asia.nikkei.com',
'couriermail.com.au'
]
function setDefaultOptions() {
chrome.storage.sync.set({
sites: defaultSites
}, function() {
chrome.tabs.create({ 'url': 'chrome://extensions/?options=' + chrome.runtime.id });
});
}
var blockedRegexes = [
/.+:\/\/.+\.tribdss\.com\//,
/thenation\.com\/.+\/paywall-script\.php/
];
var enabledSites = [];
// Get the enabled sites
chrome.storage.sync.get({
sites: {}
}, function(items) {
var sites = items.sites;
enabledSites = Object.keys(items.sites).map(function(key) {
return items.sites[key];
});
});
// Listen for changes to options
chrome.storage.onChanged.addListener(function(changes, namespace) {
var key;
for (key in changes) {
var storageChange = changes[key];
if (key === 'sites') {
var sites = storageChange.newValue;
enabledSites = Object.keys(sites).map(function(key) {
return sites[key];
});
}
}
});
// Set and show default options on install
chrome.runtime.onInstalled.addListener(function (details) {
if (details.reason == "install") {
setDefaultOptions();
} else if (details.reason == "update") {
// User updated extension
}
});
chrome.webRequest.onBeforeSendHeaders.addListener(function(details) {
if (blockedRegexes.some(function(regex) { return regex.test(details.url); })) {
return { cancel: true };
}
var isEnabled = enabledSites.some(function(enabledSite) {
var useSite = details.url.indexOf(enabledSite) !== -1;
if (enabledSite in restrictions) {
return useSite && details.url.indexOf(restrictions[enabledSite]) !== -1;
}
return useSite;
});
if (!isEnabled) {
return;
}
var requestHeaders = details.requestHeaders;
var tabId = details.tabId;
var setReferer = false;
// if referer exists, set it to google
requestHeaders = requestHeaders.map(function(requestHeader) {
if (requestHeader.name === 'Referer') {
if (details.url.indexOf("wsj.com") !== -1) {
requestHeader.value = 'https://www.facebook.com/';
} else {
requestHeader.value = 'https://www.google.com/';
}
setReferer = true;
}
return requestHeader;
});
// otherwise add it
if (!setReferer) {
if (details.url.indexOf("wsj.com") !== -1) {
requestHeaders.push({
name: 'Referer',
value: 'https://www.facebook.com/'
});
} else {
requestHeaders.push({
name: 'Referer',
value: 'https://www.google.com/'
});
}
}
// remove cookies before page load
requestHeaders = requestHeaders.map(function(requestHeader) {
for (var siteIndex in allow_cookies) {
if (details.url.indexOf(allow_cookies[siteIndex]) !== -1) {
return requestHeader;
}
}
if (requestHeader.name === 'Cookie') {
requestHeader.value = '';
}
return requestHeader;
});
if (tabId !== -1) {
// run contentScript inside tab
chrome.tabs.executeScript(tabId, {
file: 'contentScript.js',
runAt: 'document_start'
}, function(res) {
if (chrome.runtime.lastError || res[0]) {
return;
}
});
}
return { requestHeaders: requestHeaders };
}, {
urls: ['<all_urls>']
}, ['blocking', 'requestHeaders']);
// remove cookies after page load
chrome.webRequest.onCompleted.addListener(function(details) {
for (var domainIndex in remove_cookies) {
var domainVar = remove_cookies[domainIndex];
if (!enabledSites.includes(domainVar) || details.url.indexOf(domainVar) === -1) {
continue; // don't remove cookies
}
chrome.cookies.getAll({domain: domainVar}, function(cookies) {
for (var i=0; i<cookies.length; i++) {
chrome.cookies.remove({url: cookies[i].secure ? "https://" : "http://" + cookies[i].domain + cookies[i].path, name: cookies[i].name});
}
});
}
}, {
urls: ["<all_urls>"]
});
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-69824169-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

BIN
bypass.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 693 B

6
bypass.svg Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg fill="currentColor" width="1em" height="1em" viewBox="0 0 40 40" preserveAspectRatio="xMidYMid meet" style="vertical-align:middle;display:inline-block;" data-reactid=".0.4:$/=10.2.0">
<g data-reactid=".0.4:$/=10.2.0.0">
<path d="m20 12.5h-7.5v7.5h7.5v-7.5z m2.5 12.5v2.5h-12.5v-2.5h12.5z m0-15v12.5h-12.5v-12.5h12.5z m12.5 15v2.5h-10v-2.5h10z m0-5v2.5h-10v-2.5h10z m0-5v2.5h-10v-2.5h10z m0-5v2.5h-10v-2.5h10z m-30 18.75v-18.75h-2.5v18.75q0 0.5075000000000003 0.37124999999999986 0.8787500000000001t0.8787500000000001 0.37124999999999986 0.8787500000000001-0.37124999999999986 0.37124999999999986-0.8787500000000001z m32.5 0v-21.25h-30v21.25q0 0.6449999999999996-0.21499999999999986 1.25h28.965q0.5075000000000003 0 0.8787499999999966-0.37124999999999986t0.3712500000000034-0.8787500000000001z m2.5-23.75v23.75q0 1.5625-1.09375 2.65625t-2.65625 1.09375h-32.5q-1.5625 0-2.65625-1.09375t-1.09375-2.65625v-21.25h5v-2.5h35z" data-reactid=".0.4:$/=10.2.0.0.0"></path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 KiB

40
changelog.txt Normal file
View File

@ -0,0 +1,40 @@
Updates--
2017-04-16: Added MIT Technology Review (technologyreview.com), NRC (nrc.nl), The Courier Mail (couriermail.com.au).
2017-04-05: Added 'Nikkei Asian Review'.
2017-02-25: If you are trying to view NYT articles or tired of the WSJ popup, try installing an adblocker (I recommend 'uBlock Origin').
2017-02-16: Added 'The Australian'.
2017-02-09: WSJ working again (bypass paywall)! Also added glassdoor, nytimes, seattletimes.
Bypass the following sites' paywalls:
The Age (theage.com.au)
The Australian (theaustralian.com.au)
Baltimore Sun (baltimoresun.com)
Barron's (barrons.com)
Crain's Chicago Business (chicagobusiness.com)
Chicago Tribune (chicagotribune.com)
Daily Press (dailypress.com)
The Economist (economist.com)
Financial Times (ft.com)
Glassdoor (glassdoor.com)
Hartford Courant (courant.com)
Harvard Business Review (hbr.org)
Inc.com (inc.com)
Los Angeles Times (latimes.com)
Medscape (medscape.com)
MIT Technology Review (technologyreview.com)
Nikkei Asian Review (asia.nikkei.com)
NRC (nrc.nl)
The Courier Mail (couriermail.com.au)
The Morning Call (mcall.com)
The Nation (thenation.com)
The New York Times (nytimes.com)
The New Yorker (newyorker.com)
OrlandoSentinel (orlandosentinel.com)
Quora (quora.com)
SunSentinel (sun-sentinel.com)
The Seattle Times (seattletimes.com)
The Sydney Morning Herald (smh.com.au)
The Telegraph (telegraph.co.uk)
The Washington Post (washingtonpost.com)
The Wall Street Journal (wsj.com)

1
contentScript.js Normal file
View File

@ -0,0 +1 @@
window.localStorage.clear();

BIN
ft_screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

24
manifest.json Normal file
View File

@ -0,0 +1,24 @@
{
"background": {
"scripts": ["background.js"]
},
"content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'",
"browser_action": {
"default_popup": "popup.html"
},
"description": "Bypass News Sites' Paywalls",
"icons": {
"128": "bypass.png"
},
"manifest_version": 2,
"name": "Bypass Paywalls",
"short_name": "Bypass Paywall",
"options_ui": {
"chrome_style": true,
"page": "options.html"
},
"permissions": [ "cookies",
"*://*.baltimoresun.com/", "*://*.barrons.com/", "*://*.chicagobusiness.com/", "*://*.chicagotribune.com/", "*://*.dailypress.com/", "*://*.economist.com/", "*://*.ft.com/", "*://*.courant.com/", "*://*.hbr.org/", "*://*.inc.com/", "*://*.jacksonville.com/", "*://*.latimes.com/", "*://*.mcall.com/", "*://*.medscape.com/", "*://*.newyorker.com/", "*://*.orlandosentinel.com/", "*://*.quora.com/", "*://*.telegraph.co.uk/", "*://*.theage.com.au/", "*://*.thenation.com/", "*://*.tribdss.com/", "*://*.smh.com.au/", "*://*.sun-sentinel.com/", "*://*.washingtonpost.com/", "*://*.wsj.com/", "*://*.seattletimes.com/", "*://*.glassdoor.com/", "*://*.nytimes.com/", "*://.theaustralian.com.au/", "*://*.theaustralian.com.au/", "*://*.nikkei.com/", "*://*.technologyreview.com/", "*://*.nrc.nl/", "*://*.couriermail.com.au/", "*://.couriermail.com.au/", "storage", "webRequest", "webRequestBlocking"],
"version": "1.0.4"
}

34
options.html Normal file
View File

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<title>Bypass Paywalls Options</title>
<style>
#bypass_sites label {
display: block;
}
body {
width:350px;
height:600px;
}
</style>
</head>
<body>
<div>
Selected sites will have their cookies cleared and referer set to Google. You should
uncheck sites you have an account with or else you will be logged out at every visit.
</div>
<br/>
<div id='bypass_sites'>
</div>
<br/>
<div id="status"></div>
<div id="error"></div>
<br/>
<button id="save">Save</button>
<span style='float:right;'>
<button id="select-all">Select all</button>
<button id="select-none">Select none</button>
</span>
<script src="options.js"></script>
</body>
</html>

107
options.js Normal file
View File

@ -0,0 +1,107 @@
var defaultSites = {
'The Age': 'theage.com.au',
'The Australian': 'theaustralian.com.au',
'Baltimore Sun': 'baltimoresun.com',
'Barron\'s': 'barrons.com',
'Crain\'s Chicago Business': 'chicagobusiness.com',
'Chicago Tribune': 'chicagotribune.com',
'Daily Press': 'dailypress.com',
'The Economist': 'economist.com',
'Financial Times': 'ft.com',
'Glassdoor': 'glassdoor.com',
'Hartford Courant': 'courant.com',
'Harvard Business Review': 'hbr.org',
'Inc.com': 'inc.com',
'Los Angeles Times': 'latimes.com',
'Medscape': 'medscape.com',
'MIT Technology Review': 'technologyreview.com',
'Nikkei Asian Review': 'asia.nikkei.com',
'NRC': 'nrc.nl',
'The Courier Mail': 'couriermail.com.au',
'The Morning Call': 'mcall.com',
'The Nation': 'thenation.com',
'The New York Times': 'nytimes.com',
'The New Yorker': 'newyorker.com',
'OrlandoSentinel': 'orlandosentinel.com',
'Quora': 'quora.com',
'SunSentinel': 'sun-sentinel.com',
'The Seattle Times': 'seattletimes.com',
'The Sydney Morning Herald': 'smh.com.au',
'The Telegraph': 'telegraph.co.uk',
'The Washington Post': 'washingtonpost.com',
'The Wall Street Journal': 'wsj.com'
};
// Saves options to chrome.storage
function save_options() {
var gh_url = document.getElementById('bypass_sites').value;
var inputEls = document.querySelectorAll('#bypass_sites input');
var sites = {};
var sites = Array.from(inputEls).reduce(function(memo, inputEl) {
if (inputEl.checked) {
memo[inputEl.dataset.key] = inputEl.dataset.value;
}
return memo;
}, {});
chrome.storage.sync.set({
sites: sites
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function() {
status.textContent = '';
window.close();
}, 800);
});
}
// Restores checkbox input states using the preferences
// stored in chrome.storage.
function renderOptions() {
chrome.storage.sync.get({
sites: {}
}, function(items) {
var sites = items.sites;
var sitesEl = document.getElementById('bypass_sites');
for (var key in defaultSites) {
if (!defaultSites.hasOwnProperty(key)) {
continue;
}
var value = defaultSites[key];
var labelEl = document.createElement('label');
var inputEl = document.createElement('input');
inputEl.type = 'checkbox';
inputEl.dataset.key = key;
inputEl.dataset.value = value;
inputEl.checked = key in sites;
labelEl.appendChild(inputEl);
labelEl.appendChild(document.createTextNode(' '+key));
sitesEl.appendChild(labelEl);
}
});
}
function selectAll() {
var inputEls = Array.from(document.querySelectorAll('input'));
inputEls.forEach(function(inputEl) {
inputEl.checked = true;
});
}
function selectNone() {
var inputEls = Array.from(document.querySelectorAll('input'));
inputEls.forEach(function(inputEl) {
inputEl.checked = false;
});
}
document.addEventListener('DOMContentLoaded', renderOptions);
document.getElementById('save').addEventListener('click', save_options);
document.getElementById('select-all').addEventListener('click', selectAll);
document.getElementById('select-none').addEventListener('click', selectNone);

6
popup.html Normal file
View File

@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
<div style="width:180px;">Bypass Paywalls by Adam</div>
</body>
</html>