-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththeme.js
124 lines (115 loc) · 4.25 KB
/
theme.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
let styleSnippetConfig = JSON.parse(
window.localStorage.getItem(
"cc.microblock.betterncm.stylesnippets.snippetsConfig.relive-theme"
) || "{}"
);
window.localStorage.setItem(
"refined-now-playing-refined-control-bar",
styleSnippetConfig["@modify-play-page"] == true ||
styleSnippetConfig["@modify-play-page"] == undefined
? "false"
: "true"
);
plugin.onAllPluginsLoaded(async function (plugins) {
if (!plugins.StyleSnippet?.addExternalSnippet) {
setTimeout(async () => {
(await betterncm.utils.waitForElement("header")).prepend(
dom("div", {
innerText:
"请安装/更新 StyleSnippet 插件,否则 ReLive 主题将不会生效。",
style: {
width: "100%",
height: "30px",
lineHeight: "30px",
background: "#ec414188",
color: "white",
textAlign: "center",
zIndex: 999,
position: "absolute",
pointerEvents: "none",
},
})
);
}, 1000);
return;
}
plugins.StyleSnippet.addExternalSnippet(
await betterncm.fs.readFileText(this.pluginPath + "./theme.less"),
"ReLiveTheme",
"relive-theme"
);
document.addEventListener("fullscreenchange", () => {
if (document.fullscreenElement) document.body.classList.add("fullscreen");
else document.body.classList.remove("fullscreen");
});
// light/dark theme switcher
let isDark = JSON.parse(window.localStorage.getItem("relive-theme-dark") || "false");
function loadDark() {
if (isDark) {
document.body.classList.add("s-theme-white");
document.querySelector("#skin_default").href = undefined;
document.querySelector("#pri-skin-gride").href =
"orpheus://skin/default/default/web/css/skin.ls.css";
} else {
document.body.classList.remove("s-theme-white");
document.querySelector("#skin_default").href =
"../../style/res/less/default/css/skin.ls.css";
document.querySelector("#pri-skin-gride").href =
"orpheus://skin/pub/web/css/skin.ls.css";
}
}
loadDark();
let lastSkinNode;
new MutationObserver(async () => {
let skinNode = document.querySelector(".m-tool > .skin");
if (!skinNode || skinNode == lastSkinNode) return;
lastSkinNode = skinNode;
skinNode.addEventListener("click", (e) => {
isDark = !isDark;
window.localStorage.setItem("relive-theme-dark", JSON.stringify(isDark));
loadDark();
});
}).observe(document.querySelector("html"), {
childList: true,
subtree: true,
});
// fullscreen popup fix
new MutationObserver((mutation) => {
for (const mut of mutation) {
let target = mut.target;
target.childNodes.forEach((node) => {
if (node.tagName == "DIV") {
document.body.appendChild(node);
}
});
}
}).observe(document.querySelector("html"), {
childList: true,
});
// program detector
new MutationObserver((mutation) => {
for (const mut of mutation) {
let target = mut.target;
for (const node of target.children) {
if (node.classList.contains("g-single")) {
document.body.classList.toggle(
"mq-playing-program",
node.childNodes.item(0).classList.contains("g-single-program")
);
}
}
}
}).observe(document.querySelector("body"), {
childList: true,
});
new MutationObserver(async () => {
let fmPlayer = document.querySelector(".m-player.m-player-fm");
document.body.classList.toggle(
"mq-playing-fm",
fmPlayer ? !fmPlayer.classList.contains("f-dn") : false
);
}).observe(document.querySelector("html"), {
childList: true,
subtree: true,
});
});