-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscreenshots.js
More file actions
93 lines (82 loc) · 2.05 KB
/
screenshots.js
File metadata and controls
93 lines (82 loc) · 2.05 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
var modal = document.getElementById('modal');
var span = document.getElementsByClassName("close")[0];
var screenshots = {};
var modalImages = [];
var modalIndex = 0;
function updateModal()
{
var e = document.getElementById('screenshot');
var img = "<img width=\"100%\" src=\"" + modalImages[modalIndex] + "\"/>";
var nav = "";
if (modalImages.length > 1) {
nav = "<div style=\"text-align:center;margin-top:8px;\">";
if (modalIndex > 0) {
nav += "<a href=\"#\" onclick=\"modalPrev();return false\" style=\"margin-right:16px;\">< prev</a>";
}
nav += (modalIndex + 1) + " of " + modalImages.length;
if (modalIndex < modalImages.length - 1) {
nav += "<a href=\"#\" onclick=\"modalNext();return false\" style=\"margin-left:16px;\">next ></a>";
}
nav += "</div>";
}
e.innerHTML = img + nav;
}
function modalPrev()
{
if (modalIndex > 0) {
modalIndex--;
updateModal();
}
}
function modalNext()
{
if (modalIndex < modalImages.length - 1) {
modalIndex++;
updateModal();
}
}
function showscreenshot(s)
{
if (typeof s === "string") {
modalImages = [s];
} else {
modalImages = s;
}
modalIndex = 0;
updateModal();
modal.style.display = "block";
}
function getbox(n, content)
{
if (screenshots[n]) {
var arg = JSON.stringify(screenshots[n]).replace(/"/g, """);
return("<a href=\"#\" data-imgs=\"" + arg + "\" onclick=\"showscreenshot(JSON.parse(this.dataset.imgs));return false\">" + content + "</a>");
}
return content;
}
function screenshotjsonget(url)
{
var r = new XMLHttpRequest();
r.open("GET", url, true);
r.setRequestHeader("Content-type", "application/json")
r.onreadystatechange = function()
{
if (r.readyState == 4 && r.status == 200)
{
var tbl = JSON.parse(r.responseText);
Object.keys(tbl).forEach(function(key, index) {
screenshots[key] = tbl[key];
})
}
}
r.send();
}
screenshotjsonget("https://luanti.foo-projects.org/screenshots.json");
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}