-
Notifications
You must be signed in to change notification settings - Fork 2
/
roll.html
123 lines (107 loc) · 3.76 KB
/
roll.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Roll</title>
<style>
body {
height: 100vh;
width: 100vw;
margin: 0;
background-color: #000;
font-family: 'monospace';
color: lightgray;
}
header {
height: 8vh;
padding-top: 2vh;
padding-left: 2em;
}
footer {
height: 5vh;
padding-top: 5vh;
padding-left: 2em;
}
main {
height: 80vh;
width: 100%;
display: flex;
justify-content: center;
}
#tryAgain {
display: none;
}
#page {
height: 80vh;
max-width: 80vw;
}
#workPage {
text-decoration: none;
color: lightgray;
}
#workPage:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<header><a href="" id="workPage"></a></header>
<main>
<img id="page" />
<p id="tryAgain">Not suitable... try again! (may be access-controlled or not image-based).</p>
</main>
<footer>
<span id="identifier"></span>
<span id="counter"></span>
<span id="toggle">
<input type="checkbox" id="hilo" />
<label for="hilo">Hi res</label>
</span>
</footer>
<script>
fetch("https://iiif.wellcomecollection.org/service/suggest-b-number?q=imfeelinglucky")
.then(resp => resp.json())
.then(suggestions => {
document.getElementById("identifier").innerText = suggestions[0].id;
fetch(`https://iiif.wellcomecollection.org/presentation/${suggestions[0].id}`)
.then(resp => resp.json())
.then(manifest => analyse(manifest));
});
function analyse(manifest) {
document.getElementById("workPage").innerText = manifest.label["en"][0];
document.getElementById("workPage").href = manifest.homepage[0].id;
// just check the first canvas has a thumbnail that's an image with a 1024 thumb
var lastSize = manifest.items?.[0].thumbnail?.[0].service?.[0].sizes?.slice(-1)[0];
if (lastSize && (lastSize.width == 1024 || lastSize.height == 1024)) {
let image = document.getElementById("page");
setImageSrc(image, manifest.items, 0);
loadNext(manifest.items, 0, image);
} else {
document.getElementById("page").style.display = "none";
document.getElementById("tryAgain").style.display = "block";
}
}
function loadNext(canvases, index, prev) {
if (canvases.length > index) {
let next = new Image();
next.onload = () => loadNext(canvases, index + 1, next);
setImageSrc(next, canvases, index);
if (prev) {
document.getElementById("counter").innerText = `${index + 1}/${canvases.length}`;
document.getElementById("page").src = prev.src;
}
}
}
function setImageSrc(image, canvases, index) {
let service = canvases[index].thumbnail?.[0].service?.[0];
let slice = document.getElementById("hilo").checked ? -1 : -2;
if (service) {
let size = service.sizes?.slice(slice)[0];
image.src = `${service["@id"]}/full/${size.width},${size.height}/0/default.jpg`;
}
}
</script>
</body>
</html>