-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.js
More file actions
37 lines (32 loc) · 1.07 KB
/
Copy pathdebug.js
File metadata and controls
37 lines (32 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const logEl = document.getElementById("log");
const statusEl = document.getElementById("status");
const statusTextEl = document.getElementById("statusText");
function render(debugLog) {
logEl.innerHTML = debugLog
.map((entry) => {
const time = new Date(entry.ts).toLocaleTimeString();
return `<div class="entry"><span class="ts">${time}</span> ${entry.msg}</div>`;
})
.join("");
logEl.scrollTop = logEl.scrollHeight;
}
function renderStatus(enabled) {
statusEl.classList.toggle("on", enabled);
statusTextEl.textContent = enabled ? "fix enabled" : "fix disabled";
}
chrome.storage.local.get({ debugLog: [], enabled: true }, ({ debugLog, enabled }) => {
render(debugLog);
renderStatus(enabled);
});
chrome.storage.onChanged.addListener((changes, area) => {
if (area !== "local") return;
if (changes.debugLog) {
render(changes.debugLog.newValue || []);
}
if (changes.enabled) {
renderStatus(changes.enabled.newValue);
}
});
document.getElementById("clear").addEventListener("click", () => {
chrome.storage.local.set({ debugLog: [] });
});