From be7b65b7992b6d7281593bef723a37359cbf38de Mon Sep 17 00:00:00 2001 From: MDeeApp <6595194+MDeeApp@users.noreply.github.com> Date: Sun, 5 Oct 2025 20:40:59 +0200 Subject: [PATCH] extension console logs only in debug mode --- extension/content.js | 61 ++++++++++++++++++++++++++++++++++++++++++++ extension/popup.html | 25 +++++++++++++++++- extension/popup.js | 14 ++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) diff --git a/extension/content.js b/extension/content.js index 5c03c60..8126461 100644 --- a/extension/content.js +++ b/extension/content.js @@ -30,6 +30,67 @@ function isOnReelsPage() { } } +let debugLoggingEnabled = false; + +const originalConsoleLog = console.log.bind(console); +const originalConsoleDebug = console.debug ? console.debug.bind(console) : null; +const originalConsoleInfo = console.info ? console.info.bind(console) : null; + +function shouldSuppressTrackerLog(args) { + if (!args || args.length === 0) { + return false; + } + const [first] = args; + if (typeof first === 'string' && first.startsWith('[FB Tracker]')) { + return !debugLoggingEnabled; + } + return false; +} + +console.log = (...args) => { + if (shouldSuppressTrackerLog(args)) { + return; + } + originalConsoleLog(...args); +}; + +if (originalConsoleDebug) { + console.debug = (...args) => { + if (shouldSuppressTrackerLog(args)) { + return; + } + originalConsoleDebug(...args); + }; +} + +if (originalConsoleInfo) { + console.info = (...args) => { + if (shouldSuppressTrackerLog(args)) { + return; + } + originalConsoleInfo(...args); + }; +} + +function applyDebugLoggingPreference(value) { + debugLoggingEnabled = Boolean(value); + if (debugLoggingEnabled) { + originalConsoleLog('[FB Tracker] Debug logging enabled'); + } +} + +chrome.storage.sync.get(['debugLoggingEnabled'], (result) => { + applyDebugLoggingPreference(result && typeof result.debugLoggingEnabled !== 'undefined' + ? result.debugLoggingEnabled + : false); +}); + +chrome.storage.onChanged.addListener((changes, area) => { + if (area === 'sync' && changes && Object.prototype.hasOwnProperty.call(changes, 'debugLoggingEnabled')) { + applyDebugLoggingPreference(changes.debugLoggingEnabled.newValue); + } +}); + function getTrackerElementForPost(postElement) { if (!postElement) { return null; diff --git a/extension/popup.html b/extension/popup.html index f60596e..147efca 100644 --- a/extension/popup.html +++ b/extension/popup.html @@ -29,6 +29,21 @@ color: #050505; } + .toggle-label { + display: flex; + align-items: center; + gap: 8px; + margin-bottom: 8px; + font-weight: 600; + color: #050505; + } + + .toggle-label input { + margin: 0; + width: 18px; + height: 18px; + } + select { width: 100%; padding: 8px; @@ -106,6 +121,14 @@