-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfavorites.js
58 lines (51 loc) · 2.8 KB
/
favorites.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
if (localStorage.getItem("currentUser") == undefined) {
document.getElementById('conect').innerText = 'Sorry, but you are not logged in. Will connect and we will show your favorites songs';
}
showFavoriteList()
//מציג את המועדפים
function showFavoriteList() {
// debugger;
var usersList = JSON.parse(localStorage.getItem("users"))
var user = localStorage.getItem("currentUser")
for (let index = 0; index < usersList.length; index++) { //עובר כל כל המשתמשים
if (usersList[index].userId == user) { //מחפש את המשתמש הנוכחי
for (let index2 = 0; index2 <= usersList[index].favorites.length; index2++) { //עוברת על המערך של המועדפים של המשתמש
if (usersList[index].favorites.length == 0) {
document.getElementById('conect').innerText = 'your favorite list is empty';
}
else {
for (let index3 = 0; index3 < songsList.length; index3++) {//במקביל עוברת גם על רשימת כל השירים
if (songsList[index3].idSong == usersList[index].favorites[index2]) {//אם מצא ששיר שווה לשיר לפי הID
document.getElementById('favorite').innerHTML += "<div>"
+ singersList[songsList[index3].id - 1].singer + ' '
+ songsList[index3].name
+'<div><img src="./img/delete.png" id="deleteFromFavorite" onclick="deleteFromFavorite(' + songsList[index3].idSong + ')" width="40px"></img></div>'
+"</div>"
+"<audio controls id='audioFan'><source src='./song/" + songsList[index3].id + "/" + songsList[index3].src + ".mp3'></audio>"
}
}
}
}
break;
}
}
}
//מוחק שיר מהמועדפים
function deleteFromFavorite(element) {
// debugger;
var usersList = JSON.parse(localStorage.getItem("users"))
var user = localStorage.getItem("currentUser")
for (let index = 0; index < usersList.length; index++) { //עובר כל כל המשתמשים
if (usersList[index].userId == user) { //מחפש את המשתמש הנוכחי
for (let index2 = 0; index2 < usersList[index].favorites.length; index2++) {
if (usersList[index].favorites[index2] == element) {
debugger;
usersList[index].favorites.splice(index2, 1);
localStorage.setItem("users", JSON.stringify(usersList))
document.getElementById('favorite').innerHTML = "";
showFavoriteList();
}
}
}
}
}