/*function toggleNav() { var x = document.getElementById("navlinks"); if (x.style.display === "block") { x.style.display = "none"; } else { x.style.display = "block"; } }*/ function toggleNav() { const menu = document.getElementById("navlinks"); menu.classList.toggle("open"); } function removeDiacritics(str) { return str.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); } function searchList() { var input, filter, ul, li, a, i, txtValue; input = document.getElementById("search"); input.focus({ preventScroll: true }); filter = input.value.toUpperCase(); filter = removeDiacritics(input.value.toUpperCase()); ul = document.getElementById("links"); li = ul.getElementsByTagName("li") for (i = 0; i < li.length; i++) { a = li[i].getElementsByTagName("a")[0]; txtValue = a.textContent || a.innerText; if (txtValue.toUpperCase().indexOf(filter) > -1) { li[i].style.display = ""; } else { li[i].style.display = "none"; } } } function scrollSearch() { var input; input = document.getElementById("search"); input.addEventListener("click", () => { document.getElementById("search").scrollIntoView({ behavior: "smooth", block: "start" }); }); } function handleFocus() { var input; input = document.getElementById("search"); setTimeout(() => { input.scrollIntoView({ behavior: "smooth", block: "start" }); }, 300); } function sortByName() { const ul = document.getElementById("links"); const items = Array.from(ul.querySelectorAll("li")); items.sort((a, b) => { const textA = a.textContent.toLowerCase(); const textB = b.textContent.toLowerCase(); return textA.localeCompare(textB); }); items.forEach(li => ul.appendChild(li)); } function sortByDate() { const ul = document.getElementById("links"); const items = Array.from(ul.querySelectorAll("li")); items.sort((a, b) => { const dateA = new Date(a.dataset.date); const dateB = new Date(b.dataset.date); return dateB - dateA; // newest first }); items.forEach(li => ul.appendChild(li)); } function sortList() { const ul = document.getElementById("links"); const items = Array.from(ul.querySelectorAll("li")); const sortType = document.getElementById("sortSelect").value; items.sort((a, b) => { const nameA = a.textContent.trim().toLowerCase(); const nameB = b.textContent.trim().toLowerCase(); const dateA = new Date(a.dataset.date); const dateB = new Date(b.dataset.date); switch (sortType) { case "az": return compareDanish(nameA, nameB); case "za": return compareDanish(nameB, nameA); case "newest": return dateB - dateA; case "oldest": return dateA - dateB; default: return 0; } }); items.forEach(li => ul.appendChild(li)); } function normalizeDanish(str) { return str .toLowerCase() .replace(/aa/g, "az"); // push "aa" BEFORE æ/ø/å } function customSortKey(str) { return str .toLowerCase() .replace(/æ/g, "{") .replace(/ø/g, "|") .replace(/å/g, "}"); } function compareDanish(a, b) { const keyA = customSortKey(a); const keyB = customSortKey(b); if (keyA < keyB) return -1; if (keyA > keyB) return 1; return 0; } function formatRelativeDate(dateString) { const inputDate = new Date(dateString); const now = new Date(); const diffMs = now - inputDate; const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24)); if (diffDays === 0) return "Today"; if (diffDays === 1) return "Yesterday"; if (diffDays < 7) return `${diffDays} days ago`; if (diffDays < 30) return `${Math.floor(diffDays / 7)} weeks ago`; if (diffDays < 365) return `${Math.floor(diffDays / 30)} months ago`; return `${Math.floor(diffDays / 365)} years ago`; }