-
Notifications
You must be signed in to change notification settings - Fork 0
/
mhw3.js
169 lines (124 loc) · 4.75 KB
/
mhw3.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
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
function displayMenu(event)
{
let main = document.querySelector('main');
let footer = document.querySelector('footer');
let menu = document.querySelector('#menu');
let first_ban = document.querySelector('#hamburger [data-index="1"]');
let ham = document.querySelector('#hamburger [data-index="2"]');
let last_ban = document.querySelector('#hamburger [data-index="3"]');
let explanation = document.createElement("p");
explanation.textContent = "Yes, I Know, I was supposed to create the menù, but let's be real, at the end of the day, it doesn't matter";
if(flag === 0){
flag = 1;
main.classList.add('hidden');
footer.classList.add('hidden');
menu.classList.remove('hidden');
first_ban.classList.add('change');
ham.classList.add('change');
last_ban.classList.add('change');
menu.appendChild(explanation);
console.log("menù aperto");
}
else{
flag = 0;
main.classList.remove('hidden');
footer.classList.remove('hidden');
menu.classList.add('hidden');
first_ban.classList.remove('change');
ham.classList.remove('change');
last_ban.classList.remove('change');
menu.innerHTML='';
console.log("menù chiuso");
}
}
function reality()
{
introductionWallpaper.style.backgroundImage = "url(1000YardStare.jpg)";
/*
introductionWallpaper.style.backgroundSize = "cover";
introductionWallpaper.style.backgroundPosition = "center";
*/
}
function expectations()
{
introductionWallpaper.style.backgroundImage = "url(https://hips.hearstapps.com/hmg-prod/images/soldier-of-the-us-army-1st-raider-brigade-walks-past-tanks-news-photo-1694456644.jpg?crop=0.88932xw:1xh;center,top&resize=1200:*)";
}
let flag = 0;
const menu = document.querySelector('#hamburger');
menu.addEventListener('click', displayMenu);
const rabbitHole = document.querySelector('#introduction a');
const introductionWallpaper = document.querySelector('#introduction');
rabbitHole.addEventListener('mouseover', reality);
rabbitHole.addEventListener('mouseout', expectations);
function onJson(json) {
console.log('JSON ricevuto');
console.log(json);
const library = document.querySelector('#album-view');
library.innerHTML = '';
const results = json.tracks.items;
let num_results = results.length;
console.log(num_results);
for(let i=0; i<num_results; i++)
{
console.log(results[i]);
const album_data = results[i]
const title = album_data.name;
const selected_image = album_data.album.images[0].url;
const data_pubblicazione = document.createElement('p');
data_pubblicazione.textContent = 'questo contenuto è stato rilasciato in data ' + album_data.release_date;
const num_brani = document.createElement('p');
num_brani.textContent = 'questo album è composto da ' + album_data.total_tracks + " brani";
const album = document.createElement('div');
album.classList.add('album');
const img = document.createElement('img');
img.src = selected_image;
const caption = document.createElement('span');
caption.textContent = title;
album.appendChild(img);
album.appendChild(caption);
album.appendChild(data_pubblicazione);
album.appendChild(num_brani);
library.appendChild(album);
}
}
function onResponse(response) {
console.log('Risposta ricevuta');
return response.json();
}
function search(event)
{
event.preventDefault();
const album_input = document.querySelector('#album');
const album_value = encodeURIComponent(album_input.value);
console.log('Eseguo ricerca: ' + album_value);
fetch("search_content.php?q="+encodeURIComponent(album_value)).then(onResponse).then(onJson);
event.preventDefault();
}
function onTokenJson(json)
{
console.log(json)
token = json.access_token;
}
function onTokenResponse(response)
{
return response.json();
}
const form = document.querySelector('form');
form.addEventListener('submit', search);
async function fetchData(){
try{
const pokemonName = document.getElementById ("pokemonName").value.toLowerCase();
const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${pokemonName}`);
if(!response.ok){
throw new Error ("Could not fetch resource");
}
const data = await response.json();
const pokemonSprite = data.sprites.front_default;
const imgElement = document.getElementById("pokemonSprite");
imgElement.src = pokemonSprite;
imgElement.style.display = "block";
}
catch(error){
console.error(error);
}
}