Skip to content

Commit 107620d

Browse files
authored
Create index.js
1 parent d7c5d75 commit 107620d

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

active/index.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
23+
// Attach form submit event listener
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+
location.href = __uv$config.prefix + __uv$config.encodeUrl(url);
37+
});
38+
39+
// Autofill function with auto-submit
40+
function autofill(url) {
41+
address.value = url;
42+
form.requestSubmit(); // Automatically submit the form
43+
}

0 commit comments

Comments
 (0)