|
|
@ -1,6 +1,7 @@
|
|
|
|
/* Please respect alphabetical order when adding a site in any list */
|
|
|
|
/* Please respect alphabetical order when adding a site in any list */
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var ext_api = chrome || browser;
|
|
|
|
|
|
|
|
|
|
|
|
// Cookies from this list are blocked by default (obsolete)
|
|
|
|
// Cookies from this list are blocked by default (obsolete)
|
|
|
|
// defaultSites are loaded from sites.js at installation extension
|
|
|
|
// defaultSites are loaded from sites.js at installation extension
|
|
|
@ -184,15 +185,16 @@ const userAgentMobile = "Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible ;
|
|
|
|
var enabledSites = [];
|
|
|
|
var enabledSites = [];
|
|
|
|
|
|
|
|
|
|
|
|
function setDefaultOptions() {
|
|
|
|
function setDefaultOptions() {
|
|
|
|
browser.storage.sync.set({
|
|
|
|
ext_api.storage.sync.set({
|
|
|
|
sites: defaultSites
|
|
|
|
sites: defaultSites
|
|
|
|
}, function() {
|
|
|
|
}, function() {
|
|
|
|
browser.runtime.openOptionsPage();
|
|
|
|
ext_api.runtime.openOptionsPage();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the enabled sites (from local storage) & add to allow/remove_cookies (if not already in one of these arrays)
|
|
|
|
// Get the enabled sites (from local storage) & add to allow/remove_cookies (if not already in one of these arrays)
|
|
|
|
// Add googlebot- and block_javascript-settings for custom sites
|
|
|
|
// Add googlebot- and block_javascript-settings for custom sites
|
|
|
|
browser.storage.sync.get({
|
|
|
|
ext_api.storage.sync.get({
|
|
|
|
sites: {},
|
|
|
|
sites: {},
|
|
|
|
sites_custom: {}
|
|
|
|
sites_custom: {}
|
|
|
|
}, function (items) {
|
|
|
|
}, function (items) {
|
|
|
@ -238,7 +240,7 @@ browser.storage.sync.get({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Listen for changes to options
|
|
|
|
// Listen for changes to options
|
|
|
|
browser.storage.onChanged.addListener(function (changes, namespace) {
|
|
|
|
ext_api.storage.onChanged.addListener(function (changes, namespace) {
|
|
|
|
for (var key in changes) {
|
|
|
|
for (var key in changes) {
|
|
|
|
var storageChange = changes[key];
|
|
|
|
var storageChange = changes[key];
|
|
|
|
if (key === 'sites') {
|
|
|
|
if (key === 'sites') {
|
|
|
@ -283,7 +285,7 @@ browser.storage.onChanged.addListener(function (changes, namespace) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Set and show default options on install
|
|
|
|
// Set and show default options on install
|
|
|
|
browser.runtime.onInstalled.addListener(function (details) {
|
|
|
|
ext_api.runtime.onInstalled.addListener(function (details) {
|
|
|
|
if (details.reason == "install") {
|
|
|
|
if (details.reason == "install") {
|
|
|
|
setDefaultOptions();
|
|
|
|
setDefaultOptions();
|
|
|
|
} else if (details.reason == "update") {
|
|
|
|
} else if (details.reason == "update") {
|
|
|
@ -292,7 +294,7 @@ browser.runtime.onInstalled.addListener(function (details) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// repubblica.it bypass
|
|
|
|
// repubblica.it bypass
|
|
|
|
browser.webRequest.onBeforeRequest.addListener(function (details) {
|
|
|
|
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -307,7 +309,7 @@ var block_js_default = ["*://*.tinypass.com/*", "*://*.poool.fr/*", "*://*.piano
|
|
|
|
var block_js_custom = [];
|
|
|
|
var block_js_custom = [];
|
|
|
|
var block_js = block_js_default.concat(block_js_custom);
|
|
|
|
var block_js = block_js_default.concat(block_js_custom);
|
|
|
|
// Disable javascript for these sites/general paywall-scripts
|
|
|
|
// Disable javascript for these sites/general paywall-scripts
|
|
|
|
browser.webRequest.onBeforeRequest.addListener(function(details) {
|
|
|
|
ext_api.webRequest.onBeforeRequest.addListener(function(details) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -320,9 +322,13 @@ browser.webRequest.onBeforeRequest.addListener(function(details) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
["blocking"]);
|
|
|
|
["blocking"]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var extraInfoSpec = ['blocking', 'requestHeaders'];
|
|
|
|
|
|
|
|
if (ext_api.webRequest.OnBeforeSendHeadersOptions.hasOwnProperty('EXTRA_HEADERS'))
|
|
|
|
|
|
|
|
extraInfoSpec.push('extraHeaders');
|
|
|
|
|
|
|
|
|
|
|
|
// list of regional ad.nl sites
|
|
|
|
// list of regional ad.nl sites
|
|
|
|
const ad_region_domains = ['bd.nl', 'ed.nl', 'tubantia.nl', 'bndestem.nl', 'pzc.nl', 'destentor.nl', 'gelderlander.nl'];
|
|
|
|
const ad_region_domains = ['bd.nl', 'ed.nl', 'tubantia.nl', 'bndestem.nl', 'pzc.nl', 'destentor.nl', 'gelderlander.nl'];
|
|
|
|
browser.webRequest.onBeforeSendHeaders.addListener(function(details) {
|
|
|
|
ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) {
|
|
|
|
var requestHeaders = details.requestHeaders;
|
|
|
|
var requestHeaders = details.requestHeaders;
|
|
|
|
|
|
|
|
|
|
|
|
var header_referer = '';
|
|
|
|
var header_referer = '';
|
|
|
@ -336,9 +342,9 @@ browser.webRequest.onBeforeSendHeaders.addListener(function(details) {
|
|
|
|
// remove cookies for sites medium platform (mainfest.json needs in permissions: <all_urls>)
|
|
|
|
// remove cookies for sites medium platform (mainfest.json needs in permissions: <all_urls>)
|
|
|
|
if (isSiteEnabled({url: '.medium.com'}) && details.url.indexOf('cdn-client.medium.com') !== -1 && header_referer.indexOf('.medium.com') === -1) {
|
|
|
|
if (isSiteEnabled({url: '.medium.com'}) && details.url.indexOf('cdn-client.medium.com') !== -1 && header_referer.indexOf('.medium.com') === -1) {
|
|
|
|
var domainVar = new URL(header_referer).hostname;
|
|
|
|
var domainVar = new URL(header_referer).hostname;
|
|
|
|
browser.cookies.getAll({domain: domainVar}, function(cookies) {
|
|
|
|
ext_api.cookies.getAll({domain: domainVar}, function(cookies) {
|
|
|
|
for (var i=0; i<cookies.length; i++) {
|
|
|
|
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});
|
|
|
|
ext_api.cookies.remove({url: (cookies[i].secure ? "https://" : "http://") + cookies[i].domain + cookies[i].path, name: cookies[i].name});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -347,10 +353,10 @@ browser.webRequest.onBeforeSendHeaders.addListener(function(details) {
|
|
|
|
if (isSiteEnabled({url: '.ad.nl'})) {
|
|
|
|
if (isSiteEnabled({url: '.ad.nl'})) {
|
|
|
|
var domainVar = new URL(details.url).hostname.replace('www.', '');
|
|
|
|
var domainVar = new URL(details.url).hostname.replace('www.', '');
|
|
|
|
if (ad_region_domains.includes(domainVar)) {
|
|
|
|
if (ad_region_domains.includes(domainVar)) {
|
|
|
|
browser.cookies.getAll({domain: domainVar}, function(cookies) {
|
|
|
|
ext_api.cookies.getAll({domain: domainVar}, function(cookies) {
|
|
|
|
for (var i=0; i<cookies.length; i++) {
|
|
|
|
for (var i=0; i<cookies.length; i++) {
|
|
|
|
if (remove_cookies_select_drop['ad.nl'].includes(cookies[i].name)){
|
|
|
|
if (remove_cookies_select_drop['ad.nl'].includes(cookies[i].name)){
|
|
|
|
browser.cookies.remove({url: (cookies[i].secure ? "https://" : "http://") + cookies[i].domain + cookies[i].path, name: cookies[i].name});
|
|
|
|
ext_api.cookies.remove({url: (cookies[i].secure ? "https://" : "http://") + cookies[i].domain + cookies[i].path, name: cookies[i].name});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -364,10 +370,10 @@ browser.webRequest.onBeforeSendHeaders.addListener(function(details) {
|
|
|
|
// allow BG paywall-script to set cookies in homepage/sections (else no article-text)
|
|
|
|
// allow BG paywall-script to set cookies in homepage/sections (else no article-text)
|
|
|
|
if (details.url.indexOf('meter.bostonglobe.com/js/') !== -1 && (header_referer === 'https://www.bostonglobe.com/'
|
|
|
|
if (details.url.indexOf('meter.bostonglobe.com/js/') !== -1 && (header_referer === 'https://www.bostonglobe.com/'
|
|
|
|
|| header_referer.indexOf('/?p1=BGHeader_') !== -1 || header_referer.indexOf('/?p1=BGMenu_') !== -1)) {
|
|
|
|
|| header_referer.indexOf('/?p1=BGHeader_') !== -1 || header_referer.indexOf('/?p1=BGMenu_') !== -1)) {
|
|
|
|
browser.webRequest.handlerBehaviorChanged(function () {});
|
|
|
|
ext_api.webRequest.handlerBehaviorChanged(function () {});
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
} else if (header_referer.indexOf('theglobeandmail.com') !== -1 && !(header_referer.indexOf('/article-') !== -1)) {
|
|
|
|
} else if (header_referer.indexOf('theglobeandmail.com') !== -1 && !(header_referer.indexOf('/article-') !== -1)) {
|
|
|
|
browser.webRequest.handlerBehaviorChanged(function () {});
|
|
|
|
ext_api.webRequest.handlerBehaviorChanged(function () {});
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return { cancel: true };
|
|
|
|
return { cancel: true };
|
|
|
@ -451,11 +457,11 @@ browser.webRequest.onBeforeSendHeaders.addListener(function(details) {
|
|
|
|
|
|
|
|
|
|
|
|
if (tabId !== -1) {
|
|
|
|
if (tabId !== -1) {
|
|
|
|
// run contentScript inside tab
|
|
|
|
// run contentScript inside tab
|
|
|
|
browser.tabs.executeScript(tabId, {
|
|
|
|
ext_api.tabs.executeScript(tabId, {
|
|
|
|
file: 'contentScript.js',
|
|
|
|
file: 'contentScript.js',
|
|
|
|
runAt: 'document_start'
|
|
|
|
runAt: 'document_start'
|
|
|
|
}, function(res) {
|
|
|
|
}, function(res) {
|
|
|
|
if (browser.runtime.lastError || res[0]) {
|
|
|
|
if (ext_api.runtime.lastError || res[0]) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -464,13 +470,14 @@ browser.webRequest.onBeforeSendHeaders.addListener(function(details) {
|
|
|
|
return { requestHeaders: requestHeaders };
|
|
|
|
return { requestHeaders: requestHeaders };
|
|
|
|
}, {
|
|
|
|
}, {
|
|
|
|
urls: ['<all_urls>']
|
|
|
|
urls: ['<all_urls>']
|
|
|
|
}, ['blocking', 'requestHeaders']);
|
|
|
|
}, extraInfoSpec);
|
|
|
|
|
|
|
|
// extraInfoSpec is ['blocking', 'requestHeaders'] + possible 'extraHeaders'
|
|
|
|
|
|
|
|
|
|
|
|
browser.tabs.onUpdated.addListener(updateBadge);
|
|
|
|
ext_api.tabs.onUpdated.addListener(updateBadge);
|
|
|
|
browser.tabs.onActivated.addListener(updateBadge);
|
|
|
|
ext_api.tabs.onActivated.addListener(updateBadge);
|
|
|
|
|
|
|
|
|
|
|
|
function updateBadge() {
|
|
|
|
function updateBadge() {
|
|
|
|
browser.tabs.query({
|
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
currentWindow: true
|
|
|
|
}, function (arrayOfTabs) {
|
|
|
|
}, function (arrayOfTabs) {
|
|
|
@ -478,8 +485,8 @@ function updateBadge() {
|
|
|
|
if (!activeTab)
|
|
|
|
if (!activeTab)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
var textB = getTextB(activeTab.url);
|
|
|
|
var textB = getTextB(activeTab.url);
|
|
|
|
browser.browserAction.setBadgeBackgroundColor({color: "red"});
|
|
|
|
ext_api.browserAction.setBadgeBackgroundColor({color: "red"});
|
|
|
|
browser.browserAction.setBadgeText({text: textB});
|
|
|
|
ext_api.browserAction.setBadgeText({text: textB});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -494,23 +501,16 @@ function getTextB(currentUrl) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// remove cookies after page load
|
|
|
|
// remove cookies after page load
|
|
|
|
browser.webRequest.onCompleted.addListener(function(details) {
|
|
|
|
ext_api.webRequest.onCompleted.addListener(function (details) {
|
|
|
|
for (var domainIndex in remove_cookies) {
|
|
|
|
for (var domainIndex in remove_cookies) {
|
|
|
|
var domainVar = remove_cookies[domainIndex];
|
|
|
|
var domainVar = remove_cookies[domainIndex];
|
|
|
|
if (!enabledSites.includes(domainVar) || details.url.indexOf(domainVar) === -1) {
|
|
|
|
if (!enabledSites.includes(domainVar) || details.url.indexOf(domainVar) === -1) {
|
|
|
|
continue; // don't remove cookies
|
|
|
|
continue; // don't remove cookies
|
|
|
|
}
|
|
|
|
}
|
|
|
|
browser.cookies.getAll({domain: domainVar}, function(cookies) {
|
|
|
|
ext_api.cookies.getAll({
|
|
|
|
|
|
|
|
domain: domainVar
|
|
|
|
|
|
|
|
}, function (cookies) {
|
|
|
|
for (var i = 0; i < cookies.length; i++) {
|
|
|
|
for (var i = 0; i < cookies.length; i++) {
|
|
|
|
var cookie = {
|
|
|
|
|
|
|
|
url: (cookies[i].secure ? "https://" : "http://") + cookies[i].domain + cookies[i].path,
|
|
|
|
|
|
|
|
name: cookies[i].name,
|
|
|
|
|
|
|
|
storeId: cookies[i].storeId
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if (cookies[i].firstPartyDomain !== undefined) {
|
|
|
|
|
|
|
|
cookie.firstPartyDomain = cookies[i].firstPartyDomain;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var cookie_domain = cookies[i].domain;
|
|
|
|
var cookie_domain = cookies[i].domain;
|
|
|
|
var rc_domain = cookie_domain.replace(/^(\.?www\.|\.)/, '');
|
|
|
|
var rc_domain = cookie_domain.replace(/^(\.?www\.|\.)/, '');
|
|
|
|
// hold specific cookie(s) from remove_cookies domains
|
|
|
|
// hold specific cookie(s) from remove_cookies domains
|
|
|
@ -521,7 +521,10 @@ browser.webRequest.onCompleted.addListener(function(details) {
|
|
|
|
if ((rc_domain in remove_cookies_select_drop) && !(remove_cookies_select_drop[rc_domain].includes(cookies[i].name))) {
|
|
|
|
if ((rc_domain in remove_cookies_select_drop) && !(remove_cookies_select_drop[rc_domain].includes(cookies[i].name))) {
|
|
|
|
continue; // only remove specific cookie
|
|
|
|
continue; // only remove specific cookie
|
|
|
|
}
|
|
|
|
}
|
|
|
|
browser.cookies.remove(cookie);
|
|
|
|
ext_api.cookies.remove({
|
|
|
|
|
|
|
|
url: (cookies[i].secure ? "https://" : "http://") + cookies[i].domain + cookies[i].path,
|
|
|
|
|
|
|
|
name: cookies[i].name
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|