-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (26 loc) · 862 Bytes
/
Copy pathscript.js
File metadata and controls
32 lines (26 loc) · 862 Bytes
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
const html = document.querySelector("html");
const checkbox = document.querySelector("input[name=theme]");
const getStyle = (element, style) =>
window.getComputedStyle(element).getPropertyValue(style);
const initialColors = {
bg: getStyle(html, "--bg"),
bgPanel: getStyle(html, "--bg-panel"),
colorHeadings: getStyle(html, "--color-headings"),
colorText: getStyle(html, "--color-text"),
};
const darkColors = {
bg: "#333333",
bgPanel: "#434343",
colorHeadings: "#3664ff",
colorText: "#b5b5b5",
};
const transformKey = (key) =>
"--" + key.replace(/([A-Z])/g, "-$1").toLowerCase();
const changeColors = (colors) => {
Object.keys(colors).map((key) =>
html.style.setProperty(transformKey(key), colors[key])
);
};
checkbox.addEventListener("change", ({ target }) => {
changeColors(target.checked ? darkColors : initialColors);
});