-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
40 lines (37 loc) · 1.26 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const form = document.forms[0];
form.submitButton.disabled = true;
form.addEventListener("submit", event => {
event.preventDefault();
const spec = new URL(form.spec.value);
const version = new URL(form.version.value);
const respecConfig = form.respecConfig.value;
const searchParams = new URLSearchParams(spec.searchParams);
searchParams.set("spec", spec.href.replace(spec.search, ""));
searchParams.set("version", version.href);
if (respecConfig) searchParams.set("respecConfig", respecConfig);
window.location.search = searchParams.toString();
});
// prefill form
const { searchParams } = new URL(window.location.href);
const version = searchParams.get("version");
const spec = searchParams.get("spec");
const respecConfig = searchParams.get("respecConfig");
if (spec) {
searchParams.delete("version");
searchParams.delete("spec");
searchParams.delete("respecConfig");
form.spec.value = spec + searchParams.toString();
}
if (version) {
form.version.value = version;
}
if (respecConfig) {
form.respecConfig.value = respecConfig;
}
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("sw.js").then(() => {
form.submitButton.disabled = false;
});
} else {
form.append("Error: ServiceWorker must be available for this app to work.");
}