burlesco/webext/background.js

243 lines
5.5 KiB
JavaScript
Raw Normal View History

// Script blocking
2016-04-24 21:06:35 -07:00
chrome.webRequest.onBeforeRequest.addListener(
function() {
return {cancel: true};
},
{
urls: [
// O Estado de S. Paulo
'*://*.estadao.com.br/paywall/*',
// Folha de S.Paulo
'*://paywall.folha.uol.com.br/*',
'*://static.folha.uol.com.br/paywall/*',
// O Globo
'*://ogjs.infoglobo.com.br/*/js/controla-acesso-aux.js',
// Gazeta do Povo
'*://www.netdeal.com.br/*',
// Correio Popular
'*://correio.rac.com.br/includes/js/novo_cp/fivewall.js*',
// O Estado do Maranhão
'*://dashboard.tinypass.com/xbuilder/experience/load*',
'http://assets.imirante.com/2.0/oestadoma/js/jquery.login.min.js',
// Jornal de Novo Hamburgo
'*://*.jornalnh.com.br/includes/js/paywall.js*',
'*://blockv2.fivewall.com.br/*',
// Diário de Santa Maria
'*://www.rbsonline.com.br/cdn/scripts/SLoader.js',
2017-10-19 08:25:08 -07:00
// New York Times
'*://*.nytimes.com/js/mtr.js',
'*://*.nyt.com/js/mtr.js',
2017-10-19 08:34:47 -07:00
// Washington Post
'*://*.washingtonpost.com/*pwapi/*.js*',
'*://*.washingtonpost.com/*drawbridge/drawbridge.js?_*',
Squashed commit of the following: commit ec8867ad0401096d82a5df0dbc7fe3331442f35a Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 13:45:38 2017 -0200 kissmetrics não é necessario commit 90b869e0c662aa3e84255947556a9a81d0b2eb1c Merge: a109583 517229c Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 13:37:28 2017 -0200 Merge pull request #2 from CaioWzy/master Refatora GauchaZH & remove código reduntante commit 517229c8bdc6ec0c94b1d50a1ddcfb8ebdcb0343 Author: CaioWzy <caiowzy@gmail.com> Date: Tue Oct 31 12:18:16 2017 -0300 Refatora GauchaZH commit a109583918304e03fabe09a7f1c338d7fb6be97c Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 11:42:02 2017 -0200 Update manifest.json commit b853a79480937bcd1c4ef361a236f18687885f86 Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 11:13:24 2017 -0200 Prepara lançamento estavel v5.0 commit a0828abe71ba5efe45954a491e6722e333ddc863 Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 11:09:55 2017 -0200 Formata manifest.json commit 3e68d4acedf076230f1104a3a430ef77696a6c70 Merge: f542a8e 37d6d9b Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 11:08:55 2017 -0200 Merge pull request #1 from AugustoResende/CaioWzy-fix/gauchazh Caio wzy fix/gauchazh commit 37d6d9b1cc6b231f748d6eb03c4da7c31ea7235c Merge: 6b4adb3 f542a8e Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 11:08:41 2017 -0200 Merge branch 'master' into CaioWzy-fix/gauchazh commit 6b4adb351e7f0386d74616a94ff16f177ed6f3ae Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 11:00:26 2017 -0200 Corrige , commit eed1c6f76bcd1086c29ec4720edda5d53a735c4a Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 10:59:33 2017 -0200 Formatando manifest.json commit 403868fcf05f587de18566b74cb628efe7cf5d42 Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 10:59:10 2017 -0200 Removendo métodos desnecessários e formatando código commit db636e79c3d9d2da69654fd6e99d113401dc263a Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 10:46:14 2017 -0200 Formata licença commit 182ac6a038f05d7ae6625fd8c260fb9e259d4ca5 Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 10:44:43 2017 -0200 Atualizando permissões commit 23d17548173c136414813ad08a4548a700e27e40 Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 10:44:19 2017 -0200 Corrigindo metodo de bloqueio commit 6ba5e2d95313b160ce70f8fa6dd26e828d9df921 Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 10:22:57 2017 -0200 Update manifest.json commit 7faaefcb0efcca3b114fbae2ceb6d00b879f49f1 Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 10:22:09 2017 -0200 Update background.js commit 6592492d5146125a00591edaf63ca443d6d4ef51 Author: Rodrigo Orem <orem.rodrigo@gmail.com> Date: Mon Oct 30 20:59:14 2017 -0200 Aumenta versão commit 61738f0defed29aecfb2740bc6fab68d76b0f512 Merge: 3c93bf0 da50cbd Author: Rodrigo Orem <orem.rodrigo@gmail.com> Date: Mon Oct 30 17:51:33 2017 -0200 Merge branch 'fix/gauchazh' of https://github.com/CaioWzy/burlesco into CaioWzy-fix/gauchazh commit da50cbde665f9acf7f4a726c6334505f35e05a53 Author: CaioWzy <caiowzy@gmail.com> Date: Sun Oct 29 20:59:43 2017 -0300 Refatora antipaywall GauchaZH commit 209a7ee1861c1afbe969835d37d03fd7c7b7ec5a Author: CaioWzy <caiowzy@gmail.com> Date: Sun Oct 29 00:04:52 2017 -0300 Atualiza gauchazh
2017-10-31 09:22:42 -07:00
2018-01-16 15:54:33 -08:00
// O Globo, Exame, Super Interessante, Veja, The Economist, Quatro Rodas
'*://cdn.tinypass.com/api/tinypass.min.js',
2017-10-30 14:50:50 -07:00
// UOL
'*://tm.jsuol.com.br/modules/content-gate.js',
2017-11-07 05:45:39 -08:00
// GaúchaZH
2017-12-20 12:10:10 -08:00
'*://gauchazh.clicrbs.com.br/static/main*',
'*://www.rbsonline.com.br/cdn/scripts/special-paywall.min.js*',
2018-03-05 18:30:50 -08:00
'*://www.rbsonline.com.br/cdn/scripts/paywall.min.js*',
// Gramophone
2018-03-06 10:02:31 -08:00
'*://api.tinypass.com/tpl/*',
// Folha de Londrina
'*://www.folhadelondrina.com.br/*/fivewall.js*'
],
types: ['script']
},
['blocking']
2016-04-24 21:06:35 -07:00
);
var WHITELIST = [
'http://paywall.folha.uol.com.br/status.php',
'https://paywall.folha.uol.com.br/status.php'
2017-08-28 17:02:20 -07:00
];
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
2017-08-28 17:02:20 -07:00
if (WHITELIST.indexOf(details.url) !== -1)
return {cancel: false};
else
return {cancel: true};
},
{
urls: [
// Folha de S.Paulo
'*://paywall.folha.uol.com.br/*',
'*://static.folha.uol.com.br/paywall/*',
// Diário Catarinense
'http://dc.clicrbs.com.br/jornal-2015/jsp/paywall.jspx*',
// Jornal de Santa Catarina
'http://jornaldesantacatarina.clicrbs.com.br/jornal/jsp/paywall*'
],
types: ['xmlhttprequest']
},
['blocking']
);
2016-12-20 00:25:30 -08:00
2017-09-23 18:36:15 -07:00
// Cookie blocking
2016-12-20 00:25:30 -08:00
chrome.webRequest.onBeforeRequest.addListener(
function() {
chrome.cookies.remove({
'url': 'http://jota.info/*',
'name': 'articles'
});
},
{
urls: [
// JOTA
'http://jota.info/*'
],
types: ['main_frame']
}
);
2017-03-17 21:17:41 -07:00
2017-10-01 15:10:20 -07:00
chrome.webRequest.onBeforeRequest.addListener(
function() {
2017-10-01 15:10:20 -07:00
removeCookies('https://www.ft.com');
},
{
urls: [
// Financial Times
'*://*.ft.com/*'
]
2017-10-01 15:10:20 -07:00
}
);
chrome.webRequest.onBeforeRequest.addListener(
function() {
removeCookies('https://www.wsj.com');
},
{
urls: [
// The Wall Street Journal
'*://*.wsj.com/*'
]
}
);
2017-10-01 15:10:20 -07:00
function removeCookies(url) {
chrome.cookies.getAll({}, function(cookies) {
cookies.forEach(function(cookie) {
2017-10-01 15:10:20 -07:00
chrome.cookies.remove({
'url': url,
'name': cookie.name
});
});
});
}
2017-09-23 18:36:15 -07:00
chrome.webRequest.onHeadersReceived.addListener(
2017-10-01 15:10:20 -07:00
// Block cookies from being set
2017-09-23 18:36:15 -07:00
function (details) {
details.responseHeaders.forEach(function(responseHeader) {
if (responseHeader.name.toLowerCase() == 'set-cookie') {
2017-09-23 18:36:15 -07:00
responseHeader.value = '';
}
});
return {
responseHeaders: details.responseHeaders
};
},
{
urls: [
// Financial Times
'*://*.ft.com/*',
// The Wall Street Journal
'*://*.wsj.com/'
]
2017-09-23 18:36:15 -07:00
},
2017-10-19 13:25:52 -07:00
['blocking', 'responseHeaders']
2017-09-23 18:36:15 -07:00
);
2017-03-17 21:17:41 -07:00
2017-10-19 13:25:52 -07:00
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
injectHeader('Cookie', '', details.requestHeaders);
return {requestHeaders: details.requestHeaders};
},
{
urls: [
// Jornal Nexo
Squashed commit of the following: commit ec8867ad0401096d82a5df0dbc7fe3331442f35a Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 13:45:38 2017 -0200 kissmetrics não é necessario commit 90b869e0c662aa3e84255947556a9a81d0b2eb1c Merge: a109583 517229c Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 13:37:28 2017 -0200 Merge pull request #2 from CaioWzy/master Refatora GauchaZH & remove código reduntante commit 517229c8bdc6ec0c94b1d50a1ddcfb8ebdcb0343 Author: CaioWzy <caiowzy@gmail.com> Date: Tue Oct 31 12:18:16 2017 -0300 Refatora GauchaZH commit a109583918304e03fabe09a7f1c338d7fb6be97c Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 11:42:02 2017 -0200 Update manifest.json commit b853a79480937bcd1c4ef361a236f18687885f86 Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 11:13:24 2017 -0200 Prepara lançamento estavel v5.0 commit a0828abe71ba5efe45954a491e6722e333ddc863 Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 11:09:55 2017 -0200 Formata manifest.json commit 3e68d4acedf076230f1104a3a430ef77696a6c70 Merge: f542a8e 37d6d9b Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 11:08:55 2017 -0200 Merge pull request #1 from AugustoResende/CaioWzy-fix/gauchazh Caio wzy fix/gauchazh commit 37d6d9b1cc6b231f748d6eb03c4da7c31ea7235c Merge: 6b4adb3 f542a8e Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 11:08:41 2017 -0200 Merge branch 'master' into CaioWzy-fix/gauchazh commit 6b4adb351e7f0386d74616a94ff16f177ed6f3ae Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 11:00:26 2017 -0200 Corrige , commit eed1c6f76bcd1086c29ec4720edda5d53a735c4a Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 10:59:33 2017 -0200 Formatando manifest.json commit 403868fcf05f587de18566b74cb628efe7cf5d42 Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 10:59:10 2017 -0200 Removendo métodos desnecessários e formatando código commit db636e79c3d9d2da69654fd6e99d113401dc263a Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 10:46:14 2017 -0200 Formata licença commit 182ac6a038f05d7ae6625fd8c260fb9e259d4ca5 Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 10:44:43 2017 -0200 Atualizando permissões commit 23d17548173c136414813ad08a4548a700e27e40 Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 10:44:19 2017 -0200 Corrigindo metodo de bloqueio commit 6ba5e2d95313b160ce70f8fa6dd26e828d9df921 Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 10:22:57 2017 -0200 Update manifest.json commit 7faaefcb0efcca3b114fbae2ceb6d00b879f49f1 Author: Augusto Resende <augusto.resende@outlook.com> Date: Tue Oct 31 10:22:09 2017 -0200 Update background.js commit 6592492d5146125a00591edaf63ca443d6d4ef51 Author: Rodrigo Orem <orem.rodrigo@gmail.com> Date: Mon Oct 30 20:59:14 2017 -0200 Aumenta versão commit 61738f0defed29aecfb2740bc6fab68d76b0f512 Merge: 3c93bf0 da50cbd Author: Rodrigo Orem <orem.rodrigo@gmail.com> Date: Mon Oct 30 17:51:33 2017 -0200 Merge branch 'fix/gauchazh' of https://github.com/CaioWzy/burlesco into CaioWzy-fix/gauchazh commit da50cbde665f9acf7f4a726c6334505f35e05a53 Author: CaioWzy <caiowzy@gmail.com> Date: Sun Oct 29 20:59:43 2017 -0300 Refatora antipaywall GauchaZH commit 209a7ee1861c1afbe969835d37d03fd7c7b7ec5a Author: CaioWzy <caiowzy@gmail.com> Date: Sun Oct 29 00:04:52 2017 -0300 Atualiza gauchazh
2017-10-31 09:22:42 -07:00
'*://api.nexojornal.com.br/*'
2017-10-19 14:37:49 -07:00
],
types: ['xmlhttprequest']
2017-10-19 13:25:52 -07:00
},
['blocking', 'requestHeaders']
);
2017-10-01 15:10:20 -07:00
2017-09-23 18:36:15 -07:00
// Referer injection
2017-03-17 21:17:41 -07:00
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
2017-10-19 13:25:52 -07:00
injectHeader(
'Referer',
'https://www.google.com.br/',
details.requestHeaders
);
return {requestHeaders: details.requestHeaders};
},
{
urls: [
// Financial Times
'*://www.ft.com/*'
],
types: ['xmlhttprequest', 'main_frame']
},
['blocking', 'requestHeaders']
2017-03-17 21:17:41 -07:00
);
2017-09-23 18:36:15 -07:00
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
injectHeader(
'Referer',
'https://www.facebook.com/',
details.requestHeaders
);
return {requestHeaders: details.requestHeaders};
},
{
urls: [
// The Wall Street Journal
2018-02-02 19:29:07 -08:00
'*://*.wsj.com/*'
],
types: ['xmlhttprequest', 'main_frame']
},
['blocking', 'requestHeaders']
);
2017-10-19 13:25:52 -07:00
function injectHeader(name, value, requestHeaders) {
2017-09-23 18:36:15 -07:00
/**
* @param {string} name - Name of the header to be inserted
* @param {string} value - Value of the header to be inserted
* @param {Object[]} requestHeaders - Provided by webRequest
* listeners in callback arg `details.requestHeader`
* @param {string} requestHeaders[].name
* @param {string} requestHeaders[].value
*/
2017-10-19 13:25:52 -07:00
var headerIndex = requestHeaders.findIndex(
x => x.name.toLowerCase() == name.toLowerCase());
2017-09-23 18:36:15 -07:00
var newHeader = {name: name, value: value};
if (headerIndex == -1)
requestHeaders.push(newHeader);
else
requestHeaders[headerIndex] = newHeader;
}