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) {
|
function getTrackerElementForPost(postElement) {
|
||||||
if (!postElement) {
|
if (!postElement) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -29,6 +29,21 @@
|
|||||||
color: #050505;
|
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 {
|
select {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
@@ -106,6 +121,14 @@
|
|||||||
<div class="info">Wähle das Browser-Profil aus, mit dem du aktuell arbeitest.</div>
|
<div class="info">Wähle das Browser-Profil aus, mit dem du aktuell arbeitest.</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="section">
|
||||||
|
<label class="toggle-label">
|
||||||
|
<input type="checkbox" id="debugLoggingToggle">
|
||||||
|
<span>Debug-Logging aktivieren</span>
|
||||||
|
</label>
|
||||||
|
<div class="info">Schaltet ausführliche Konsolen-Ausgaben im Content Script ein.</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="status" class="status"></div>
|
<div id="status" class="status"></div>
|
||||||
|
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const profileSelect = document.getElementById('profileSelect');
|
const profileSelect = document.getElementById('profileSelect');
|
||||||
const statusEl = document.getElementById('status');
|
const statusEl = document.getElementById('status');
|
||||||
|
const debugToggle = document.getElementById('debugLoggingToggle');
|
||||||
|
|
||||||
function apiFetch(url, options = {}) {
|
function apiFetch(url, options = {}) {
|
||||||
const config = {
|
const config = {
|
||||||
@@ -76,6 +77,19 @@ async function initProfileSelect() {
|
|||||||
|
|
||||||
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() {
|
function reloadFacebookTabs() {
|
||||||
chrome.tabs.query({ url: ['https://www.facebook.com/*', 'https://facebook.com/*'] }, (tabs) => {
|
chrome.tabs.query({ url: ['https://www.facebook.com/*', 'https://facebook.com/*'] }, (tabs) => {
|
||||||
tabs.forEach(tab => {
|
tabs.forEach(tab => {
|
||||||
|
|||||||
Reference in New Issue
Block a user