madebydanny.uk written in html, css, and a lot of JavaScript I don't understand madeydanny.uk
html css javascript

cdn

-132
cdn/index.html cdn.html
-132
cdn/script.js
··· 1 - document.addEventListener("DOMContentLoaded", () => { 2 - // Set current year 3 - const yearEl = document.getElementById("current-year"); 4 - if (yearEl) yearEl.textContent = new Date().getFullYear(); 5 - 6 - const dropZone = document.getElementById('drop-zone'); 7 - const fileInput = document.getElementById('fileInput'); 8 - const uploadBtn = document.getElementById('uploadBtn'); 9 - const resultDiv = document.getElementById('result'); 10 - const useImrsCheckbox = document.getElementById('useImrs'); 11 - const useOfficeCheckbox = document.getElementById('useOfficeViewer'); 12 - 13 - // Handle clicks and touches on drop zone 14 - ['click', 'touchend'].forEach(event => 15 - dropZone.addEventListener(event, () => fileInput.click()) 16 - ); 17 - 18 - // Drag and drop 19 - dropZone.addEventListener('dragover', e => { 20 - e.preventDefault(); 21 - dropZone.classList.add('drag-over'); 22 - }); 23 - dropZone.addEventListener('dragleave', () => dropZone.classList.remove('drag-over')); 24 - dropZone.addEventListener('drop', e => { 25 - e.preventDefault(); 26 - dropZone.classList.remove('drag-over'); 27 - if (e.dataTransfer && e.dataTransfer.files.length) { 28 - fileInput.files = e.dataTransfer.files; 29 - updateDropZoneText(); 30 - updateCheckboxVisibility(); 31 - } 32 - }); 33 - 34 - // File selection 35 - fileInput.addEventListener('change', () => { 36 - updateDropZoneText(); 37 - updateCheckboxVisibility(); 38 - }); 39 - 40 - function updateDropZoneText() { 41 - const textEl = dropZone.querySelector('p'); 42 - if (!textEl) return; 43 - if (fileInput.files.length) { 44 - textEl.innerHTML = `✅ Selected: ${fileInput.files[0].name}`; 45 - } else { 46 - textEl.innerHTML = `<i class="fa-solid fa-upload"></i> Drag & drop your file here, or tap to select`; 47 - } 48 - } 49 - 50 - function updateCheckboxVisibility() { 51 - if (!fileInput.files.length) { 52 - useImrsCheckbox.parentElement.style.display = "none"; 53 - useOfficeCheckbox.parentElement.style.display = "none"; 54 - return; 55 - } 56 - const file = fileInput.files[0]; 57 - const fileExt = file.name.split('.').pop().toLowerCase(); 58 - useImrsCheckbox.parentElement.style.display = file.type.startsWith('image/') ? "block" : "none"; 59 - const officeExts = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx']; 60 - useOfficeCheckbox.parentElement.style.display = officeExts.includes(fileExt) ? "block" : "none"; 61 - } 62 - 63 - uploadBtn.addEventListener('click', async () => { 64 - if (!fileInput.files.length) { 65 - resultDiv.textContent = "Please select a file first."; 66 - return; 67 - } 68 - 69 - const file = fileInput.files[0]; 70 - const formData = new FormData(); 71 - formData.append('file', file); 72 - 73 - resultDiv.innerHTML = '<i class="fa-solid fa-arrows-rotate fa-spin"></i> Uploading...'; 74 - 75 - try { 76 - const response = await fetch('https://cdn.madebydanny.uk/upload', { 77 - method: 'POST', 78 - body: formData 79 - }); 80 - 81 - const data = await response.json(); 82 - if (!response.ok) throw new Error(data.error || 'Upload failed'); 83 - 84 - let finalUrl = data.url; 85 - if (useImrsCheckbox.checked && file.type.startsWith('image/')) { 86 - finalUrl = `https://imrs.madebydanny.uk?url=${encodeURIComponent(finalUrl)}`; 87 - } 88 - 89 - // Copy URL to clipboard with fallback 90 - let copied = false; 91 - if (navigator.clipboard && navigator.clipboard.writeText) { 92 - try { 93 - await navigator.clipboard.writeText(finalUrl); 94 - copied = true; 95 - } catch { copied = false; } 96 - } 97 - if (!copied) { 98 - const tempInput = document.createElement("input"); 99 - tempInput.value = finalUrl; 100 - document.body.appendChild(tempInput); 101 - tempInput.select(); 102 - document.execCommand("copy"); 103 - document.body.removeChild(tempInput); 104 - } 105 - 106 - resultDiv.innerHTML = ` 107 - ✅ Uploaded! URL copied:<br> 108 - <a href="${finalUrl}" target="_blank">${finalUrl}</a><br> 109 - ${file.type.startsWith('image/') ? `<img src="${data.url}" alt="Uploaded Image" style="max-width: 100%; margin-top: 1rem;">` : ''} 110 - `; 111 - 112 - fetchStats(); 113 - } catch (err) { 114 - resultDiv.textContent = "Error: " + err.message; 115 - } 116 - }); 117 - 118 - async function fetchStats() { 119 - try { 120 - const res = await fetch('https://cdn.madebydanny.uk/stats'); 121 - const stats = await res.json(); 122 - document.getElementById('fileCount').textContent = stats.filesUploaded.toLocaleString(); 123 - document.getElementById('bandwidthUsed').textContent = `${stats.totalBandwidth} GB`; 124 - document.getElementById('regionsSupported').textContent = stats.regionsSupported; 125 - } catch { 126 - const statsEl = document.querySelector('.stats'); 127 - if (statsEl) statsEl.innerHTML = '<p>Unable to load CDN stats.</p>'; 128 - } 129 - } 130 - 131 - fetchStats(); 132 - });