[NoTrack] Minor cleanup

This commit is contained in:
Ducko 2022-04-08 22:35:58 +01:00
parent 1f4c10d8b1
commit 372f4d97b7
1 changed files with 6 additions and 9 deletions

View File

@ -1,6 +1,8 @@
const { get } = require('https');
const { session } = require('electron');
const bl = { cancel: true }; // Standard block callback response
let sentry;
session.defaultSession.webRequest.onBeforeRequest({
urls: [
@ -8,23 +10,18 @@ session.defaultSession.webRequest.onBeforeRequest({
'https://*/api/*/science'
]
}, async ({ url }, cb) => {
if (url.endsWith('/science')) return cb({ cancel: true });
if (url.endsWith('/science')) return cb(bl);
if (!sentry) {
const content = await new Promise((res) => get(url, (r) => {
if ((await new Promise((res) => get(url, (r) => { // Get content (js code) from URL
let t = '';
r.on('data', c => t += c.toString());
r.on('end', () => res(t));
}));
if (content.includes('RecipeWebview')) sentry = url;
}))).includes('RecipeWebview')) sentry = url;
}
if (sentry === url) {
log('NoTrack', 'Blocked', url);
return cb({ cancel: true });
}
if (sentry === url) return cb(bl);
cb({});
});