Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
95 lines (72 loc) · 1.47 KB
/
Copy pathscript.js
File metadata and controls
95 lines (72 loc) · 1.47 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
90
91
92
93
94
95
const stashImages = {
stash1: [
"1.png",
"2.png",
"3.png",
"4.png",
"5.png",
"6.png",
"7.png"
],
stash2: [
"stash2.1.png",
"stash2.2.png",
"stash2.3.png",
"stash2.4.png",
"stash2.5.png",
"stash2.6.png",
"stash2.7.png"
]
};
let currentStash = "stash1";
let currentImage = 0;
function openViewer(image, stash) {
if (!stashImages[stash]) {
return;
}
currentStash = stash;
currentImage = stashImages[stash].indexOf(image);
if (currentImage < 0) {
currentImage = 0;
}
updateViewer();
document.getElementById("viewer").style.display = "flex";
}
function updateViewer() {
const images = stashImages[currentStash];
document.getElementById("viewerImage").src = images[currentImage];
}
function nextImage() {
const images = stashImages[currentStash];
currentImage++;
if (currentImage >= images.length) {
currentImage = 0;
}
updateViewer();
}
function previousImage() {
const images = stashImages[currentStash];
currentImage--;
if (currentImage < 0) {
currentImage = images.length - 1;
}
updateViewer();
}
function closeViewer() {
document.getElementById("viewer").style.display = "none";
}
document.addEventListener("keydown", function(event) {
const viewer = document.getElementById("viewer");
if (viewer.style.display !== "flex") {
return;
}
if (event.key === "Escape") {
closeViewer();
}
if (event.key === "ArrowRight") {
nextImage();
}
if (event.key === "ArrowLeft") {
previousImage();
}
});