-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
71 lines (67 loc) · 2.14 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Simple Image Preview</title>
<style>
.columns {
column-count: 5;
column-gap: 10px;
margin: 10px;
}
img {
display: block;
margin-bottom: 10px;
width: 100%;
user-select: none;
}
</style>
</head>
<body>
<div class="columns"></div>
<script type="module">
const reg = /^(192\.168\.|127\.0\.|localhost)/
if (reg.test(location.hostname)) {
import('/src/main.ts').then((module) => {
let hash = location.hash.slice(1) || 'img'
if (hash === 'all') hash = document.querySelectorAll('img')
module.default(hash, { zIndex: 3 })
})
} else {
const s = document.createElement('script')
s.src = 'https://cdn.jsdelivr.net/npm/simple-image-preview@latest/dist/simple-image-preview.umd.js'
document.head.appendChild(s)
s.onload = () => {
simpleImagePreview()
}
}
</script>
<script>
const columnsContainer = document.querySelector('.columns')
const cdf = document.createDocumentFragment()
const testImages = JSON.parse(sessionStorage.getItem('test-imgs') || '[]')
const imgs = new Array(30).fill(0).map((item, i) => {
if (testImages.length) return testImages[i]
const imgWidth = Math.floor(Math.random() * 500) + 200
const imgHeight = Math.floor(Math.random() * 500) + 200
const imgUrl = `https://picsum.photos/${imgWidth}/${imgHeight}`
return fetch(imgUrl).then((r) => {
testImages.push(r.url)
return r.url
})
})
Promise.allSettled(imgs).then((result) => {
sessionStorage.setItem('test-imgs', JSON.stringify(testImages))
for (const r of result) {
if (r.status === 'fulfilled') {
const img = document.createElement('img')
img.src = r.value
cdf.appendChild(img)
}
}
columnsContainer.appendChild(cdf)
})
</script>
</body>
</html>