diff options
Diffstat (limited to 'script.js')
-rw-r--r-- | script.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/script.js b/script.js new file mode 100644 index 0000000..e2c8f36 --- /dev/null +++ b/script.js | |||
@@ -0,0 +1,69 @@ | |||
1 | (() => { | ||
2 | const queryString = window.location.search; | ||
3 | const urlParams = new URLSearchParams(queryString); | ||
4 | |||
5 | const title = urlParams.get("title"); | ||
6 | const streamUrl = urlParams.get("stream"); | ||
7 | const ircUrl = urlParams.get("irc"); | ||
8 | |||
9 | if (streamUrl === null || ircUrl === null) { | ||
10 | return; | ||
11 | } | ||
12 | |||
13 | /** @type HTMLInputElement */ | ||
14 | const titleEl = document.querySelector(".c-form-field__input[name=title]"); | ||
15 | /** @type HTMLInputElement */ | ||
16 | const streamEl = document.querySelector(".c-form-field__input[name=stream]"); | ||
17 | /** @type HTMLInputElement */ | ||
18 | const ircEl = document.querySelector(".c-form-field__input[name=irc]"); | ||
19 | |||
20 | titleEl.value = title; | ||
21 | streamEl.value = streamUrl; | ||
22 | ircEl.value = ircUrl; | ||
23 | |||
24 | if (streamUrl.trim().length === 0 || ircUrl.trim().length === 0) { | ||
25 | return; | ||
26 | } | ||
27 | |||
28 | const normalizedircUrl = ircUrl.startsWith("irc://") | ||
29 | ? ircUrl.substring(6) | ||
30 | : ircUrl.startsWith("ircs://") | ||
31 | ? ircUrl.substring(7) | ||
32 | : ircUrl; | ||
33 | const ircUrlComponents = normalizedircUrl.split("/"); | ||
34 | |||
35 | if (ircUrlComponents.length !== 2) { | ||
36 | return; | ||
37 | } | ||
38 | |||
39 | if (title !== null && title.trim().length !== 0) { | ||
40 | document.querySelector("title").textContent = title; | ||
41 | } | ||
42 | |||
43 | const ircChan = ircUrlComponents[0]; | ||
44 | const ircHost = ircUrlComponents[1]; | ||
45 | |||
46 | document.querySelector(".c-section--create").classList.add("u-hidden"); | ||
47 | document.querySelector(".c-section--main").classList.remove("u-hidden"); | ||
48 | |||
49 | /** @type HTMLIFrameElement */ | ||
50 | const streamFrameEl = document.querySelector(".c-frame--pt iframe"); | ||
51 | /** @type HTMLIFrameElement */ | ||
52 | const ircFrameEl = document.querySelector(".c-frame--irc iframe"); | ||
53 | |||
54 | streamFrameEl.src = streamUrl; | ||
55 | ircFrameEl.src = "https://irc.vulpes.one/?uri=" + ircUrl; | ||
56 | |||
57 | /** @type HTMLAnchorElement */ | ||
58 | const ircLink = document.querySelector(".c-irc-link"); | ||
59 | ircLink.href = ircUrl; | ||
60 | ircLink.textContent = `Join #${ircChan} on ${ircHost}`; | ||
61 | |||
62 | document.querySelector(".c-msg__close").addEventListener("click", (e) => { | ||
63 | e.preventDefault(); | ||
64 | |||
65 | /** @type HTMLElement */ | ||
66 | const el = e.currentTarget; | ||
67 | el.parentElement.remove(); | ||
68 | }); | ||
69 | })(); | ||