-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfolder.js
More file actions
88 lines (74 loc) · 3.13 KB
/
folder.js
File metadata and controls
88 lines (74 loc) · 3.13 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
document.addEventListener('DOMContentLoaded', function() {
const gallery = document.getElementById('gallery');
const folder = new URLSearchParams(window.location.search).get('folder');
let imageCount = 0;
const imagesPerLoad = 100; // Number of images to load per click
const totalImages = 1000; // Total number of images in each folder
if (!folder || isNaN(folder) || folder < 0 || folder > 9) {
gallery.textContent = 'Folder not found';
return;
}
function createImageNumberLabel(imageNumber) {
const label = document.createElement('p');
label.textContent = `Bitcoin String ${imageNumber.toString().padStart(5, '0')}`;
label.style.textAlign = 'center';
label.style.background = 'Gold';
return label;
}
function createDownloadButton(jsonSrc) {
const button = document.createElement('button');
button.textContent = 'Download JSON';
button.onclick = () => downloadJSON(jsonSrc);
button.style.display = 'block';
button.style.margin = '5px auto';
return button;
}
function loadImages() {
const startImageNumber = parseInt(folder) * 1000 + imageCount + 1;
const endImageNumber = Math.min(startImageNumber + imagesPerLoad - 1, parseInt(folder) * 1000 + totalImages);
for (let image = startImageNumber; image <= endImageNumber; image++) {
const img = document.createElement('img');
const imageName = `${folder}/${image.toString().padStart(5, '0')}.svg`;
img.src = imageName;
img.alt = `Image ${image.toString().padStart(5, '0')}`;
img.style.width = '150px';
img.style.height = '150px';
const jsonName = `${folder}json/item-${image.toString().padStart(5, '0')}.json`;
const imageContainer = document.createElement('div');
imageContainer.appendChild(createImageNumberLabel(image));
imageContainer.appendChild(img);
imageContainer.appendChild(createDownloadButton(jsonName));
gallery.appendChild(imageContainer);
}
imageCount += imagesPerLoad;
if (imageCount >= totalImages) {
loadMoreButton.style.display = 'none';
}
}
// Initial load
loadImages();
const loadMoreButton = document.createElement('button');
loadMoreButton.textContent = 'Load More';
loadMoreButton.onclick = loadImages;
loadMoreButton.style.display = 'block';
loadMoreButton.style.margin = '20px auto';
loadMoreButton.style.padding = '10px 20px';
loadMoreButton.style.textAlign = 'center';
document.body.appendChild(loadMoreButton);
});
function downloadImage(imageSrc) {
const link = document.createElement('a');
link.href = imageSrc;
link.download = imageSrc.split('/').pop();
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
function downloadJSON(jsonSrc) {
const link = document.createElement('a');
link.href = jsonSrc;
link.download = jsonSrc.split('/').pop();
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}