-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
92 lines (80 loc) · 3 KB
/
main.js
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
// FETCH ALBUM DATA
const fetchAlbumData = async () => {
try {
const albumURL = "https://api.discogs.com/releases/28742893";
const response = await fetch(albumURL);
const data = await response.json();
console.log("Fetched album data:", data);
return data;
} catch (error) {
console.error("ERROR FETCHING ALBUM DATA:", error);
return null;
}
};
// FETCH LABEL LINK
const fetchLabelLinks = async (albumData) => {
try {
const labelLinksData = fetch(albumData.labels[0].resource_url);
const response = await labelLinksData;
const data = await response.json();
console.log("labelLink data: ", data);
console.log("labelLink to use: ", data.uri);
albumData.labelLink = data.uri;
} catch (error) {
console.error("ERROR FETCHING LABEL DATA:", error);
albumData.labelLink = null;
}
};
// DISPLAY ALBUM INFORMATION
const displayAlbumInfo = async () => {
const albumData = await fetchAlbumData();
if (!albumData) return;
// SET BAND NAME IN FOOTER
document.getElementById("bandName").textContent = albumData.artists[0].name;
console.log("Band Name:", albumData.artists[0].name);
console.log("Album Year:", albumData.year);
console.log("Label:", albumData.labels[0].name);
console.log("labelLink to use:", albumData.labelLink);
// ALBUM ART
const albumArt = document.getElementById("albumArt");
const albumImage = document.createElement("img");
albumImage.src = albumData.images[0].uri;
albumArt.appendChild(albumImage);
// LABEL LINKS
await fetchLabelLinks(albumData);
let labelLinks = "";
if (albumData.labelLink) {
labelLinks = `<a class="league-blue" href="${albumData.labelLink}" target="_blank">${albumData.labels[0].name}</a>`;
}
// ALBUM DETAILS
const albumDetails = document.getElementById("albumDetails");
albumDetails.innerHTML = `
<h2 class="league-blue-lrg"><strong>Album Name:</strong> <a class="league-blue-lrg" href="${albumData.uri}" target="_blank">${albumData.title}</a></h2>
<p><strong>Year:</strong> ${albumData.year}</p>
<p><strong>Label:</strong> ${labelLinks}</p>
`;
// UPDATE TRACKLIST
const tracklist = document.getElementById("tracklist");
tracklist.innerHTML = "<h2>Tracklist</h2>";
albumData.tracklist.forEach((track) => {
tracklist.innerHTML += `<p class="league-blue-sml"><strong>${track.position}.</strong> ${track.title} <small>(${track.duration})</small></p>`;
});
// SHOW CONTENT DIV
const splashscreenDiv = document.getElementById("splashscreen");
const contentDiv = document.getElementById("content");
splashscreenDiv.style.display = "none";
contentDiv.style.display = "block";
};
// CONTENT AFTER SPLASHSCREEN CLICK/ TIMEOUT
const showContent = () => {
displayAlbumInfo();
};
// EVENT LISTENER FOR SPLASHSCREEN IMAGE
document.addEventListener("DOMContentLoaded", () => {
const splashscreenImage = document.getElementById("splashscreen-image");
splashscreenImage.addEventListener("click", showContent);
});
// 10 SECONDS TIMER
setTimeout(() => {
showContent();
}, 2000);