diff --git a/theme/basic.css b/theme/basic.css index 1cbed97..a07b747 100644 --- a/theme/basic.css +++ b/theme/basic.css @@ -133,3 +133,7 @@ li[draggable] { [draggable].over { border: 1px white dashed; } + +#cacheButton.disabled { + display: none; +} diff --git a/theme/index.html b/theme/index.html index 811878e..705cdae 100644 --- a/theme/index.html +++ b/theme/index.html @@ -27,6 +27,7 @@ diff --git a/theme/moth.js b/theme/moth.js index 3d5b7fc..73b5d88 100644 --- a/theme/moth.js +++ b/theme/moth.js @@ -111,18 +111,7 @@ function showPuzzles(teamId) { } function drawCacheButton(teamId) { - let cacher = document.createElement("li") - let cache_button = document.createElement("a") - cache_button.innerText = "Cache" - cache_button.title = "Cache an offine copy of current content" - cache_button.href = "#" - cache_button.addEventListener("click", async function() { - toast("Caching all currently-open content") - await fetchAll(teamId) - toast("Done caching content") - }) - cacher.appendChild(cache_button) - document.getElementsByTagName("nav")[0].getElementsByTagName("ul")[0].appendChild(cacher) + let cacher = document.querySelector("#cacheButton") function updateCacheButton() { let headers = new Headers() @@ -133,13 +122,13 @@ function drawCacheButton(teamId) { fetch(url, {method: "HEAD", headers: headers}) .then( resp => { if (resp.ok) { - cacher.style.disply = "initial" + cacher.classList.remove("disabled") } else { - cacher.style.display = "none" + cacher.classList.add("disabled") } }) .catch(ex => { - cacher.style.display = "none" + cacher.classList.add("disabled") }) } @@ -147,7 +136,8 @@ function drawCacheButton(teamId) { updateCacheButton() } -async function fetchAll(teamId) { +async function fetchAll() { + let teamId = sessionStorage.getItem("id") let headers = new Headers() headers.append("pragma", "no-cache") headers.append("cache-control", "no-cache") @@ -155,6 +145,7 @@ async function fetchAll(teamId) { let url = new URL("current_manifest.json", window.location) url.searchParams.set("id", teamId) + toast("Caching all currently-open content") requests.push( fetch(url, {headers: headers}) .then( resp => { if (resp.ok) { @@ -198,7 +189,8 @@ async function fetchAll(teamId) { } } } - return Promise.all(requests) + await Promise.all(requests) + toast("Done caching content") } function login(e) {