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 @@
Wähle das Browser-Profil aus, mit dem du aktuell arbeitest.
+
+ +
Schaltet ausführliche Konsolen-Ausgaben im Content Script ein.
+
+
@@ -116,4 +139,4 @@ - \ No newline at end of file + diff --git a/extension/popup.js b/extension/popup.js index 7c7d109..ea186cc 100644 --- a/extension/popup.js +++ b/extension/popup.js @@ -1,5 +1,6 @@ const profileSelect = document.getElementById('profileSelect'); const statusEl = document.getElementById('status'); +const debugToggle = document.getElementById('debugLoggingToggle'); function apiFetch(url, options = {}) { const config = { @@ -76,6 +77,19 @@ async function initProfileSelect() { initProfileSelect(); +chrome.storage.sync.get(['debugLoggingEnabled'], (result) => { + const enabled = Boolean(result && result.debugLoggingEnabled); + debugToggle.checked = enabled; +}); + +debugToggle.addEventListener('change', () => { + const enabled = debugToggle.checked; + chrome.storage.sync.set({ debugLoggingEnabled: enabled }, () => { + updateStatus(`Debug-Logging ${enabled ? 'aktiviert' : 'deaktiviert'}`, true); + reloadFacebookTabs(); + }); +}); + function reloadFacebookTabs() { chrome.tabs.query({ url: ['https://www.facebook.com/*', 'https://facebook.com/*'] }, (tabs) => { tabs.forEach(tab => {