-
Notifications
You must be signed in to change notification settings - Fork 0
/
mp3.js
193 lines (137 loc) · 5.02 KB
/
mp3.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
const preSong = document.getElementById('preFile');
const lastSong = document.getElementById('nextFile');
const audio = document.getElementById('audio');
const body = document.getElementsByTagName('body')[0];
const play = document.getElementById('play');
const btnTheme = document.getElementById('darkTheme');
const container = document.getElementById('container');
const topContainer = document.getElementById('topContainer');
const spanHeadline = document.getElementById('spanHeadline');
let songIndex = 0;
// song titles array
const songs = ['Kalimba','Maid with the Flaxen Hair','Sleep Away'];
// font and background color arrays
const bgColor = ['#ADD8E6','#C89D7C','#FFD580'];
const fontColor = ['#E0FFFF','#FBD0AF','#FFFFB3'];
loadSong(songs[songIndex]);
// The loadLong function generates the song title, the background and font color and also the transition
function loadSong(song){
audio.src = `audio/${song}.mp3`;
play.innerHTML = songs[songIndex];
play.style.background = bgColor[songIndex];
play.style.color = fontColor[songIndex];
body.style.background = bgColor[songIndex];
body.style.transition = '1s';
preSong.style.color = bgColor[songIndex];
lastSong.style.color = bgColor[songIndex];
btnTheme.style.color = bgColor[songIndex];
spanHeadline.classList.add('span');
}
// Event listener for previous and next song
preSong.addEventListener('click', prevSong);
lastSong.addEventListener('click', nextSong);
// Previous song
function prevSong() {
songIndex--;
if (songIndex < 0) {
songIndex = songs.length - 1;
}
loadSong(songs[songIndex]);
setTimeout(() => {
audio.play();
}, 500);
}
// Next song
function nextSong() {
songIndex++;
if (songIndex > songs.length - 1) {
songIndex = 0;
}
loadSong(songs[songIndex]);
setTimeout(() => {
audio.play();
}, 500);
}
let statusTheme = false;
btnTheme.addEventListener('click', () => {
/*
if statusTheme is false, the darkTheme function switch the container to the dark theme.
The innerText takes a new value (sun with cloud) and we add hover effects on the btn-s.
At the end, the statustheme varible will be set to true.
*/
if(statusTheme === false){
darkTheme();
btnTheme.innerText = '⛅️';
preSong.addEventListener('mouseenter', () => {
preSong.style.background = '#222';
});
lastSong.addEventListener('mouseenter', () => {
lastSong.style.background = '#222';
});
preSong.addEventListener('mouseleave', () => {
preSong.style.background = '#333';
});
lastSong.addEventListener('mouseleave', () => {
lastSong.style.background = '#333';
});
statusTheme = true;
}
else
{
// By statusTheme true, will activate the lightTheme function with the moon sign
lightTheme();
btnTheme.innerText = '🌙';
preSong.addEventListener('mouseenter', () => {
preSong.style.background = '#ddd';
});
lastSong.addEventListener('mouseenter', () => {
lastSong.style.background = '#ddd';
});
preSong.addEventListener('mouseleave', () => {
preSong.style.background = '#eee';
});
lastSong.addEventListener('mouseleave', () => {
lastSong.style.background = '#eee';
});
// after switching the theme, we set the statusTheme to false
statusTheme = false;
}
});
// the dark theme function
function darkTheme(){
container.style.background = '#333'
container.style.boxShadow = '0 0 25px #111, inset 0 0 10px #111';
container.style.border = '5px solid #333';
container.style.transition = '1.5s';
topContainer.style.background = 'rgb(56,56,56)';
topContainer.style.boxShadow = '0 0 15px #111';
play.style.border = '5px solid #444';
play.style.boxShadow = '0 0 15px #111, inset 0 0 8px #333';
preSong.style.background = '#333';
preSong.style.border = '3px solid #333';
preSong.style.boxShadow = '0 0 15px #111';
lastSong.style.border = '3px solid #333';
lastSong.style.background = '#333';
lastSong.style.boxShadow = '0 0 15px #111';
audio.classList.add('currentPartDark');
spanHeadline.style.textShadow = '0 0 3px #111';
}
// the light theme function
function lightTheme(){
container.style.background = 'linear-gradient( #ccc, whitesmoke)'
container.style.boxShadow = '0 0 30px #999, inset 0 0 6px #999';
container.style.border = '5px solid #fff';
container.style.transition = '1.5s';
topContainer.style.background = 'linear-gradient( #ccc, whitesmoke)';
topContainer.style.boxShadow = '0 2px 14px #999, 0 2px 14px #999';
play.style.border = '4px solid #eee';
play.style.boxShadow = '0 0 14px #777, inset 0 0 14px #777';
preSong.style.background = '#fff';
preSong.style.border = '3px solid #eee';
preSong.style.boxShadow = '0 0 14px #aaa, 0 0 14px #aaa';
lastSong.style.background = '#fff';
lastSong.style.border = '3px solid #eee';
lastSong.style.boxShadow = '0 0 14px #aaa, 0 0 14px #aaa';
audio.classList.remove('currentPartDark');
spanHeadline.style.textShadow = '0 3px 5px #777, 0 3px 5px #777';
}