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
|
/*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`;
}
|