Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
54 lines (49 loc) · 1.41 KB
/
Copy pathapp.js
File metadata and controls
54 lines (49 loc) · 1.41 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Listen for clicks on the extension icon in the browser toolbar
chrome.action.onClicked.addListener(tab =>
chrome.scripting.executeScript({
target: { tabId: tab.id },
func: toggleDebugger
})
);
// This function is serialized and injected into the page
function toggleDebugger() {
// Color mapping for different HTML elements
const elementStyles = {
// Fallback for every tag without an explicit rule below
"*": "#2A9D8F",
"div": "#457B9D",
"article": "#9B5DE5",
"section": "#00BCD4",
"nav": "#F4A261",
"header": "#FF7043",
"footer": "#4CAF50",
"main": "#7B1FA2",
"aside": "#FF4081",
"form": "#009688",
"ul, ol": "#5C6BC0",
"li": "#FF8A65",
"p": "#66BB6A",
"a": "#FFB74D",
"img": "#4DD0E1",
"button, input, select, textarea": "#EC407A"
};
const styleId = "css-debugger-styles";
// The <style> element itself is the on/off state, so it can never desync
const existing = document.getElementById(styleId);
if (existing) {
existing.remove();
return;
}
const style = document.createElement("style");
style.id = styleId;
style.textContent = Object.entries(elementStyles).map(([selector, color]) => `
${selector} {
outline: 1px solid ${color} !important;
}
${selector}::before,
${selector}::after {
outline: 1px dashed ${color} !important;
}`
).join("\n");
document.head.append(style);
}