-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
241 lines (172 loc) · 6.27 KB
/
script.js
File metadata and controls
241 lines (172 loc) · 6.27 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
const baseURL = 'https://fdnd.directus.app/';
const endpointMe = 'items/person/194';
const myURL = baseURL + endpointMe;
getMyAvatar();
getMyName();
getMyImage();
let listItem = document.querySelector("header li:nth-of-type(4) img");
let h1 = document.querySelector("h1");
function getMyAvatar() {
getData(myURL).then(data => {
const myData = data.data;
const myAvatar = myData.avatar;
listItem.src = myAvatar;
listItem.alt = "User Avatar";
})
}
function getMyName() {
getData(myURL).then(data => {
// console.log(data.data);
const myData = data.data;
let myName = myData.nickname;
// console.log(myName);
h1.textContent = myName;
});
}
function setFavicon(avatarUrl) {
console.log("setFavicon() is aangeroepen!");
let link = document.querySelector('link[rel="icon"]');
if (!link) {
console.log("Geen bestaande favicon gevonden, nieuwe aanmaken...");
link = document.createElement('link');
link.rel = 'icon';
link.type = 'image/x-icon';
document.head.appendChild(link);
} else {
console.log("Bestaande favicon gevonden, wordt geüpdatet...");
}
console.log("Nieuwe favicon URL:", avatarUrl);
link.href = avatarUrl;
}
// Roep de functie aan om te testen
setFavicon("https://example.com/favicon.ico");
function setFavicon(avatarUrl) {
// Maak de <link> tag aan als deze nog niet bestaat
let link = document.querySelector('link[rel="icon"]');
if (!link) {
link = document.createElement('link');
link.rel = 'icon';
document.head.appendChild(link);
}
// Zet de favicon naar de avatar URL
link.href = avatarUrl;
}
getData(myURL).then(data => {
const myData = data.data;
const myAvatar = myData.avatar; // Zorg ervoor dat je de juiste property gebruikt voor de avatar
setFavicon(myAvatar); // Zet de avatar als de favicon
});
// const myImgDialog = document.querySelector('.dialog-content');
getMyImage();
// function getMyImage() {
// getData(myURL).then( data => {
// console.log(data.data);
// const myData = data.data;
// const customData = JSON.parse(myData.custom);
// let myPhotos = myData.custom.photos;
// console.log(myPhotos)
// });
// }
function getMyImage() {
getData(myURL).then(data => {
// console.log(data.data);
const myData = data.data;
// Als custom een string is, moet je het parsen naar een object
const customData = JSON.parse(myData.custom);
// Haal de foto's uit customData
let myPhotos = customData.photos;
// console.log(myPhotos);
// Zoek het element in de HTML waar je de foto's wilt plaatsen
myPhotos.forEach(photo => {
let wrapper = document.createElement('div');
let img = document.createElement('img');
img.src = photo.image_url;
img.alt = photo.description || 'Photo';
img.onload = function () {
if (img.naturalWidth > img.naturalHeight) {
wrapper.classList.add('landscape');
} else {
}
};
wrapper.appendChild(img);
photoContainer.appendChild(wrapper);
});
}).catch(error => {
console.error('Er is een fout opgetreden:', error);
});
}
// function searchFunction(event) {
// event.preventDefault(); // Zorg ervoor dat het formulier niet opnieuw laadt.
// const query = document.querySelector('form > input').value.toLowerCase();
// const sections = document.querySelectorAll('section, div, article'); // Je kunt dit aanpassen afhankelijk van de HTML-structuur van je website.
// let results = [];
// sections.forEach(section => {
// // Zoek naar tekstinhoud in de sectie
// if (section.textContent.toLowerCase().includes(query)) {
// results.push(section);
// }
// // Zoek naar afbeeldingen met alt-tekst die overeenkomt met de zoekterm
// const images = section.querySelectorAll('img');
// images.forEach(img => {
// if (img.alt.toLowerCase().includes(query)) {
// results.push(img);
// }
// });
// });
// // Toon de resultaten (je kunt dit aanpassen naar hoe je de resultaten wilt weergeven)
// if (results.length > 0) {
// alert("Resultaten gevonden: " + results.length);
// console.log(results);
// } else {
// alert("Geen resultaten gevonden.");
// }
// }
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: no-preference)").matches;
// Als de voorkeur voor minder beweging uitstaat, toon de video
if (prefersReducedMotion) {
const video = document.querySelector("video");
video.style.display = "block"; // Video zichtbaar maken
document.body.style.backgroundImage = 'none'; // Achtergrondafbeelding verbergen
let btn = document.getElementById("myBtn");
btn.style.display = "block"; // Knop zichtbaar maken
let h1 = document.querySelector("h1");
let h2 = document.querySelectorAll("h2");
h1.style.color = "white";
h2.forEach(h2 => {
h2.style.color = "white";
})
function myFunction() {
if (video.paused) {
video.play();
btn.innerHTML = "Pause video";
} else {
video.pause();
btn.innerHTML = "Play video";
}
}
}
document.querySelector(".closeDialog").addEventListener("click", function() {
document.getElementById("myDialog").close();
});
// document.querySelectorAll(".dialog section ul li").forEach(item => {
// item.addEventListener("click", () => {
// item.classList.add("revealed");
// });
// });
document.querySelectorAll(".dialog section ul li").forEach(item => {
item.addEventListener("click", () => {
console.log("hi");
item.classList.add("is-revealed"); // Maak de tekst zichtbaar en laat de deksel wegvliegen
});
});
async /*9*/ function getData(URL) {
return ( //8
fetch(URL) //1
.then( //2
response /*3*/ => response.json() //4
)
.then( //5
jsonData /*6*/ => { return jsonData } //7
)
);
}