-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
78 lines (78 loc) · 3.46 KB
/
index.html
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!doctype html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="icon" href="icon.svg">
<title>Nix cache view</title>
<style>
body {
margin: 1.5rem;
font-family: sans-serif;
}
.wide {
box-sizing: border-box;
width: 100%;
max-width: 30rem;
}
</style>
<p id="presets_container" hidden>
<label>Presets</label><br>
<select id="presets">
<option></option>
<option value="https://cache.nixos.org" selected data-sample-hash="b9iwk28nd0h9z8gpyr3fcr1xjlwnavmc">cache.nixos.org</option>
<option value="https://tmpnix-gsdrv.glitch.me/release/drvs" data-cache-base-out="https://cdn.glitch.me/35f4f809-f949-484d-af9c-269b3b7abc78" data-sample-hash="z7b28n9pqvbrhvs5djq129s83db5hbl1">wh0/tmpnix-drv</option>
<option value="https://cdn.glitch.me/35f4f809-f949-484d-af9c-269b3b7abc78" data-cache-base-drv="https://tmpnix-gsdrv.glitch.me/release/drvs" data-sample-hash="2x8jc972p6vrpsn3dg9xkka94s47rpy5">wh0/tmpnix-out</option>
</select>
</p>
<form name="omni" action="view.html">
<p><label>Cache base<br><input name="cache_base" value="https://cache.nixos.org" class="wide"></label></p>
<p><label>Cache base drv<br><input name="cache_base_drv" value="" class="wide"></label></p>
<p><label>Cache base out<br><input name="cache_base_out" value="" class="wide"></label></p>
<p><label>Hash<br><input name="hash" value="7ghhnlwla2mddkg7hgqa5v0sr8g5hga8" autofocus class="wide"></label></p>
<p>
<input type="submit" value="View">
</p>
</form>
<script>
// when we load a preset, set the hash input's .value so that the browser thinks it's dirty.
// if we don't, then it'll show up with the cache.nixos.org sample hash when we go back.
// but remember that it's not _really_ dirty and we can still feel free to clobber it when changing presets.
let hashReallyDirty = false;
document.forms.omni.onsubmit = (e) => {
console.log('submit');
// disable empty extra fields to make the url cleaner
if (!e.target.elements.cache_base_drv.value) {
e.target.elements.cache_base_drv.disabled = true;
}
if (!e.target.elements.cache_base_out.value) {
e.target.elements.cache_base_out.disabled = true;
}
};
document.getElementById('presets').oninput = (e) => {
if (e.target.selectedIndex === 0) return;
document.forms.omni.elements.cache_base.value = e.target.value;
const presetOption = e.target.selectedOptions[0];
document.forms.omni.elements.cache_base_drv.value = presetOption.dataset.cacheBaseDrv || '';
document.forms.omni.elements.cache_base_out.value = presetOption.dataset.cacheBaseOut || '';
if (!hashReallyDirty) {
document.forms.omni.elements.hash.value = presetOption.dataset.sampleHash || '';
}
};
document.forms.omni.elements.cache_base.oninput = (e) => {
document.getElementById('presets').selectedIndex = 0;
};
document.forms.omni.elements.cache_base_drv.oninput = (e) => {
document.getElementById('presets').selectedIndex = 0;
};
document.forms.omni.elements.cache_base_out.oninput = (e) => {
document.getElementById('presets').selectedIndex = 0;
};
document.forms.omni.elements.hash.onchange = (e) => {
hashReallyDirty = true;
};
window.onpagehide = (e) => {
// re-enable controls that we disabled for submission
document.forms.omni.elements.cache_base_drv.disabled = false;
document.forms.omni.elements.cache_base_out.disabled = false;
};
document.getElementById('presets_container').hidden = false;
</script>