From 61d37c1ed5818e7f5d53f358495e5349ae817702 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 10 Mar 2021 19:27:04 +0100 Subject: Init --- script.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 script.js (limited to 'script.js') diff --git a/script.js b/script.js new file mode 100644 index 0000000..e2c8f36 --- /dev/null +++ b/script.js @@ -0,0 +1,69 @@ +(() => { + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + + const title = urlParams.get("title"); + const streamUrl = urlParams.get("stream"); + const ircUrl = urlParams.get("irc"); + + if (streamUrl === null || ircUrl === null) { + return; + } + + /** @type HTMLInputElement */ + const titleEl = document.querySelector(".c-form-field__input[name=title]"); + /** @type HTMLInputElement */ + const streamEl = document.querySelector(".c-form-field__input[name=stream]"); + /** @type HTMLInputElement */ + const ircEl = document.querySelector(".c-form-field__input[name=irc]"); + + titleEl.value = title; + streamEl.value = streamUrl; + ircEl.value = ircUrl; + + if (streamUrl.trim().length === 0 || ircUrl.trim().length === 0) { + return; + } + + const normalizedircUrl = ircUrl.startsWith("irc://") + ? ircUrl.substring(6) + : ircUrl.startsWith("ircs://") + ? ircUrl.substring(7) + : ircUrl; + const ircUrlComponents = normalizedircUrl.split("/"); + + if (ircUrlComponents.length !== 2) { + return; + } + + if (title !== null && title.trim().length !== 0) { + document.querySelector("title").textContent = title; + } + + const ircChan = ircUrlComponents[0]; + const ircHost = ircUrlComponents[1]; + + document.querySelector(".c-section--create").classList.add("u-hidden"); + document.querySelector(".c-section--main").classList.remove("u-hidden"); + + /** @type HTMLIFrameElement */ + const streamFrameEl = document.querySelector(".c-frame--pt iframe"); + /** @type HTMLIFrameElement */ + const ircFrameEl = document.querySelector(".c-frame--irc iframe"); + + streamFrameEl.src = streamUrl; + ircFrameEl.src = "https://irc.vulpes.one/?uri=" + ircUrl; + + /** @type HTMLAnchorElement */ + const ircLink = document.querySelector(".c-irc-link"); + ircLink.href = ircUrl; + ircLink.textContent = `Join #${ircChan} on ${ircHost}`; + + document.querySelector(".c-msg__close").addEventListener("click", (e) => { + e.preventDefault(); + + /** @type HTMLElement */ + const el = e.currentTarget; + el.parentElement.remove(); + }); +})(); -- cgit v1.3.1