-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
89 lines (75 loc) · 2.5 KB
/
Copy pathscript.js
File metadata and controls
89 lines (75 loc) · 2.5 KB
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
function updateClock() {
const now = new Date();
const day = new Intl.DateTimeFormat("en-GB", { weekday: "short" }).format(now).toUpperCase();
const date = new Intl.DateTimeFormat("en-GB", { day: "numeric", month: "short" }).format(now).toUpperCase();
const time = new Intl.DateTimeFormat("en-GB", { hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false }).format(now);
const blinkingTime = time.replace(/:/g, '<span class="colon">:</span>');
document.getElementById("clock").innerHTML = `<span class="clock-date">${day} ${date}</span> ${blinkingTime}`;
}
updateClock();
setInterval(updateClock, 1000);
(function pageNumberEntry() {
const plainEl = document.getElementById("page-number-plain");
if (!plainEl) return;
const plainDefaultValue = plainEl.dataset.default;
const map = window.PAGE_MAP || {};
let buffer = "";
function render() {
if (plainEl) plainEl.textContent = buffer || plainDefaultValue;
}
document.addEventListener("keydown", (e) => {
const tag = document.activeElement && document.activeElement.tagName;
if (tag === "INPUT" || tag === "TEXTAREA") return;
if (/^[0-9]$/.test(e.key)) {
if (buffer.length < 3) buffer += e.key;
render();
return;
}
if (e.key === "Backspace") {
buffer = buffer.slice(0, -1);
render();
return;
}
if (e.key === "Escape") {
buffer = "";
render();
return;
}
if (e.key === "Enter" && buffer) {
const url = map[buffer];
if (url) {
window.location.href = url;
} else {
window.location.href = "/404/?p=" + buffer;
}
}
});
})();
(function lightbox() {
const box = document.getElementById("lightbox");
const boxImg = document.getElementById("lightbox-img");
if (!box || !boxImg) return;
function open(src, alt) {
boxImg.src = src;
boxImg.alt = alt || "";
box.hidden = false;
}
function close() {
box.hidden = true;
boxImg.src = "";
}
document.querySelectorAll(".project-shots img").forEach((img) => {
img.addEventListener("click", () => open(img.src, img.alt));
});
box.addEventListener("click", close);
document.addEventListener("keydown", (e) => {
if (e.key === "Escape" && !box.hidden) close();
});
})();
(function notFoundNumber() {
const target = document.getElementById("not-found-code");
if (!target) return;
const params = new URLSearchParams(window.location.search);
const p = params.get("p");
if (p) target.textContent = "PAGE " + p + " NOT FOUND";
})();