extension console logs only in debug mode
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user