Files
SahikDevSite/public/main.js
T
2026-12-02 15:45:58 +08:00

85 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// about.sahik.dev
(() => {
const reduceMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
/* ---------- 開機畫面:每個分頁只播一次,點一下或按任意鍵跳過 ---------- */
if (!reduceMotion && !sessionStorage.getItem("booted")) {
sessionStorage.setItem("booted", "1");
const lines = [
"SAHIK BIOS v26.12",
"",
"CPU Xeon E5-2696 v4 ........ <span class=ok>OK</span>",
"MEM 256 GB ECC ............. <span class=ok>OK</span>",
"GPU Tesla M40 24G .......... <span class=ok>OK</span>",
"NAS 3 × mirror ............. <span class=ok>OK</span>",
"",
"Loading about.sahik.dev",
];
const boot = document.createElement("div");
boot.className = "boot";
boot.setAttribute("aria-hidden", "true");
const pre = document.createElement("pre");
boot.appendChild(pre);
document.body.appendChild(boot);
let i = 0, timer;
const finish = () => {
clearTimeout(timer);
boot.classList.add("done");
setTimeout(() => boot.remove(), 400);
removeEventListener("keydown", finish);
};
const step = () => {
if (i < lines.length) {
pre.innerHTML = lines.slice(0, ++i).join("\n") + ' <span class="cursor"></span>';
timer = setTimeout(step, i === 1 ? 220 : 110);
} else {
timer = setTimeout(finish, 380);
}
};
boot.addEventListener("click", finish);
addEventListener("keydown", finish);
step();
}
/* ---------- 伺服器照片切換 ---------- */
document.querySelectorAll("[data-gallery]").forEach((g) => {
const main = g.querySelector(".server-photo");
const caption = g.querySelector(".photo-caption");
const thumbs = g.querySelectorAll(".thumbs button");
thumbs.forEach((t) => {
t.addEventListener("click", () => {
main.src = t.dataset.src;
main.alt = t.dataset.alt;
caption.textContent = t.dataset.caption;
thumbs.forEach((x) => x.setAttribute("aria-pressed", String(x === t)));
});
});
});
/* ---------- 頭像彩蛋 ---------- */
const toast = document.querySelector(".toast");
let toastTimer;
const say = (msg) => {
toast.textContent = msg;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2200);
};
const avatar = document.querySelector(".avatar-btn");
const msgs = ["?", "咕。", "牠沒有名字。", "再點一下就要發生事情了。"];
let clicks = 0;
avatar.addEventListener("click", () => {
avatar.classList.remove("wiggle");
void avatar.offsetWidth;
avatar.classList.add("wiggle");
if (clicks < msgs.length) {
say(msgs[clicks++]);
} else {
clicks = 0;
say("Never gonna give you up ♪");
window.open("https://sahik.dev", "_blank", "noopener");
}
});
})();