From 3fa55dba1b0ca408a10e7456a6d4308dd114c2f6 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 1 Oct 2023 10:14:20 +0200 Subject: move stylesheets and refactor js bundler --- web/script/playerconf-copy-url.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 web/script/playerconf-copy-url.js (limited to 'web/script/playerconf-copy-url.js') diff --git a/web/script/playerconf-copy-url.js b/web/script/playerconf-copy-url.js new file mode 100644 index 0000000..49f27fd --- /dev/null +++ b/web/script/playerconf-copy-url.js @@ -0,0 +1,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) + }) +} -- cgit v1.2.3-70-g09d2