-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangeColor.js
More file actions
78 lines (69 loc) · 2.44 KB
/
changeColor.js
File metadata and controls
78 lines (69 loc) · 2.44 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Utility: Apply transparency to the header once
function makeHeaderTransparent() {
const header = document.querySelector("header");
if (header && header.style.background !== "transparent") {
header.style.background = "transparent";
}
}
// Build and inject a global <style> tag with differentiated glow animations.
// colorIn → received messages (.message-in)
// colorOut → sent messages (.message-out)
// Scoped to the active chat panel so no system UI is affected.
function applyGlowingEffect(colorIn, colorOut) {
const styleContent = `
@keyframes glowIn {
0% { box-shadow: 0 0 5px ${colorIn}, 0 0 10px ${colorIn}; }
100% { box-shadow: 0 0 10px ${colorIn}, 0 0 20px ${colorIn}; }
}
@keyframes glowOut {
0% { box-shadow: 0 0 5px ${colorOut}, 0 0 10px ${colorOut}; }
100% { box-shadow: 0 0 10px ${colorOut}, 0 0 20px ${colorOut}; }
}
div[tabindex='0'][data-tab='8'] .message-in ._amk6,
div[tabindex='0'][data-tab='8'] .message-in ._amk4 {
border: 2px solid transparent;
border-radius: 8px;
animation: glowIn 2s infinite alternate;
}
div[tabindex='0'][data-tab='8'] .message-out ._amk6,
div[tabindex='0'][data-tab='8'] .message-out ._amk4 {
border: 2px solid transparent;
border-radius: 8px;
animation: glowOut 2s infinite alternate;
}
`;
let style = document.getElementById("glowingBorderStyle");
if (!style) {
style = document.createElement("style");
style.id = "glowingBorderStyle";
document.head.appendChild(style);
}
// Only rewrite the tag when the colors actually changed
if (style.innerHTML !== styleContent) {
style.innerHTML = styleContent;
}
}
// Read both color keys and apply. Centralising the read here ensures
// that a change to either key always sees the up-to-date value of the other.
function loadAndApply() {
chrome.storage.local.get(["colorIn", "colorOut"], (result) => {
applyGlowingEffect(
result.colorIn || "#00aaff",
result.colorOut || "#00ff88"
);
});
}
// Initialize on load
function initGlowingFeature() {
makeHeaderTransparent();
// 1️⃣ Apply saved colors immediately
loadAndApply();
// 2️⃣ Re-apply whenever either color is changed from the popup
chrome.storage.onChanged.addListener((changes, areaName) => {
if (areaName === "local" && (changes.colorIn || changes.colorOut)) {
loadAndApply();
}
});
}
// ✅ Run it!
initGlowingFeature();