document.addEventListener('DOMContentLoaded', function() { // Initialize admin system and gallery on gallery.html if (window.location.pathname.includes('gallery.html')) { // Admin login system const loginBtn = document.getElementById("loginBtn"); const logoutBtn = document.getElementById("logoutBtn"); const uploadArea = document.getElementById("uploadArea"); const gallery = document.getElementById("gallery"); const fileInput = document.getElementById("fileInput"); const uploadBtn = document.getElementById("uploadBtn"); const uploadMsg = document.getElementById("uploadMsg"); // Admin password const ADMIN_PASSWORD = "gg_mistro.249"; // Keep the same password function checkLogin() { const expires = localStorage.getItem("loginExpires"); const loggedIn = expires && new Date().getTime() < expires; if (loggedIn) { uploadArea.style.display = "block"; logoutBtn.classList.remove("hidden"); loginBtn.classList.add("hidden"); } else { uploadArea.style.display = "none"; logoutBtn.classList.add("hidden"); loginBtn.classList.remove("hidden"); localStorage.removeItem("loginExpires"); } } loginBtn.addEventListener('click', async () => { const input = prompt("Enter admin password:"); if (input) { if (input === ADMIN_PASSWORD) { // Set session to expire in 2 hours const expires = new Date().getTime() + 7200000; localStorage.setItem("loginExpires", expires); checkLogin(); alert("Login successful!"); } else { alert("Incorrect password."); } } }); logoutBtn.addEventListener('click', () => { localStorage.removeItem("loginExpires"); checkLogin(); alert("You have been logged out."); }); // === IMAGE UPLOAD === uploadBtn.addEventListener('click', () => { const files = fileInput.files; if (!files.length) return alert("Select image(s) first!"); uploadMsg.textContent = "Uploading... (0/"+files.length+")"; uploadMsg.style.display = 'block'; uploadMsg.style.color = 'white'; for (const file of files) { const reader = new FileReader(); reader.onload = e => { const img = document.createElement("img"); img.src = e.target.result; img.classList.add("zoomable"); gallery.appendChild(img); saveImage(e.target.result); }; reader.readAsDataURL(file); } uploadMsg.textContent = "Upload complete! ("+files.length+"/"+files.length+")"; uploadMsg.style.color = '#00FF7F'; setTimeout(() => { uploadMsg.style.display = 'none'; fileInput.value = ''; // Clear file input }, 3000); }); function saveImage(dataUrl) { const saved = JSON.parse(localStorage.getItem("images") || "[]"); saved.push(dataUrl); localStorage.setItem("images", JSON.stringify(saved)); } function loadImages() { gallery.innerHTML = ""; const saved = JSON.parse(localStorage.getItem("images") || "[]"); if (saved.length === 0) { gallery.innerHTML = ''; return; } for (const src of saved) { const img = document.createElement("img"); img.src = src; img.classList.add("zoomable"); gallery.appendChild(img); } } loadImages(); // === IMAGE ZOOM FEATURE === const zoomContainer = document.createElement("div"); zoomContainer.id = "zoomContainer"; zoomContainer.style.display = "none"; zoomContainer.style.position = "fixed"; zoomContainer.style.top = "0"; zoomContainer.style.left = "0"; zoomContainer.style.width = "100%"; zoomContainer.style.height = "100%"; zoomContainer.style.background = "rgba(0,0,0,0.8)"; zoomContainer.style.justifyContent = "center"; zoomContainer.style.alignItems = "center"; zoomContainer.style.zIndex = "9999"; const zoomImg = document.createElement("img"); zoomImg.style.maxWidth = "90%"; zoomImg.style.maxHeight = "90%"; zoomImg.style.borderRadius = "10px"; zoomImg.style.boxShadow = "0 0 20px #00FF7F"; zoomContainer.appendChild(zoomImg); document.body.appendChild(zoomContainer); gallery.addEventListener("click", e => { if (e.target.tagName === "IMG") { zoomImg.src = e.target.src; zoomContainer.style.display = "flex"; document.body.style.overflow = "hidden"; } }); zoomContainer.addEventListener("click", () => { zoomContainer.style.display = "none"; document.body.style.overflow = "auto"; }); } feather.replace(); });