extension console logs only in debug mode

This commit is contained in:
MDeeApp
2025-10-05 20:40:59 +02:00
parent 19ea180390
commit be7b65b799
3 changed files with 99 additions and 1 deletions

View File

@@ -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;