2017-07-08 14:16:27 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var defaultSites = {
|
|
|
|
'Baltimore Sun': 'baltimoresun.com',
|
2017-09-14 21:59:39 -07:00
|
|
|
'Barron\'s': 'barrons.com',
|
2018-05-05 19:08:25 +10:00
|
|
|
'Bloomberg': 'bloomberg.com',
|
2017-07-08 14:16:27 -07:00
|
|
|
'Crain\'s Chicago Business': 'chicagobusiness.com',
|
|
|
|
'Chicago Tribune': 'chicagotribune.com',
|
2018-04-05 23:34:36 -07:00
|
|
|
'Corriere Della Sera': 'corriere.it',
|
2017-07-08 14:16:27 -07:00
|
|
|
'Daily Press': 'dailypress.com',
|
2018-04-05 23:34:36 -07:00
|
|
|
'Dagens Nyheter': 'dn.se',
|
2018-07-04 18:02:08 -07:00
|
|
|
'Denver Post': 'denverpost.com',
|
2018-09-06 20:10:57 +10:00
|
|
|
'Dynamed Plus': 'dynamed.com',
|
2017-07-08 14:16:27 -07:00
|
|
|
'The Economist': 'economist.com',
|
2019-01-04 19:24:11 +01:00
|
|
|
'Les Echos': 'lesechos.fr',
|
2019-03-20 19:03:37 -07:00
|
|
|
'Encyclopedia Britannica': 'britannica.com',
|
2018-10-02 12:20:22 +10:00
|
|
|
'Examiner': 'examiner.com.au',
|
2019-04-06 13:31:12 -07:00
|
|
|
'Financial News': 'fnlondon.com',
|
2017-07-08 14:16:27 -07:00
|
|
|
'Financial Times': 'ft.com',
|
2019-04-06 13:31:12 -07:00
|
|
|
'Foreign Affairs': 'foreignaffairs.com',
|
2018-11-11 14:47:16 -08:00
|
|
|
'Foreign Policy': 'foreignpolicy.com',
|
2017-07-08 14:16:27 -07:00
|
|
|
'Glassdoor': 'glassdoor.com',
|
2018-12-04 22:39:37 -08:00
|
|
|
'Haaretz': 'haaretz.co.il',
|
2018-04-23 12:21:18 +03:00
|
|
|
'Haaretz English': 'haaretz.com',
|
2017-07-08 14:16:27 -07:00
|
|
|
'Hartford Courant': 'courant.com',
|
2019-01-04 19:28:16 +01:00
|
|
|
'Harper\'s Magazine': 'harpers.org',
|
2017-07-08 14:16:27 -07:00
|
|
|
'Harvard Business Review': 'hbr.org',
|
|
|
|
'Inc.com': 'inc.com',
|
2019-03-10 14:15:18 -07:00
|
|
|
'Irish Times': 'irishtimes.com',
|
2018-12-07 13:43:16 +01:00
|
|
|
'La Repubblica': 'repubblica.it',
|
2019-01-04 19:24:11 +01:00
|
|
|
'Liberation': 'liberation.fr',
|
2017-07-08 14:16:27 -07:00
|
|
|
'Los Angeles Times': 'latimes.com',
|
2018-01-30 21:26:21 -08:00
|
|
|
'Medium': 'medium.com',
|
2017-07-08 14:16:27 -07:00
|
|
|
'MIT Technology Review': 'technologyreview.com',
|
2019-02-17 13:43:21 -08:00
|
|
|
'Newsrep': 'thenewsrep.com',
|
2019-04-06 13:31:12 -07:00
|
|
|
'New York Magazine': 'nymag.com',
|
2017-07-08 14:16:27 -07:00
|
|
|
'Nikkei Asian Review': 'asia.nikkei.com',
|
|
|
|
'NRC': 'nrc.nl',
|
2018-08-26 10:03:12 +10:00
|
|
|
'OrlandoSentinel': 'orlandosentinel.com',
|
|
|
|
'Quora': 'quora.com',
|
2019-04-06 13:31:12 -07:00
|
|
|
'San Francisco Chronicle': 'sfchronicle.com',
|
2019-04-28 13:43:51 -07:00
|
|
|
'Scientific American': 'scientificamerican.com',
|
2018-08-26 10:03:12 +10:00
|
|
|
'SunSentinel': 'sun-sentinel.com',
|
2018-10-02 12:11:16 +10:00
|
|
|
'The Advocate': 'theadvocate.com.au',
|
2018-12-04 22:39:37 -08:00
|
|
|
'The Age': 'theage.com.au',
|
2018-01-30 21:26:21 -08:00
|
|
|
'The Boston Globe': 'bostonglobe.com',
|
2019-04-06 13:31:12 -07:00
|
|
|
'The Globe and Mail': 'theglobeandmail.com',
|
2019-03-20 18:55:00 -07:00
|
|
|
'The Japan Times': 'japantimes.co.jp',
|
2018-12-04 22:39:37 -08:00
|
|
|
'TheMarker': 'themarker.com',
|
2018-01-30 21:26:21 -08:00
|
|
|
'The Mercury News': 'mercurynews.com',
|
2017-07-08 14:16:27 -07:00
|
|
|
'The Morning Call': 'mcall.com',
|
|
|
|
'The Nation': 'thenation.com',
|
2018-08-26 09:59:06 +10:00
|
|
|
'The New Statesman': 'newstatesman.com',
|
2017-07-08 14:16:27 -07:00
|
|
|
'The New York Times': 'nytimes.com',
|
|
|
|
'The New Yorker': 'newyorker.com',
|
|
|
|
'The Seattle Times': 'seattletimes.com',
|
2018-08-26 10:00:48 +10:00
|
|
|
'The Spectator': 'spectator.co.uk',
|
2017-07-08 14:16:27 -07:00
|
|
|
'The Sydney Morning Herald': 'smh.com.au',
|
|
|
|
'The Washington Post': 'washingtonpost.com',
|
2018-06-26 23:09:29 -07:00
|
|
|
'The Wall Street Journal': 'wsj.com',
|
2018-12-16 13:57:09 -08:00
|
|
|
'Winston-Salem Journal': 'journalnow.com',
|
2019-04-06 13:31:12 -07:00
|
|
|
'Vanity Fair': 'vanityfair.com',
|
2018-10-02 12:11:16 +10:00
|
|
|
'Wired': 'wired.com'
|
2017-07-08 14:16:27 -07:00
|
|
|
};
|
|
|
|
|
2018-01-30 21:26:21 -08:00
|
|
|
const restrictions = {
|
2017-07-08 14:16:27 -07:00
|
|
|
'barrons.com': 'barrons.com/articles'
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't remove cookies before page load
|
2018-01-30 21:26:21 -08:00
|
|
|
const allow_cookies = [
|
2017-07-08 14:16:27 -07:00
|
|
|
'asia.nikkei.com',
|
|
|
|
'nytimes.com',
|
|
|
|
'wsj.com',
|
2018-01-30 21:26:21 -08:00
|
|
|
'ft.com',
|
|
|
|
'fd.nl',
|
2018-04-05 23:34:36 -07:00
|
|
|
'mercurynews.com',
|
2018-04-07 11:01:10 -07:00
|
|
|
'theage.com.au',
|
2018-05-12 17:14:39 -07:00
|
|
|
'economist.com',
|
2018-07-04 18:02:08 -07:00
|
|
|
'bostonglobe.com',
|
2018-09-09 18:54:40 -07:00
|
|
|
'denverpost.com',
|
2018-09-30 17:33:18 +10:00
|
|
|
'chicagobusiness.com',
|
2018-09-30 19:34:59 +10:00
|
|
|
'theadvocate.com.au',
|
2018-10-07 12:59:33 -07:00
|
|
|
'examiner.com.au',
|
|
|
|
'hbr.org',
|
2019-01-05 18:01:37 -08:00
|
|
|
'medium.com',
|
2019-03-10 14:15:18 -07:00
|
|
|
'washingtonpost.com',
|
2019-04-06 13:31:12 -07:00
|
|
|
'nymag.com',
|
2017-07-08 14:16:27 -07:00
|
|
|
]
|
|
|
|
|
|
|
|
// Removes cookies after page load
|
2018-01-30 21:26:21 -08:00
|
|
|
const remove_cookies = [
|
2017-07-08 14:16:27 -07:00
|
|
|
'asia.nikkei.com',
|
2018-01-30 21:26:21 -08:00
|
|
|
'ft.com',
|
|
|
|
'fd.nl',
|
2018-04-05 23:34:36 -07:00
|
|
|
'mercurynews.com',
|
2018-04-07 11:01:10 -07:00
|
|
|
'theage.com.au',
|
2018-05-12 17:14:39 -07:00
|
|
|
'economist.com',
|
2018-06-08 17:14:57 -04:00
|
|
|
'bostonglobe.com',
|
2018-07-04 18:02:08 -07:00
|
|
|
'wired.com',
|
2018-09-09 18:54:40 -07:00
|
|
|
'denverpost.com',
|
2018-09-30 15:55:46 +10:00
|
|
|
'chicagobusiness.com',
|
2019-01-04 19:28:16 +01:00
|
|
|
'harpers.org',
|
2018-09-30 19:34:59 +10:00
|
|
|
'theadvocate.com.au',
|
2018-10-07 12:59:33 -07:00
|
|
|
'examiner.com.au',
|
2019-01-04 19:24:11 +01:00
|
|
|
'lesechos.fr',
|
|
|
|
'liberation.fr',
|
2018-10-07 12:59:33 -07:00
|
|
|
'hbr.org',
|
2018-11-11 14:47:16 -08:00
|
|
|
'medium.com',
|
|
|
|
'foreignpolicy.com',
|
2018-12-09 20:32:54 -08:00
|
|
|
'wsj.com',
|
2019-02-17 13:43:21 -08:00
|
|
|
'seattletimes.com',
|
|
|
|
'thenewsrep.com',
|
|
|
|
'washingtonpost.com',
|
2019-04-06 13:31:12 -07:00
|
|
|
'sfchronicle.com',
|
|
|
|
'nymag.com',
|
|
|
|
'foreignaffairs.com',
|
2019-04-28 13:43:51 -07:00
|
|
|
'scientificamerican.com',
|
2017-07-08 14:16:27 -07:00
|
|
|
]
|
|
|
|
|
|
|
|
function setDefaultOptions() {
|
|
|
|
chrome.storage.sync.set({
|
|
|
|
sites: defaultSites
|
|
|
|
}, function() {
|
|
|
|
chrome.tabs.create({ 'url': 'chrome://extensions/?options=' + chrome.runtime.id });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var blockedRegexes = [
|
|
|
|
/.+:\/\/.+\.tribdss\.com\//,
|
2018-10-07 11:52:56 -07:00
|
|
|
/thenation\.com\/.+\/paywall-script\.php/,
|
|
|
|
/haaretz\.co\.il\/htz\/js\/inter\.js/
|
2017-07-08 14:16:27 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-02-06 23:17:42 -08:00
|
|
|
// WSJ bypass
|
|
|
|
chrome.webRequest.onBeforeRequest.addListener(function (details) {
|
2019-02-10 15:14:18 -08:00
|
|
|
if (!isSiteEnabled(details) || details.url.indexOf("mod=rsswn") !== -1) {
|
2019-02-06 23:17:42 -08:00
|
|
|
return;
|
|
|
|
}
|
2019-02-07 19:23:57 -08:00
|
|
|
|
|
|
|
var param;
|
|
|
|
var updatedUrl;
|
|
|
|
|
|
|
|
param = getParameterByName("mod", details.url);
|
|
|
|
|
|
|
|
if (param === null) {
|
|
|
|
updatedUrl = stripQueryStringAndHashFromPath(details.url);
|
|
|
|
updatedUrl += "?mod=rsswn";
|
|
|
|
} else {
|
|
|
|
updatedUrl = details.url.replace(param, "rsswn");
|
|
|
|
}
|
|
|
|
return { redirectUrl: updatedUrl};
|
|
|
|
},
|
|
|
|
{urls:["*://*.wsj.com/*"], types:["main_frame"]},
|
|
|
|
["blocking"]
|
2019-02-06 23:17:42 -08:00
|
|
|
);
|
2017-07-08 14:16:27 -07:00
|
|
|
|
|
|
|
chrome.webRequest.onBeforeSendHeaders.addListener(function(details) {
|
2019-02-06 23:17:42 -08:00
|
|
|
if (!isSiteEnabled(details)) {
|
2017-07-08 14:16:27 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-04 22:39:37 -08:00
|
|
|
if (blockedRegexes.some(function(regex) { return regex.test(details.url); })) {
|
|
|
|
return { cancel: true };
|
|
|
|
}
|
|
|
|
|
2017-07-08 14:16:27 -07:00
|
|
|
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') {
|
2019-02-20 19:42:13 -08:00
|
|
|
if (details.url.indexOf("wsj.com") !== -1 || details.url.indexOf("ft.com") !== -1) {
|
2017-07-08 14:16:27 -07:00
|
|
|
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>']
|
2019-02-02 15:30:42 -08:00
|
|
|
}, ['blocking', 'requestHeaders', 'extraHeaders']);
|
2017-07-08 14:16:27 -07:00
|
|
|
|
|
|
|
// 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++) {
|
2018-09-18 15:24:21 -04:00
|
|
|
chrome.cookies.remove({url: (cookies[i].secure ? "https://" : "http://") + cookies[i].domain + cookies[i].path, name: cookies[i].name});
|
2017-07-08 14:16:27 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
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);
|
|
|
|
})();
|
2019-02-06 23:17:42 -08:00
|
|
|
|
|
|
|
function isSiteEnabled(details) {
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
return isEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getParameterByName(name, url) {
|
|
|
|
if (!url) url = window.location.href;
|
|
|
|
name = name.replace(/[\[\]]/g, '\\$&');
|
|
|
|
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
|
|
|
|
results = regex.exec(url);
|
|
|
|
if (!results) return null;
|
|
|
|
if (!results[2]) return '';
|
|
|
|
return decodeURIComponent(results[2].replace(/\+/g, ' '));
|
2019-02-07 19:23:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function stripQueryStringAndHashFromPath(url) {
|
|
|
|
return url.split("?")[0].split("#")[0];
|
2019-02-06 23:17:42 -08:00
|
|
|
}
|