-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
49 lines (41 loc) · 1.36 KB
/
content.js
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
/*
Enhanced Twitter
@xilantra
https://arc.net/e/E7D0C27B-9A71-4DEB-B28C-20CF8092C241
https://github.com/Xilantra/enhanced-twitter
Last updated: Jan 10 2023
*/
const menuBtn = document.createElement("button");
const body = document.body;
const bodyClass = body.classList;
// Add is-active by default
bodyClass.add("is-active");
menuBtn.className = "btn-menu";
menuBtn.textContent = "☰";
body.prepend(menuBtn);
const toggleBtn = document.querySelector(".btn-menu");
// Toggle hamburger button
toggleBtn.addEventListener("click", () => {
bodyClass.contains("is-active") ? bodyClass.remove("is-active") : bodyClass.add("is-active");
});
const style = getComputedStyle(body);
// Define CSS variables
document.documentElement.style.setProperty("--bg-dark", "rgb(0, 0, 0)");
document.documentElement.style.setProperty("--bg-dimmed", "rgb(21, 32, 43)");
document.documentElement.style.setProperty("--bg-default", "rgb(255, 255, 255)");
const bgDark = style.getPropertyValue("--bg-dark");
const bgDimmed = style.getPropertyValue("--bg-dimmed");
const bgDefault = style.getPropertyValue("--bg-default");
const backgroundColor = style.backgroundColor;
// Detect theme used
switch (backgroundColor) {
case bgDark:
bodyClass.add("bg-dark");
break;
case bgDimmed:
bodyClass.add("bg-dimmed");
break;
case bgDefault:
bodyClass.add("bg-default");
break;
}