aboutsummaryrefslogtreecommitdiff
path: root/web/script/playerconf-copy-url.js
blob: 49f27fdf7eab2a124d8f9e84811744d4c1e3eba3 (plain)
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
globalThis.addEventListener("load", () => {
    for (const e of document.getElementsByClassName("playerconf"))
        patch_playerconf(e)
})

function patch_playerconf(form) {
    const submit = form.lastChild

    const copyurl = document.createElement("button")
    const d = document.createElement("div")
    form.removeChild(submit)
    d.appendChild(submit)
    d.appendChild(copyurl)
    form.append(d)

    copyurl.textContent = "Copy Stream URL"
    d.style.gridArea = "b"
    d.style.width = "100%"
    copyurl.style.width = "5em"

    copyurl.addEventListener("click", ev => {
        const session = document.cookie.split(";").map(e => e.trim().split("=")).find(e => e[0] == "session")[1]
        ev.preventDefault()
        const fd = new FormData(form)
        const sp = ["v", "a", "s"].map(k => fd.get(k)).filter(k => k != "").flat()
        const url = `${window.location.protocol}//${window.location.host}/n/${window.location.pathname.split("/")[2]}/stream?tracks=${sp}&session=${session}`
        navigator.clipboard.writeText(url)
        copyurl.textContent = "Copied"
        setTimeout(() => copyurl.textContent = "Copy Stream URL", 1000)
    })
}