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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
/* ============================================================================
SillyLaird scroll-to-top (network-wide).
Injected by nginx before </body> on HTML responses across *.sillylaird.ca
(see /etc/nginx/snippets/sillylaird-visit-counter.conf). Also loaded as a
fallback from site.js / nav.js. Runs once (window.__slScrollTopInit).
Shows a fixed "▲ TOP" control after the page has been scrolled, and only
when the document is actually taller than the viewport. Works without the
host page loading site.css (styles come from scroll-to-top.css).
============================================================================ */
(function () {
"use strict";
if (window.__slScrollTopInit) return;
window.__slScrollTopInit = true;
// Embedded forms / comments / changelog iframe: the parent page owns scroll.
try {
if (window.self !== window.top) return;
} catch (_) {
return;
}
var path = location.pathname || "/";
if (/\/(admin|api|login|logout|auth|captcha|relay|meta|submit)(\/|$|\.)/i.test(path)) {
return;
}
if (/\.(xml|json|m3u|pls|css|js|map|ico|png|jpe?g|gif|webp|svg|woff2?|mp3|flac|webm|mp4)(\?|$)/i.test(path)) {
return;
}
var CSS_HREF = "https://www.sillylaird.ca/assets/css/scroll-to-top.css?v=20260821b";
var THRESHOLD = 280;
var MIN_OVERFLOW = 240;
function labelForLang() {
var lang = (document.documentElement.lang || "").toLowerCase();
if (lang.indexOf("ja") === 0) return "先頭へ戻る";
if (lang.indexOf("zh") === 0) return "回到顶部";
return "Scroll to top";
}
function prefersReducedMotion() {
return window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
}
function scrollY() {
return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
}
function overflowPx() {
var el = document.scrollingElement || document.documentElement;
return (el ? el.scrollHeight : 0) - (window.innerHeight || 0);
}
function ensureCss() {
var links = document.getElementsByTagName("link");
var i;
for (i = 0; i < links.length; i++) {
if (links[i].rel === "stylesheet" && (links[i].href || "").indexOf("scroll-to-top.css") !== -1) {
return;
}
}
var l = document.createElement("link");
l.rel = "stylesheet";
l.href = CSS_HREF;
document.head.appendChild(l);
}
function ensureTopTarget() {
if (document.getElementById("top")) return;
document.documentElement.id = "top";
}
function dodgeVisitCounter() {
var c = document.getElementById("site-visit-counter");
if (!c) return;
var pos = (c.style && c.style.position) || "";
var computed = window.getComputedStyle ? window.getComputedStyle(c).position : "";
if (pos === "fixed" || computed === "fixed") {
c.setAttribute("data-stt-docked", "1");
// Inline bottom from visit-counter.js wins over the stylesheet, so
// move it here or the two chips sit on top of each other.
c.style.bottom = "4.65rem";
}
}
function ensureButton() {
var existing = document.getElementById("scroll-to-top");
if (existing) return existing;
var a = document.createElement("a");
a.id = "scroll-to-top";
a.className = "scroll-to-top";
a.href = "#top";
var label = labelForLang();
a.setAttribute("aria-label", label);
a.title = label;
var caret = document.createElement("span");
caret.className = "scroll-to-top-caret";
caret.setAttribute("aria-hidden", "true");
caret.appendChild(document.createTextNode("\u25B2"));
var text = document.createElement("span");
text.className = "scroll-to-top-label";
text.setAttribute("aria-hidden", "true");
text.appendChild(document.createTextNode("TOP"));
a.appendChild(caret);
a.appendChild(text);
document.body.appendChild(a);
return a;
}
function goTop(e) {
if (e) e.preventDefault();
if (prefersReducedMotion() || typeof window.scrollTo !== "function") {
if (typeof window.scrollTo === "function") {
window.scrollTo(0, 0);
} else {
document.documentElement.scrollTop = 0;
document.body.scrollTop = 0;
}
return;
}
try {
window.scrollTo({ top: 0, behavior: "smooth" });
} catch (_) {
window.scrollTo(0, 0);
}
}
function init() {
ensureCss();
ensureTopTarget();
var btn = ensureButton();
if (!btn) return;
document.body.className = (document.body.className ? document.body.className + " " : "") + "has-scroll-to-top";
dodgeVisitCounter();
window.setTimeout(dodgeVisitCounter, 50);
window.setTimeout(dodgeVisitCounter, 400);
var ticking = false;
function update() {
ticking = false;
var show = overflowPx() > MIN_OVERFLOW && scrollY() > THRESHOLD;
if (show) {
if (btn.className.indexOf("is-visible") === -1) {
btn.className += " is-visible";
}
} else {
btn.className = btn.className.replace(/\s*is-visible\b/g, "");
}
}
function onScroll() {
if (ticking) return;
ticking = true;
if (window.requestAnimationFrame) {
window.requestAnimationFrame(update);
} else {
window.setTimeout(update, 16);
}
}
window.addEventListener("scroll", onScroll, false);
window.addEventListener("resize", onScroll, false);
btn.addEventListener("click", goTop);
update();
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init);
} else {
init();
}
})();
|