Skip to content

Commit 435f42a

Browse files
author
Natalie Cole-Clift Spiva
committed
Turn cached-version disclosure into an 'i' info bubble
- cached-version.js: small circular 'i' button (bottom-right) expands on click/hover to the cached-version notice, incl. Ctrl/Cmd+Shift+R force-refresh shortcuts and a live-reload link - bump cached-version.js?v=1 -> v=2 on all SW-enabled pages so clients fetch it
1 parent d633d86 commit 435f42a

8 files changed

Lines changed: 57 additions & 34 deletions

File tree

cached-version.js

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,64 @@
11
// cached-version.js — Discloses when AcreetionOS is being viewed from the
2-
// service-worker cache (offline or fallback). Honest transparency: a fixed
3-
// bottom-right bubble in site branding links to the live site. No bubble is
4-
// shown when the page is served live from the network.
2+
// service-worker cache (offline or fallback). An honest little "i" info bubble
3+
// sits bottom-right; clicking it expands the cached-version notice with the
4+
// force-refresh shortcuts. No bubble is shown when the page is served live.
55
// Maintainers: AcreetionOS
66

77
(function () {
88
"use strict";
99
if (!("serviceWorker" in navigator)) return;
1010

11-
var shown = false;
11+
var created = false;
1212

1313
function showBubble() {
14-
if (shown) return;
15-
shown = true;
16-
17-
var b = document.createElement("div");
18-
b.style.cssText =
19-
"all:initial;position:fixed;right:16px;bottom:16px;z-index:2147483647;" +
20-
"font:13px/1.45,-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen,Ubuntu,Cantarell,sans-serif;" +
21-
"color:#e5e5e5;background:#1a1a1a;border:1px solid #2ecc71;border-left:4px solid #2ecc71;" +
22-
"border-radius:10px;padding:12px 14px;max-width:300px;" +
23-
"box-shadow:0 6px 18px rgba(0,0,0,0.55);";
24-
25-
b.innerHTML =
26-
'<div style="font-weight:700;color:#2ecc71;margin-bottom:4px;">Cached version</div>' +
27-
'<div style="color:#b2b2b2;">You are looking at a locally cached copy' +
28-
' of this page because the network version could not be loaded right now.' +
29-
' To force-load the live page, press <b style="color:#e5e5e5;">Ctrl + Shift + R</b>' +
30-
' (Windows/Linux) or <b style="color:#e5e5e5;">Cmd + Shift + R</b> (macOS).' +
31-
' <a href="' + location.pathname + '" style="color:#2ecc71;font-weight:600;text-decoration:none;">Reload live →</a></div>';
32-
33-
// Clicking anywhere except the link dismisses the notice.
34-
b.addEventListener("click", function (e) {
35-
if (e.target.tagName !== "A") b.style.display = "none";
14+
if (created) return;
15+
created = true;
16+
17+
var wrap = document.createElement("div");
18+
// Outer "i" button — small circular info icon, site green-on-dark.
19+
wrap.innerHTML =
20+
'<button aria-label="Cached version info" title="This page is a cached copy" style="' +
21+
'all:initial;cursor:pointer;position:fixed;right:16px;bottom:16px;z-index:2147483647;' +
22+
'width:36px;height:36px;border-radius:50%;border:2px solid #2ecc71;' +
23+
'background:#1a1a1a;color:#2ecc71;font:700 20px/1 -apple-system,BlinkMacSystemFont,\'Segoe UI\',Roboto,sans-serif;' +
24+
'font-style:italic;display:flex;align-items:center;justify-content:center;' +
25+
'box-shadow:0 4px 14px rgba(0,0,0,0.55);user-select:none;' +
26+
'">i</button>' +
27+
'<div class="acc-cached-note" style="' +
28+
'position:fixed;right:16px;bottom:64px;z-index:2147483647;display:none;max-width:310px;' +
29+
'font:13px/1.5 -apple-system,BlinkMacSystemFont,\'Segoe UI\',Roboto,Oxygen,Ubuntu,Cantarell,sans-serif;' +
30+
'color:#e5e5e5;background:#1a1a1a;border:1px solid #2ecc71;border-left:4px solid #2ecc71;' +
31+
'border-radius:10px;padding:12px 14px;box-shadow:0 6px 18px rgba(0,0,0,0.55);' +
32+
'">' +
33+
'<div style="font-weight:700;color:#2ecc71;margin-bottom:4px;">Cached version</div>' +
34+
'<div style="color:#b2b2b2;">You are looking at a locally cached copy of this page ' +
35+
'because the network version could not be loaded right now. To force-load the live page, ' +
36+
'press <b style="color:#e5e5e5;">Ctrl + Shift + R</b> (Windows/Linux) ' +
37+
'or <b style="color:#e5e5e5;">Cmd + Shift + R</b> (macOS). ' +
38+
'<a href="' + location.pathname + '" style="color:#2ecc71;font-weight:600;text-decoration:none;">Reload live →</a>' +
39+
'</div>' +
40+
'</div>';
41+
42+
var btn = wrap.firstElementChild;
43+
var note = wrap.lastElementChild;
44+
45+
function toggle(force) {
46+
note.style.display = typeof force === "boolean" ? (force ? "block" : "none") : (note.style.display === "block" ? "none" : "block");
47+
}
48+
49+
btn.addEventListener("click", function (e) {
50+
e.stopPropagation();
51+
toggle();
52+
});
53+
// Hover also reveals it (discoverable), click finishes interaction.
54+
btn.addEventListener("mouseenter", function () { toggle(true); });
55+
btn.addEventListener("mouseleave", function () { toggle(false); });
56+
// Dismiss when clicking outside.
57+
document.addEventListener("click", function (e) {
58+
if (!wrap.contains(e.target)) toggle(false);
3659
});
3760

38-
(document.body || document.documentElement).appendChild(b);
61+
(document.body || document.documentElement).appendChild(wrap);
3962
}
4063

4164
navigator.serviceWorker.addEventListener("message", function (e) {

compare.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ <h2>
458458
</div>
459459
</div>
460460
<script src="sw-register.js?v=20260825" defer>
461-
<script src="cached-version.js?v=1" defer>
461+
<script src="cached-version.js?v=2" defer>
462462
</script>
463463
<script src="footer.js?v=20260825" defer>
464464
</script>

docs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ <h1 id="doc-title">
351351

352352
</script>
353353
<script src="sw-register.js?v=20260825" defer>
354-
<script src="cached-version.js?v=1" defer>
354+
<script src="cached-version.js?v=2" defer>
355355
</script>
356356
<script src="footer.js?v=20260825" defer>
357357
</script>

faq.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ <h2>
748748
</div>
749749
</div>
750750
<script src="sw-register.js?v=20260825" defer>
751-
<script src="cached-version.js?v=1" defer>
751+
<script src="cached-version.js?v=2" defer>
752752
</script>
753753
<script src="faq-issue.js?v=20260824" defer>
754754
</script>

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ <h2 class="section-title section-title--block section-title--mt-lg">Community &a
460460
</div>
461461
<script src="sw-register.js?v=20260825" defer>
462462
</script>
463-
<script src="cached-version.js?v=1" defer>
463+
<script src="cached-version.js?v=2" defer>
464464
</script>
465465
<script src="index-providers.js?v=20260825" defer>
466466
</script>

requirements.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ <h3>
306306
</div>
307307
</div>
308308
<script src="sw-register.js?v=20260825" defer>
309-
<script src="cached-version.js?v=1" defer>
309+
<script src="cached-version.js?v=2" defer>
310310
</script>
311311
<script src="footer.js?v=20260825" defer>
312312
</script>

status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ <h2><i class="bi bi-clock-history"></i> Incident History</h2>
178178
</div>
179179
</div>
180180
<script src="sw-register.js?v=20260825" defer>
181-
<script src="cached-version.js?v=1" defer>
181+
<script src="cached-version.js?v=2" defer>
182182
</script>
183183
<script src="footer.js?v=20260825" defer>
184184
</script>

unofficial.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ <h2>
538538
</div>
539539
</div>
540540
<script src="sw-register.js?v=20260825" defer>
541-
<script src="cached-version.js?v=1" defer>
541+
<script src="cached-version.js?v=2" defer>
542542
</script>
543543
<script src="footer.js?v=20260825" defer>
544544
</script>

0 commit comments

Comments
 (0)