2017-07-08 19:40:29 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var defaultSites = {
|
|
|
|
'The Age': 'theage.com.au',
|
|
|
|
'Baltimore Sun': 'baltimoresun.com',
|
2017-09-15 07:17:10 +02:00
|
|
|
'Barron\'s': 'barrons.com',
|
2018-05-06 02:53:07 +02:00
|
|
|
'Bloomberg': 'bloomberg.com',
|
2018-07-08 00:11:09 +02:00
|
|
|
'Business Insider': 'businessinsider.com',
|
2018-07-16 06:43:40 +02:00
|
|
|
'Caixin': 'caixinglobal.com',
|
2017-07-08 19:40:29 +02:00
|
|
|
'Crain\'s Chicago Business': 'chicagobusiness.com',
|
|
|
|
'Chicago Tribune': 'chicagotribune.com',
|
2018-04-06 08:22:58 +02:00
|
|
|
'Corriere Della Sera': 'corriere.it',
|
2017-07-08 19:40:29 +02:00
|
|
|
'Daily Press': 'dailypress.com',
|
2018-04-06 08:22:58 +02:00
|
|
|
'Dagens Nyheter': 'dn.se',
|
2018-07-05 03:46:28 +02:00
|
|
|
'Denver Post': 'denverpost.com',
|
2017-07-08 19:40:29 +02:00
|
|
|
'The Economist': 'economist.com',
|
2018-10-02 03:52:35 +02:00
|
|
|
'Examiner': 'examiner.com.au',
|
2017-07-08 19:40:29 +02:00
|
|
|
'Financial Times': 'ft.com',
|
|
|
|
'Glassdoor': 'glassdoor.com',
|
2017-09-15 07:17:10 +02:00
|
|
|
'Haaretz': 'haaretz.co.il',
|
2018-04-23 11:20:40 +02:00
|
|
|
'Haaretz English': 'haaretz.com',
|
2018-07-05 03:46:28 +02:00
|
|
|
'Hacked': 'hacked.com',
|
2017-07-08 19:40:29 +02:00
|
|
|
'Hartford Courant': 'courant.com',
|
|
|
|
'Harvard Business Review': 'hbr.org',
|
2017-09-15 07:17:10 +02:00
|
|
|
'Het Financieele Dagblad': 'fd.nl',
|
2017-07-08 19:40:29 +02:00
|
|
|
'Inc.com': 'inc.com',
|
2017-09-15 07:17:10 +02:00
|
|
|
'Le Temps': 'letemps.ch',
|
2017-07-08 19:40:29 +02:00
|
|
|
'Los Angeles Times': 'latimes.com',
|
2018-01-31 06:08:11 +01:00
|
|
|
'Medium': 'medium.com',
|
2017-07-08 19:40:29 +02:00
|
|
|
'Medscape': 'medscape.com',
|
|
|
|
'MIT Technology Review': 'technologyreview.com',
|
2018-07-23 03:55:35 +02:00
|
|
|
'New Statesman': 'newstatesman.com',
|
2017-07-08 19:40:29 +02:00
|
|
|
'Nikkei Asian Review': 'asia.nikkei.com',
|
|
|
|
'NRC': 'nrc.nl',
|
2018-10-02 03:52:35 +02:00
|
|
|
'The Advocate': 'theadvocate.com.au',
|
2018-01-31 06:08:11 +01:00
|
|
|
'The Boston Globe': 'bostonglobe.com',
|
2018-06-30 21:48:40 +02:00
|
|
|
'The Business Journals': 'bizjournals.com',
|
2018-06-23 04:58:07 +02:00
|
|
|
'The Globe and Mail': 'theglobeandmail.com',
|
2018-09-09 22:21:36 +02:00
|
|
|
'The Japan Times': 'japantimes.co.jp',
|
2018-01-31 06:08:11 +01:00
|
|
|
'The Mercury News': 'mercurynews.com',
|
2017-07-08 19:40:29 +02:00
|
|
|
'The Morning Call': 'mcall.com',
|
|
|
|
'The Nation': 'thenation.com',
|
|
|
|
'The New York Times': 'nytimes.com',
|
|
|
|
'The New Yorker': 'newyorker.com',
|
2018-07-23 04:04:27 +02:00
|
|
|
'The Spectator': 'spectator.co.uk',
|
2018-07-16 06:43:40 +02:00
|
|
|
'Orange County Register': 'ocregister.com',
|
2017-07-08 19:40:29 +02:00
|
|
|
'OrlandoSentinel': 'orlandosentinel.com',
|
|
|
|
'Quora': 'quora.com',
|
|
|
|
'SunSentinel': 'sun-sentinel.com',
|
2018-05-21 04:54:34 +02:00
|
|
|
'TheMarker': 'themarker.com',
|
2017-07-08 19:40:29 +02:00
|
|
|
'The Seattle Times': 'seattletimes.com',
|
|
|
|
'The Sydney Morning Herald': 'smh.com.au',
|
2018-08-29 01:15:23 +02:00
|
|
|
'The Toronto Star': 'thestar.com',
|
2017-07-08 19:40:29 +02:00
|
|
|
'The Washington Post': 'washingtonpost.com',
|
2018-06-03 20:23:04 +02:00
|
|
|
'The Wall Street Journal': 'wsj.com',
|
2018-07-23 04:22:07 +02:00
|
|
|
'Towards Data Science': 'towardsdatascience.com',
|
2018-06-23 04:58:07 +02:00
|
|
|
'Vanity Fair': 'vanityfair.com',
|
2018-10-02 03:52:35 +02:00
|
|
|
'Wired': 'wired.com'
|
2017-07-08 19:40:29 +02:00
|
|
|
};
|
|
|
|
|
2018-01-31 06:08:11 +01:00
|
|
|
const restrictions = {
|
2017-07-08 19:40:29 +02:00
|
|
|
'barrons.com': 'barrons.com/articles'
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't remove cookies before page load
|
2018-01-31 06:08:11 +01:00
|
|
|
const allow_cookies = [
|
2017-07-08 19:40:29 +02:00
|
|
|
'asia.nikkei.com',
|
|
|
|
'nytimes.com',
|
|
|
|
'wsj.com',
|
2017-09-15 07:17:10 +02:00
|
|
|
'ft.com',
|
|
|
|
'letemps.ch',
|
2018-01-31 06:08:11 +01:00
|
|
|
'fd.nl',
|
2018-04-06 08:22:58 +02:00
|
|
|
'mercurynews.com',
|
2018-04-07 20:02:08 +02:00
|
|
|
'theage.com.au',
|
2018-05-13 02:14:07 +02:00
|
|
|
'economist.com',
|
2018-06-28 03:05:25 +02:00
|
|
|
'bostonglobe.com',
|
2018-07-05 03:46:28 +02:00
|
|
|
'denverpost.com',
|
2018-07-16 06:43:40 +02:00
|
|
|
'hacked.com',
|
2018-07-23 03:55:35 +02:00
|
|
|
'ocregister.com',
|
2018-07-23 04:04:27 +02:00
|
|
|
'newstatesman.com',
|
2018-07-23 04:22:07 +02:00
|
|
|
'spectator.co.uk',
|
|
|
|
'towardsdatascience.com',
|
2018-09-28 16:39:45 +02:00
|
|
|
'medium.com',
|
|
|
|
'theadvocate.com.au',
|
|
|
|
'examiner.com.au'
|
2017-07-08 19:40:29 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
// Removes cookies after page load
|
2018-01-31 06:08:11 +01:00
|
|
|
const remove_cookies = [
|
2017-07-08 19:40:29 +02:00
|
|
|
'asia.nikkei.com',
|
2017-09-15 07:17:10 +02:00
|
|
|
'ft.com',
|
|
|
|
'letemps.ch',
|
2018-01-31 06:08:11 +01:00
|
|
|
'fd.nl',
|
2018-04-06 08:22:58 +02:00
|
|
|
'mercurynews.com',
|
2018-04-07 20:02:08 +02:00
|
|
|
'theage.com.au',
|
2018-05-13 02:14:07 +02:00
|
|
|
'economist.com',
|
2018-06-28 03:05:25 +02:00
|
|
|
'bostonglobe.com',
|
2018-07-05 03:46:28 +02:00
|
|
|
'denverpost.com',
|
2018-07-16 06:43:40 +02:00
|
|
|
'hacked.com',
|
2018-07-23 03:55:35 +02:00
|
|
|
'ocregister.com',
|
2018-07-23 04:04:27 +02:00
|
|
|
'newstatesman.com',
|
2018-07-23 04:22:07 +02:00
|
|
|
'spectator.co.uk',
|
|
|
|
'towardsdatascience.com',
|
2018-09-28 16:39:45 +02:00
|
|
|
'medium.com',
|
|
|
|
'theadvocate.com.au',
|
|
|
|
'examiner.com.au'
|
2017-07-08 19:40:29 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
function setDefaultOptions() {
|
|
|
|
browser.storage.sync.set({
|
|
|
|
sites: defaultSites
|
|
|
|
}, function() {
|
|
|
|
browser.runtime.openOptionsPage();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-31 06:08:11 +01:00
|
|
|
const blockedRegexes = [
|
2017-07-08 19:40:29 +02:00
|
|
|
/.+:\/\/.+\.tribdss\.com\//,
|
|
|
|
/thenation\.com\/.+\/paywall-script\.php/
|
|
|
|
];
|
|
|
|
|
|
|
|
var enabledSites = [];
|
|
|
|
|
|
|
|
// Get the enabled sites
|
|
|
|
browser.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
|
|
|
|
browser.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
|
|
|
|
browser.runtime.onInstalled.addListener(function (details) {
|
|
|
|
if (details.reason == "install") {
|
|
|
|
setDefaultOptions();
|
|
|
|
} else if (details.reason == "update") {
|
|
|
|
// User updated extension
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
browser.webRequest.onBeforeSendHeaders.addListener(function(details) {
|
|
|
|
if (blockedRegexes.some(function(regex) { return regex.test(details.url); })) {
|
|
|
|
return { cancel: true };
|
|
|
|
}
|
|
|
|
|
|
|
|
var isEnabled = enabledSites.some(function(enabledSite) {
|
|
|
|
|
2018-05-11 05:36:28 +02:00
|
|
|
var useSite = details.url.indexOf("." + enabledSite) !== -1;
|
2017-07-08 19:40:29 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
browser.tabs.executeScript(tabId, {
|
|
|
|
file: 'contentScript.js',
|
|
|
|
runAt: 'document_start'
|
|
|
|
}, function(res) {
|
|
|
|
if (browser.runtime.lastError || res[0]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return { requestHeaders: requestHeaders };
|
|
|
|
}, {
|
|
|
|
urls: ['<all_urls>']
|
|
|
|
}, ['blocking', 'requestHeaders']);
|
|
|
|
|
|
|
|
// remove cookies after page load
|
|
|
|
browser.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
|
|
|
|
}
|
|
|
|
browser.cookies.getAll({domain: domainVar}, function(cookies) {
|
|
|
|
for (var i=0; i<cookies.length; i++) {
|
|
|
|
browser.cookies.remove({url: cookies[i].secure ? "https://" : "http://" + cookies[i].domain + cookies[i].path, name: cookies[i].name});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
urls: ["<all_urls>"]
|
2018-08-29 01:15:23 +02:00
|
|
|
});
|