-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelement.ts
47 lines (44 loc) · 1.19 KB
/
element.ts
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
import { server } from ".";
import { formatTrack, getCurrentTrack } from "./jxa";
export const overlayListRewriter = new HTMLRewriter().on("#overlay-list", {
async element(element) {
const overlays = ["music?style=basic", "music?style=xp"];
element.setInnerContent(
overlays
.map(
(overlay) =>
`<li><a href="/${overlay}">${overlay
.split(/[\?&]/)
.map((t, i) => (i > 0 ? `(${t.replaceAll("=", ": ")})` : t))
.join(" ")}</a><br /><br /><strong>source url:</strong> <pre>${
server.url
}${overlay}</pre></li>`
)
.join(""),
{ html: true }
);
},
});
export const makeMusicRewriter = (opts?: { pauseOverride?: boolean }) =>
new HTMLRewriter()
.on("#track-info", {
async element(element) {
const trackInfo = formatTrack(await getCurrentTrack(), {
pauseOverride: opts?.pauseOverride,
});
element.setInnerContent(trackInfo, {
html: false,
});
},
})
.on("#track-info-withyear", {
async element(element) {
const trackInfo = formatTrack(await getCurrentTrack(), {
withYear: true,
pauseOverride: opts?.pauseOverride,
});
element.setInnerContent(trackInfo, {
html: false,
});
},
});