-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsongs.html
334 lines (226 loc) · 11.6 KB
/
songs.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<html>
<!--
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
-->
<script type="application/javascript">
var request = new XMLHttpRequest();
function formatParams( params ){
return "?" + Object
.keys(params)
.map(function(key){
return key+"="+encodeURIComponent(params[key])
})
.join("&")
}
params = sessionStorage.getItem('params')
jsonparams = $.parseJSON(params);
formatted_params = formatParams(jsonparams)
// alert(formatted_params)
var request_url = 'https://445z5zpkmd.execute-api.ap-southeast-2.amazonaws.com/beta/my-songs' + formatted_params
request.open('GET', request_url, true);
request.onload = function () {
// Begin accessing JSON data here
var data = JSON.parse(this.response);
const songs = document.getElementById('songs');
const songlist = document.createElement('div');
if (request.status >= 200 && request.status < 400) {
var songdict = {};
var songidorder = [];
data.forEach(song => {
if (! songidorder.includes(song.id)){
songidorder.push(song.id)
}
if (song.id in songdict) {
difficulties = songdict[song.id]['difficulties']
difficultyratings = songdict[song.id]['difficultyratings']
difficulties.push(song.difficulty)
difficultyratings.push(song.difficultyrating)
songdict[song.id]['difficulties'] = difficulties
songdict[song.id]['difficultyratings'] = difficultyratings
} else {
songdict[song.id] = {
"songname" : song.songname,
"author" : song.author,
"coverurl" : song.coverurl,
"difficulties" : [song.difficulty],
"difficultyratings" : [song.difficultyrating],
"downloadurl" : song.downloadurl,
"popularityrating" : song.popularityrating,
"songsubname" : song.songsubname,
"upvotes" : song.upvotes,
"downvotes" : song.downvotes,
"completionratio" : song.completionratio,
"daysold" : song.daysold,
"id" : song.id
}
}
})
var resultsize = Object.keys(songdict).length
if(resultsize == 0){
const heading = document.createElement('h1')
heading.textContent = "No Results Found"
songs.appendChild(heading)
}
const resultcount = document.getElementById('resultcount');
resultcount.textContent = resultsize + " Results"
songidorder.forEach(songid => {
song = songdict[songid]
const row = document.createElement('div');
row.setAttribute('class', 'row');
// create the content in the first column
const col_1 = document.createElement('div');
col_1.setAttribute('class','col-2');
col_1.setAttribute('style','text-align: center');
// create cover object
const cover = document.createElement('img');
cover.src = song['coverurl'];
cover.setAttribute('width','100%')
col_1.appendChild(cover);
col_1.appendChild(document.createElement('hr'));
// create h3 object
const dlh3 = document.createElement('h3');
// create download button object
const dlbtn = document.createElement('a')
dlbtn.setAttribute('type','button')
dlbtn.setAttribute('href',song['downloadurl'])
dlbtn.setAttribute('class','btn btn-link')
dlbtn.textContent = 'Download'
dlh3.appendChild(dlbtn)
// create bsr link object
const bsrlink = document.createElement('a');
bsrlink.setAttribute('class','badge badge-info')
bsrlink.setAttribute('href','javascript:;')
bsrlink.setAttribute('style','padding-top:8px;padding-bottom:8px')
bsrlink.setAttribute('data-toggle','tooltip')
bsrlink.setAttribute('data-placement','top')
bsrlink.setAttribute('title','Copy to clipboard')
bsrlink.setAttribute('onclick','copytxt(this)')
bsrlink.textContent = '!bsr ' + song['id']
dlh3.innerHTML = dlh3.innerHTML + " "
dlh3.appendChild(bsrlink)
col_1.appendChild(dlh3)
row.appendChild(col_1)
// create the second column
const col_2 = document.createElement('div');
col_2.setAttribute('class','col');
// Add the songname
const songname = document.createElement('h2')
songname.textContent = song['songname'] + ' '
col_2.append(songname)
// Add the songsubname
const songsubname = document.createElement('h5')
songsubname.textContent = song['songsubname']
col_2.append(songsubname)
col_2.append(document.createElement('hr'))
// Add the author
const author = document.createElement('p')
author.textContent = 'Mapped by: ' + song['author']
col_2.appendChild(author)
// Add the difficulty rating
for (var i = 0; i < song['difficultyratings'].length; i++) {
// Add the difficulty
const difficulty = document.createElement('span')
difficulty.setAttribute('class','badge badge-secondary')
difficulty.setAttribute('style','vertical-align: middle;line-height: 20px;margin-bottom:10px;margin-top:10px')
difficulty.textContent = song['difficulties'][i]
// songname.appendChild(difficulty)
const difficultyrow = document.createElement('div')
difficultyrow.setAttribute('class','row')
const difficultytxt = document.createElement('div')
// difficultytxt.textContent = 'Difficulty: '
difficultytxt.setAttribute('class','col-md-1')
// difficultytxt.setAttribute('style','vertical-align: middle;line-height: 40px;padding-bottom:10px')
difficultytxt.appendChild(difficulty)
difficultyrow.appendChild(difficultytxt)
const starcol = document.createElement('div')
starcol.setAttribute('class','col-md')
//data-toggle="tooltip" data-placement="bottom" title="(Notecount - Dotnotes) / Song Length (seconds) * (1 - Player Completion Percentage)"
const stardiv = document.createElement('div')
var diffrating = song['difficultyratings'][i]
if (diffrating > 15){
diffrating = 15
}
const stardivwidth = 600 / 15 * diffrating
stardiv.setAttribute('style','position: absolute; top: 0; left:0;padding-bottom:10px;overflow:hidden;width:'+stardivwidth+'px')
const starimg = document.createElement('img')
starimg.setAttribute('src','starssmall.png')
starimg.setAttribute('data-toggle','tooltip')
starimg.setAttribute('data-placement','bottom')
starimg.setAttribute('title','Difficulty Rating ' + song['difficultyratings'][i])
const blackstarimg = document.createElement('img')
blackstarimg.setAttribute('src','blackstars.png')
blackstarimg.setAttribute('data-toggle','tooltip')
blackstarimg.setAttribute('data-placement','bottom')
blackstarimg.setAttribute('title','Difficulty Rating ' + song['difficultyratings'][i])
const blackstardiv = document.createElement('div')
blackstardiv.setAttribute('style','position: absolute; top: 0; left:0;padding-bottom:10px;overflow:hidden')
blackstardiv.appendChild(blackstarimg)
stardiv.appendChild(starimg)
starcol.appendChild(blackstardiv)
starcol.appendChild(stardiv)
difficultyrow.appendChild(starcol)
col_2.appendChild(difficultyrow)
}
// create inner row
const innerrow = document.createElement('div')
innerrow.setAttribute('class','row')
// Add popularity rating
const popularityrating = document.createElement('div')
popularityrating.setAttribute('class','col')
const prp = document.createElement('p')
prp.textContent = 'Popularity Rating: ' + Math.round(song['popularityrating']) + '%'
popularityrating.appendChild(prp)
innerrow.appendChild(popularityrating)
// Add completion ratio
const completionratio = document.createElement('div')
completionratio.setAttribute('class','col')
const crp = document.createElement('p')
crp.textContent = 'Player Completion: ' + (Math.round(song['completionratio'] * 10000)/100) + '%'
completionratio.appendChild(crp)
innerrow.appendChild(completionratio)
// Add up/down votes
const updownvotes = document.createElement('div')
updownvotes.setAttribute('class','col')
const udvp = document.createElement('p')
udvp.innerHTML = '<p><i class="fas fa-thumbs-up"></i> '+song['upvotes']+' <i class="fas fa-thumbs-down"></i> '+song['downvotes']+'</p>'
updownvotes.appendChild(udvp)
innerrow.appendChild(updownvotes)
// Add days old
const daysold = document.createElement('div')
daysold.setAttribute('class','col')
const dop = document.createElement('p')
dop.textContent = 'Days Old: ' + song['daysold']
daysold.appendChild(dop)
innerrow.appendChild(daysold)
col_2.appendChild(innerrow)
// Add the 2nd column to the row
row.appendChild(col_2)
// add the row to the songs div
songlist.appendChild(row)
songlist.appendChild(document.createElement('hr'))
});
document.getElementById("songs").innerHTML = ""
songs.appendChild(songlist)
} else {
console.log('error');
}
}
request.send();
</script>
<body>
<div class="container">
<div class="card">
<div id="resultcount" class="card-header">Getting Results</div>
<div id="songs" class="card-body">
<p>Attempting to load results...</p>
<div class="progress">
<div class="progress-bar progress-bar-striped bg-info progress-bar-animated" style="width: 100%"></div>
</div>
</div>
</div>
</div>
</body>
</html>