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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>時光图床</title> <style> body { font-family: Arial, sans-serif; margin: 0; background-color: #f9f9f9; display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%; } .container { display: flex; flex-direction: column; align-items: center; } .folder, .image { margin: 10px; padding: 10px; border: 1px solid #ccc; border-radius: 5px; text-align: center; width: 100%; max-width: 300px; background-color: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); transition: transform 0.2s; } .folder:hover, .image:hover { background-color: #f0f0f0; transform: translateY(-2px); } .image img { max-width: 100%; max-height: 200px; cursor: pointer; border-radius: 5px; } .modal { display: none; position: fixed; z-index: 1; padding-top: 100px; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.9); } .modal-content { margin: auto; display: block; width: 80%; max-width: 700px; border-radius: 5px; } .close { position: absolute; top: 15px; right: 35px; color: #f1f1f1; font-size: 40px; font-weight: bold; transition: 0.3s; } .close:hover, .close:focus { color: #bbb; text-decoration: none; cursor: pointer; } @media (min-width: 600px) { .container { flex-direction: row; flex-wrap: wrap; justify-content: center; } .folder, .image { width: 45%; max-width: none; } } @media (min-width: 900px) { .folder, .image { width: 30%; } } </style> </head> <body> <h1>時光图床</h1> <div class="container" id="container"></div>
<div id="myModal" class="modal"> <span class="close">×</span> <img class="modal-content" id="img01"> <div id="caption"></div> </div>
<script> document.addEventListener('DOMContentLoaded', function() { const container = document.getElementById('container'); const modal = document.getElementById('myModal'); const modalImg = document.getElementById('img01'); const close = document.getElementsByClassName('close')[0];
let currentPath = '';
function loadFolders(folders, path = '') { container.innerHTML = ''; folders.forEach(folder => { if (folder.images && folder.images.length > 0) { folder.images.forEach(image => { const imageDiv = document.createElement('div'); imageDiv.className = 'image'; const img = document.createElement('img'); img.src = `/${image}`; img.alt = image; img.onclick = function() { modal.style.display = 'block'; modalImg.src = this.src; history.pushState({ path: currentPath, image: image }, '', `/${image}`); }; imageDiv.appendChild(img); container.appendChild(imageDiv); }); } else { const folderDiv = document.createElement('div'); folderDiv.className = 'folder'; folderDiv.textContent = folder.name; folderDiv.onclick = function() { currentPath = `${path}${folder.name}/`; history.pushState({ path: currentPath }, '', currentPath); fetch(`/api/files/${currentPath}`) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }) .then(data => loadFolders(data, currentPath)) .catch(error => console.error('Error fetching files:', error)); }; container.appendChild(folderDiv); } }); }
window.addEventListener('popstate', function(event) { if (event.state && event.state.path) { currentPath = event.state.path; fetch(`/api/files/${currentPath}`) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }) .then(data => loadFolders(data, currentPath)) .catch(error => console.error('Error fetching files:', error)); } if (event.state && event.state.image) { modal.style.display = 'block'; modalImg.src = `/${event.state.image}`; } });
fetch('/api/files') .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }) .then(data => { currentPath = ''; history.replaceState({ path: currentPath }, '', currentPath); loadFolders(data); }) .catch(error => console.error('Error fetching files:', error));
close.onclick = function() { modal.style.display = 'none'; history.pushState({ path: currentPath }, '', currentPath); };
window.onclick = function(event) { if (event.target == modal) { modal.style.display = 'none'; history.pushState({ path: currentPath }, '', currentPath); } }; }); </script> </body> </html>
|