-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
152 lines (145 loc) · 4 KB
/
script.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
console.log("welcome to Spotify");
let songindex = 0;
let audio = new Audio("songs/1.mp3");
let replace = Array.from(document.getElementsByClassName("songrec"));
let gif = document.getElementById("gif");
let btitle = document.getElementById("updatetitle");
let next = document.getElementById("next");
let progress = document.getElementById("progresshere");
let danishhere = document.getElementsByClassName("danish");
let play = document.getElementById("play");
let songs = [
{
songName: "Ballpoint - Walk Slowly",
filePath: "songs/1.mp3",
cover: "img/covers/1.jpg",
time: "2:17",
},
{
songName: "JONY, HammAli & Navai - Без тебя я не я",
filePath: "songs/2.mp3",
cover: "img/covers/2.jpg",
time: "3:21",
},
{
songName: "UpsideDown - Wut Wut",
filePath: "songs/3.mp3",
cover: "img/covers/3.jpg",
time: "2:19",
},
{
songName: "DJ Trac - Shaab _Justice League",
filePath: "songs/4.mp3",
cover: "img/covers/4.jpg",
time: "2:16",
},
{
songName: "Cheel _ Violet Vape",
filePath: "songs/5.mp3",
cover: "img/covers/5.jpg",
time: "3:01",
},
];
btitle.innerHTML = songs[songindex].songName;
replace.forEach((element, i) => {
element.getElementsByTagName("img")[0].src = songs[i].cover;
element.getElementsByTagName("span")[0].innerHTML = songs[i].songName;
element.getElementsByClassName("songTime")[0].innerHTML = songs[i].time;
});
function removePauseIcon() {
for (element of danishhere) {
element.classList.add("fa-play-circle");
element.classList.remove("fa-pause-circle");
}
}
function playhere() {
play.classList.add("fa-pause-circle");
play.classList.remove("fa-play-circle");
gif.style.opacity = "1";
audio.play();
}
function pausehere() {
play.classList.remove("fa-pause-circle");
play.classList.add("fa-play-circle");
gif.style.opacity = "0";
audio.pause();
removePauseIcon();
}
audio.addEventListener("timeupdate", () => {
progress.value = (audio.currentTime / audio.duration) * 100;
});
progress.addEventListener("change", () => {
audio.currentTime = (progress.value * audio.duration) / 100;
});
play.addEventListener("click", () => {
if (audio.paused || audio.currentTime <= 0) {
playhere();
danishhere[songindex].classList.add("fa-pause-circle");
danishhere[songindex].classList.remove("fa-play-circle");
} else {
pausehere();
}
});
let finalSongName; // for remember last song
Array.from(document.getElementsByClassName("danish")).forEach(
(element, index) => {
element.addEventListener("click", (d, i = index) => {
if (element.classList.contains("fa-pause-circle")) {
pausehere();
return;
}
songindex = i;
finalSongName = songs[i].songName
if (btitle.innerHTML != finalSongName) {
audio.src = `songs/${songindex + 1}.mp3`;
btitle.innerHTML = finalSongName;
}
playhere();
removePauseIcon();
d.target.classList.remove("fa-play-circle");
d.target.classList.add("fa-pause-circle");
});
}
);
next.addEventListener("click", () => {
if (songindex >= 4) {
songindex = 0;
} else {
songindex += 1;
}
audio.src = `songs/${songindex + 1}.mp3`;
audio.currentTime = 0;
playhere();
removePauseIcon();
btitle.innerHTML = songs[songindex].songName;
danishhere[songindex].classList.add("fa-pause-circle");
danishhere[songindex].classList.remove("fa-play-circle");
});
back.addEventListener("click", () => {
if (songindex <= 0) {
songindex = 0;
} else {
songindex -= 1;
}
audio.src = `songs/${songindex + 1}.mp3`;
audio.currentTime = 0;
btitle.innerHTML = songs[songindex].songName;
playhere();
removePauseIcon();
danishhere[songindex].classList.add("fa-pause-circle");
danishhere[songindex].classList.remove("fa-play-circle");
});
audio.addEventListener("ended", () => {
if (songindex >= 4) {
songindex = 0;
} else {
songindex += 1;
}
audio.src = `songs/${songindex + 1}.mp3`;
audio.currentTime = 0;
btitle.innerHTML = songs[songindex].songName;
playhere();
removePauseIcon();
danishhere[songindex].classList.add("fa-pause-circle");
danishhere[songindex].classList.remove("fa-play-circle");
});