-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
140 lines (124 loc) · 3.78 KB
/
index.html
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
<html>
<head>
<title>OwntonePled</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<style>
body {
border: 2px solid #ccc;
}
.flex-container {
height:99%;
width: 99%;
display: flex;
}
.flex-child {
flex: 1;
margin-top: 0.75%;
margin-left: 1%;
margin-bottom: 0.2%;
padding-top: 1%;
padding-left: 1%;
border: 1px solid #ccc;
overflow: scroll;
}
ul {
padding: 0.75%;
}
.playlist {
height: auto;
width: 95%;
max-height: 50%;
min-height: 10%;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
padding-left: 2.7%;
overflow: scroll;
}
.dragging {
background-color: #eee;
}
#searchInput {
width: 91%;
padding: .75%;
border: 1px solid #ddd;
}
</style>
</head>
<body>
<div class="flex-container">
<div class="flex-child">
<span>
<b>Songs</b>  
<input type="text" id="searchInput" placeholder="Loading">
</span>
<ul id="Songs"></ul>
</div>
<div class="flex-child">
<span id="plSpan" hidden>
<b>Playlists</b>    
<button id="newPlBtn">New playlist</button>  
<button id="cancelPlBtn" hidden>Cancel</button>  
<input id="newPlName" placeholder="Enter playlist name" hidden>
<button id="savePlBtn" hidden>Save changes</button>
</span>
</br></br>
<div id="Playlists"></div>
</div>
</div>
</body>
<script type="module">
import {addSongs, addPlaylists, newPlaylist, savePlaylists} from './songs3.mjs';
window.resizeTo(
window.screen.availWidth * .75,
window.screen.availHeight * .75);
window.addEventListener("beforeunload", async function(e){
navigator.sendBeacon(`${window.location.href}api/pageclose`);
}, false);
var playlists = [];
document.querySelector('#searchInput').addEventListener('keyup', function() {
for (const li of document.getElementById("Songs").getElementsByTagName("li")) {
li.hidden = li.innerText.includes(document.getElementById("searchInput").value) ? false : true;
}
});
document.querySelector('#newPlBtn').addEventListener('click', function(){
document.querySelector('#newPlBtn').hidden = true;
document.querySelector('#newPlName').hidden = false;
document.querySelector('#cancelPlBtn').hidden = false;
});
document.querySelector('#cancelPlBtn').addEventListener('click', function() {
document.querySelector('#newPlName').hidden = true;
document.querySelector('#cancelPlBtn').hidden = true;
document.querySelector('#newPlBtn').hidden = false;
});
document.querySelector('#newPlName').addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
newPlaylist(document.querySelector('#newPlName').value);
document.querySelector('#savePlBtn').hidden = false;
document.querySelector('#newPlName').hidden = true;
document.querySelector('#newPlBtn').hidden = false;
document.querySelector('#cancelPlBtn').hidden = true;
}
});
document.querySelector('#savePlBtn').addEventListener('click', savePlaylists);
const loaderArray = ['Loading', 'Loading .','Loading .', 'Loading .'];
let idx = 1;
const interval = setInterval(
() => {
document.querySelector('#searchInput').placeholder = loaderArray[idx];
idx = idx < 3 ? idx+1 : 0;
}, 500
);
(async function(){
try {
await addSongs(document.querySelector('#Songs'));
await addPlaylists(document.querySelector('#Playlists'));
clearInterval(interval);
document.querySelector('#plSpan').hidden = false;
document.querySelector('#searchInput').placeholder="Search for songs..."
} catch (e) {
console.error(`error: ${JSON.stringify(e, null, 2)}`);
}
})();
</script>
</html>