415 lines
11 KiB
JavaScript
Raw Normal View History

2017-07-08 14:16:27 -07:00
'use strict';
var defaultSites = {
'Algemeen Dagblad': 'ad.nl',
2019-05-12 22:27:15 -07:00
'American Banker': 'americanbanker.com',
2017-07-08 14:16:27 -07:00
'Baltimore Sun': 'baltimoresun.com',
'Barron\'s': 'barrons.com',
2018-05-05 19:08:25 +10:00
'Bloomberg': 'bloomberg.com',
'Business Insider': 'businessinsider.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',
'De Groene Amsterdammer': 'groene.nl',
'De Volkskrant': 'volkskrant.nl',
2019-05-25 14:41:10 -07:00
'DeMorgen': 'demorgen.be',
2018-07-04 18:02:08 -07:00
'Denver Post': 'denverpost.com',
'Dynamed Plus': 'dynamed.com',
2017-07-08 14:16:27 -07:00
'The Economist': 'economist.com',
'Les Echos': 'lesechos.fr',
2019-06-02 13:38:20 +02:00
'Eindhovens Dagblad': 'ed.nl',
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-09-23 21:21:21 +03:00
'First Things': 'firstthings.com',
'Financial News': 'fnlondon.com',
2017-07-08 14:16:27 -07:00
'Financial Times': 'ft.com',
'Foreign Policy': 'foreignpolicy.com',
2017-07-08 14:16:27 -07:00
'Glassdoor': 'glassdoor.com',
'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',
'Liberation': 'liberation.fr',
2019-10-15 14:11:26 +02:00
'Loeb Classical Library': 'loebclassics.com',
2017-07-08 14:16:27 -07:00
'Los Angeles Times': 'latimes.com',
2018-01-30 21:26:21 -08:00
'Medium': 'medium.com',
'Mexico News Daily': 'mexiconewsdaily.com',
2019-06-20 22:28:29 -07:00
'MIT Sloan Management Review': 'sloanreview.mit.edu',
2017-07-08 14:16:27 -07:00
'MIT Technology Review': 'technologyreview.com',
2019-02-17 13:43:21 -08:00
'Newsrep': 'thenewsrep.com',
'New York Magazine': 'nymag.com',
2017-07-08 14:16:27 -07:00
'Nikkei Asian Review': 'asia.nikkei.com',
'NRC': 'nrc.nl',
2019-09-22 17:10:17 -07:00
'New Zealand Herald': 'nzherald.co.nz',
2019-09-25 18:54:25 +02:00
'OrlandoSentinel': 'orlandosentinel.com',
'Parool': 'parool.nl',
2019-05-25 14:25:56 -07:00
'Quartz': 'qz.com',
2018-08-26 10:03:12 +10:00
'Quora': 'quora.com',
'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',
2019-07-11 09:43:44 -08:00
'Statista':'statista.com',
2019-06-02 13:33:52 +02:00
'Telegraaf': 'telegraaf.nl',
2018-10-02 12:11:16 +10:00
'The Advocate': 'theadvocate.com.au',
'The Age': 'theage.com.au',
2019-09-16 21:07:04 +03:00
'The American Interest': 'the-american-interest.com',
2019-09-18 11:04:03 +02:00
'The Atlantic': 'theatlantic.com',
'The Australian': 'theaustralian.com.au',
'The Australian Financial Review': 'afr.com',
2018-01-30 21:26:21 -08:00
'The Boston Globe': 'bostonglobe.com',
'The Business Journals': 'bizjournals.com',
'The Globe and Mail': 'theglobeandmail.com',
2019-03-20 18:55:00 -07:00
'The Japan Times': 'japantimes.co.jp',
'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',
'The News-Gazette': 'news-gazette.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',
2019-06-21 20:42:35 -07:00
'The Telegraph': 'telegraph.co.uk',
2019-09-22 17:03:15 -07:00
'The Times': 'thetimes.co.uk',
'The Toronto Star': 'thestar.com',
2017-07-08 14:16:27 -07:00
'The Washington Post': 'washingtonpost.com',
2018-06-26 23:09:29 -07:00
'The Wall Street Journal': 'wsj.com',
'Trouw': 'trouw.nl',
'Winston-Salem Journal': 'journalnow.com',
'Vanity Fair': 'vanityfair.com',
'Vrij Nederland': 'vn.nl',
2019-06-21 20:53:21 -07:00
'Wired': 'wired.com',
'Zeit Online': 'zeit.de'
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',
'ad.nl',
'ed.nl',
'parool.nl',
'trouw.nl',
'vn.nl',
'volkskrant.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',
'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',
'nymag.com',
'theaustralian.com.au',
2019-06-02 13:33:52 +02:00
'telegraaf.nl', // keep accept cookies
2019-05-25 14:41:10 -07:00
'demorgen.be',
'mexiconewsdaily.com',
2019-09-16 21:07:04 +03:00
'the-american-interest.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',
'ad.nl',
2019-06-05 14:46:20 +03:00
'ed.nl',
'vn.nl',
2018-01-30 21:26:21 -08:00
'ft.com',
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',
'chicagobusiness.com',
2019-01-04 19:28:16 +01:00
'harpers.org',
2018-09-30 19:34:59 +10:00
'theadvocate.com.au',
'examiner.com.au',
'lesechos.fr',
'liberation.fr',
2019-10-15 14:11:26 +02:00
'loebclassics.com',
'hbr.org',
2019-09-18 11:04:03 +02:00
'theatlantic.com',
'medium.com',
'mexiconewsdaily.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',
'sfchronicle.com',
'nymag.com',
2019-04-28 13:43:51 -07:00
'scientificamerican.com',
2019-06-02 13:33:52 +02:00
'telegraaf.nl',
'thestar.com',
2019-05-25 14:25:56 -07:00
'qz.com',
2019-05-25 14:41:10 -07:00
'demorgen.be',
2019-06-20 22:28:29 -07:00
'sloanreview.mit.edu',
2019-06-21 20:53:21 -07:00
'zeit.de',
2019-09-23 21:21:21 +03:00
'firstthings.com'
2017-07-08 14:16:27 -07:00
]
2019-05-12 14:00:27 -07:00
// Override User-Agent with Googlebot
const use_google_bot = [
'theaustralian.com.au',
2019-05-25 14:18:22 -07:00
'barrons.com',
2019-06-21 20:42:35 -07:00
'telegraph.co.uk',
'zeit.de',
2019-09-22 16:54:54 -07:00
'mexiconewsdaily.com',
2019-09-22 17:03:15 -07:00
'thetimes.co.uk',
2019-05-12 14:00:27 -07:00
]
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\//,
/thenation\.com\/.+\/paywall-script\.php/,
2019-09-22 17:10:17 -07:00
/haaretz\.co\.il\/htz\/js\/inter\.js/,
/nzherald\.co\.nz\/.+\/headjs\/.+\.js/
2017-07-08 14:16:27 -07:00
];
const userAgentDesktop = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
const userAgentMobile = "Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible ; Googlebot/2.1 ; +http://www.google.com/bot.html)"
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
}
});
// WSJ bypass
chrome.webRequest.onBeforeRequest.addListener(function (details) {
if (!isSiteEnabled(details) || details.url.indexOf("mod=rsswn") !== -1) {
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"]
);
2017-07-08 14:16:27 -07:00
// Disable javascript for these sites
chrome.webRequest.onBeforeRequest.addListener(function(details) {
if (!isSiteEnabled(details) || details.url.indexOf("mod=rsswn") !== -1) {
return;
}
return {cancel: true};
},
{
urls: ["*://*.thestar.com/*", "*://*.economist.com/*", "*://*.theglobeandmail.com/*", "*://*.afr.com/*", "*://*.bizjournals.com/*", "*://*.businessinsider.com/*", "*://*.bostonglobe.com/*"],
types: ["script"]
},
["blocking"]
);
2017-07-08 14:16:27 -07:00
chrome.webRequest.onBeforeSendHeaders.addListener(function(details) {
if (!isSiteEnabled(details)) {
2017-07-08 14:16:27 -07:00
return;
}
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 useUserAgentMobile = false;
2017-07-08 14:16:27 -07:00
var setReferer = false;
// if referer exists, set it to google
requestHeaders = requestHeaders.map(function (requestHeader) {
2017-07-08 14:16:27 -07:00
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) {
requestHeader.value = 'https://www.facebook.com/';
} else {
requestHeader.value = 'https://www.google.com/';
}
setReferer = true;
}
if (requestHeader.name === 'User-Agent') {
useUserAgentMobile = requestHeader.value.toLowerCase().includes("mobile");
}
2017-07-08 14:16:27 -07:00
return requestHeader;
});
2017-07-08 14:16:27 -07:00
// 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/'
});
}
}
2019-05-12 14:00:27 -07:00
// override User-Agent to use Googlebot
var useGoogleBot = use_google_bot.filter(function(item) {
return typeof item == 'string' && details.url.indexOf(item) > -1;
}).length > 0;
if (useGoogleBot) {
requestHeaders.push({
"name": "User-Agent",
"value": useUserAgentMobile ? userAgentMobile : userAgentDesktop
})
2019-05-12 14:00:27 -07:00
requestHeaders.push({
"name": "X-Forwarded-For",
"value": "66.249.66.1"
})
}
2017-07-08 14:16:27 -07:00
// 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);
})();
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-06-05 14:46:20 +03:00
}