30 lines
886 B
JavaScript
30 lines
886 B
JavaScript
const form = document.querySelector("form");
|
|
const input = document.querySelector("input");
|
|
const error = document.querySelector("#error");
|
|
const errorCode = document.querySelector("#error-code");
|
|
|
|
function isUrl(val = "") {
|
|
if (
|
|
/^http(s?):\/\//.test(val) ||
|
|
(val.includes(".") && val.substr(0, 1) !== " ")
|
|
)
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
form.addEventListener("submit", async (event) => {
|
|
event.preventDefault();
|
|
try {
|
|
await registerSW();
|
|
} catch (err) {
|
|
error.textContent = "Failed to register service worker.";
|
|
errorCode.textContent = err.toString();
|
|
throw err;
|
|
}
|
|
let url = input.value.trim();
|
|
if (!isUrl(url)) url = "https://www.google.com/search?q=" + url;
|
|
else if (!(url.startsWith("https://") || url.startsWith("http://")))
|
|
url = "http://" + url;
|
|
|
|
window.location.href = __uv$config.prefix + __uv$config.encodeUrl(url);
|
|
});
|