From 372f4d97b7c8b6eb38fc75c6b1eab9e5e0b7ea0d Mon Sep 17 00:00:00 2001 From: Oj Date: Fri, 8 Apr 2022 22:35:58 +0100 Subject: [PATCH] [NoTrack] Minor cleanup --- src/noTrack.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/noTrack.js b/src/noTrack.js index 003c1a2..8d7d22b 100644 --- a/src/noTrack.js +++ b/src/noTrack.js @@ -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({}); }); \ No newline at end of file