(()=>{ let tmp = new Date(); const NOW = tmp.getTime(); tmp.setHours(0); tmp.setMinutes(0); tmp.setSeconds(0); let today = tmp.getTime(); if (tmp.getDay() === 0) tmp.setDate(tmp.getDate() -7); if (tmp.getDay() !== 1) tmp.setDate(tmp.getDate()-tmp.getDay() +1); const ONE_WEEK = tmp.getTime(); tmp.setTime(today); tmp.setDate(1); const ONE_MONTH = tmp.getTime(); const relSource = document.getElementById("relSource"); /* INIT DROPDOWN */ (() => { let frag = document.createDocumentFragment(); let origins = ACCESS.reduce((acc, i) => { acc[i.publicId] = true; return acc; }, {}); for (let i of ORIGINS) origins[i] = true; for (let i of (["All"].concat(Object.keys(origins).sort())).map(i => { let node = document.createElement("option"); node.textContent = i; return node; })) frag.appendChild(i); relSource.appendChild(frag); })(); function formatDate(d) { if (!d || isNaN(d.getTime())) return ""; return d.toLocaleDateString() + " " + d.toLocaleTimeString(); } function prependDomain(xmlElement) { xmlElement.textContent = document.location.origin + xmlElement.textContent; } function generateQrCode(size, rel) { if (rel) rel = "&rel="+encodeURIComponent(rel); return "/" +PUBLIC_ID +"/qrcode.png?origin="+encodeURIComponent(document.location.origin)+'&s='+size +(rel || ""); } let HASH_CHANGING = false; function selectSource(source) { let _access = source === "All" ? ACCESS : ACCESS.filter(i => i.publicId === source); let lastAccess = _access.reduce((prev, i) => (prev && prev.accessTime > i.accessTime) ? prev : i, null); document.getElementById('totalAccessCount').textContent = _access.length; document.getElementById('weekAccess').textContent = _access.reduce((acc, i) => acc + (i.accessTime >= ONE_WEEK ? 1 : 0), 0); document.getElementById('monthAccess').textContent = _access.reduce((acc, i) => acc + (i.accessTime >= ONE_MONTH ? 1 : 0), 0); document.getElementById('lastAccess').textContent = formatDate(new Date(lastAccess?.accessTime)); document.getElementById("publicLinkQr").innerHTML = ""; document.getElementById("publicLinkQrBig").href = generateQrCode(1024, !source || source === "All" ? null : source); const linkEnd = PUBLIC_ID + (!source || source === "All" ? "" : ("?r=" +source)); document.getElementById("publicLink").textContent = document.location.origin + "/x/" + linkEnd; document.getElementById("embedLink").textContent = document.location.origin + "/x/raw/" + linkEnd; document.getElementById("publicLinkA").href = "/x/" +linkEnd; document.getElementById("embedLinkA").href = "/x/raw/" +linkEnd; HASH_CHANGING = true; document.location.hash = encodeURIComponent(source); HASH_CHANGING = false; } function updateSource() { const selected = relSource.selectedOptions?.[0]?.textContent; selectSource(selected || selected === '' ? selected : "All"); } function hashChanged() { if (HASH_CHANGING) return; if (document.location.hash) { const hash = (decodeURIComponent(document.location.hash.substring(1))); selectSource(hash); for (let i =0; i < relSource.children.length; ++i) { if (relSource.children[i].textContent === hash) { relSource.selectedIndex = i; break; } } } else { updateSource(); } } hashChanged(); addEventListener("hashchange", hashChanged); relSource.addEventListener("change", () => updateSource()); document.getElementById("size").textContent = FILE_SIZE +'o'; document.getElementById("creationTime").textContent = formatDate(new Date(CREATION_TIME)); document.getElementById("expiralTime").textContent = formatDate(new Date(EXPIRAL_TIME)); })();