Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Ultraviolet-App
Path: blob/main/public/index.js
120 views
1
"use strict";
2
/**
3
* @type {HTMLFormElement}
4
*/
5
const form = document.getElementById("uv-form");
6
/**
7
* @type {HTMLInputElement}
8
*/
9
const address = document.getElementById("uv-address");
10
/**
11
* @type {HTMLInputElement}
12
*/
13
const searchEngine = document.getElementById("uv-search-engine");
14
/**
15
* @type {HTMLParagraphElement}
16
*/
17
const error = document.getElementById("uv-error");
18
/**
19
* @type {HTMLPreElement}
20
*/
21
const errorCode = document.getElementById("uv-error-code");
22
const connection = new BareMux.BareMuxConnection("/baremux/worker.js");
23
24
form.addEventListener("submit", async (event) => {
25
event.preventDefault();
26
27
try {
28
await registerSW();
29
} catch (err) {
30
error.textContent = "Failed to register service worker.";
31
errorCode.textContent = err.toString();
32
throw err;
33
}
34
35
const url = search(address.value, searchEngine.value);
36
37
let frame = document.getElementById("uv-frame");
38
frame.style.display = "block";
39
let wispUrl =
40
(location.protocol === "https:" ? "wss" : "ws") +
41
"://" +
42
location.host +
43
"/wisp/";
44
if ((await connection.getTransport()) !== "/epoxy/index.mjs") {
45
await connection.setTransport("/epoxy/index.mjs", [
46
{ wisp: wispUrl },
47
]);
48
}
49
frame.src = __uv$config.prefix + __uv$config.encodeUrl(url);
50
});
51
52