-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
328 lines (298 loc) · 8.01 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
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
<!-- \<!doctype html> -->
<html>
<head>
<title>Deeshu mp3 printer</title>
<meta charset="utf-8" />
<style type="text/css">
html {
overflow-y: auto;
}
.child-elements {
pointer-events: none;
}
a{
pointer-events: auto;
}
#nickname{
pointer-events: auto;
font-family:Arial, Helvetica, sans-serif;
color:#D0B11B;
font-size:12px;
text-shadow: 1px 1px 0px #5a4d0c;
background:#222;
border:#D0B11B 1px solid;
margin-bottom: 2em;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
-moz-box-shadow: 0px 0px 3px 0px #D0B11B;
-webkit-box-shadow: 0px 0px 3px 0px #D0B11B;
box-shadow: 0px 0px 3px 0px #D0B11B;
text-align: center;
}
#foot{
padding: 1em;
}
body {
text-align: center;
margin: 0px;
width: 100%;
box-shadow:inset 1px 1px 40px 1px rgba(0,0,0,.45);
background:#000;
color:#D0B11B;
background-size:cover;
overflow:hidden;
/*Below is footer magic*/
display: flex;
min-height: 100vh;
flex-direction: column;
}
#overlay {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
width: 100%;
height: 100%;
z-index: 6;
display: none;
content: "";
position: fixed;
background:rgba(0,0,0,.75);
text-align:center;
font-weight: bold;
text-align: center;
color: #D0B11B;
border: 10px dashed #D0B11B;
cursor: default;
font-size: 3em;
}
#overlay > p {
position: absolute;
top: 50%;
left: 0;
right: 0;
margin-top: -1em;
}
#page_body {
padding: 2em;
/*Footer magic*/
flex: 1;
}
</style>
<link rel="stylesheet" type="text/css" href="{{ static_url("table.css") }}">
<link rel="stylesheet" type="text/css" href="{{ static_url("progress.css") }}">
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="{{ static_url("cookie.js") }}"></script>
<script>
function disclaimer(){
$("#disclaimer").text(cookies[cookieindex]);
cookieindex++;
cookieindex%=cookies.length;
}
function addTable(list, position) {
var table = $('<table></table>').addClass('printtable');
var headerRow = $('<tr></tr>');
var headers = ['File','Progress','User', 'Prio'];
for(i=0; i<headers.length; i++){
var header = $('<th></th>').text(headers[i]);
headerRow.append(header);
}
table.append(headerRow);
for(i=0; i<list.length; i++){
var curr = list[i];
var row = $('<tr></tr>');
var prefix = $('<code></code>');
if (curr['nick'] == $('#nickname').val() ){
prefix.append("[")
$('<a>',{
text: 'X',
mrl: curr['mrl'].toString(),
title: 'Cancel song',
href: '#',
click: function(event) {
event.preventDefault();
var skipMessage={
'type':'skip',
'mrl': $(event.target).attr('mrl')
};
ws.send(JSON.stringify(skipMessage));
}
}).appendTo(prefix);
prefix.append("]")
}
var contents = [
' <a target="_blank" href="'+encodeURI(curr['mrl'])+'"download="'+curr['filename']+'">'
+curr['filename']+"</a>",
"<div class='meter'><span id='p"+i+"' style='width: 0%'></span></div>",
curr['nick']+"("+curr['address']+")",
curr['prio']
]
for(o=0; o<contents.length; o++){
var cell = $('<td></td>').html(contents[o]);
if(o == 0){
cell.prepend(prefix);
}
row.append(cell);
}
table.append(row);
}
$('#printlist').html(table).delay(5).promise().done(
function() {
$("#p0").css({width:position*100+"%"});
$('#printlist').fadeTo(400, 1);
});
}
// log function
log = function(data){
$("div#terminal").prepend("</br>" +data);
console.log(data);
};
var unfading = false;
var child = false;
var lastcancel = 0;
function FileDragHover(e) {
e.stopPropagation();
e.preventDefault();
if(e.type == "dragover"){
$("#overlay").fadeIn(150);
lastcancel = e.timeStamp;
unfading = false
} else if (e.type == "dragleave" && child == false){
unfading = true
setTimeout(function(){
if(lastcancel < e.timeStamp && unfading && !child){
unfading = false;
$("#overlay").fadeOut(150);
}
}, 400);
}
}
function ChildFileDragHover(e) {
e.stopPropagation();
e.preventDefault();
lastcancel = e.timeStamp;
unfading = false
$("#overlay").fadeIn(0);
if(e.type == "dragover"){
cildd = true;
} else if (e.type == "dragleave"){
child = false;
}
}
function FileSelectHandler(e) {
e.stopPropagation();
e.preventDefault();
$("#overlay").fadeOut(150);
unfading = false;
lastcancel = e.timeStamp;
var files = e.target.files || e.originalEvent.dataTransfer.files;
if (files.length == 0){
ParseLink(e.originalEvent.dataTransfer.getData('Text'));
}
else if (files.length > 3) {
alert("Please, no more than 3 at a time.");
}
else{
for (var i = 0, f; f = files[i]; i++) {
ParseFile(f);
}
}
}
function ParseFile(file) {
if(file.type.startsWith("audio")){
var req = new XMLHttpRequest();
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4 && req.status == 200) {
}
};
req.open('post', 'upload', true)
req.setRequestHeader("filename", file.name);
req.setRequestHeader("nick", $('#nickname').val() );
req.send(file);
}
else {
alert("Please, only audio files.");
}
}
function ParseLink(link) {
linkToUpload={
"type":"link",
"nick":$('#nickname').val(),
"link":link
};
ws.send(JSON.stringify(linkToUpload));
}
// begin page load code
var ws;
$(document).ready(function () {
$("div#printlist").hide();
$("#connection").show();
$('#nickname').hide();
nick = getCookie("nick");
if (nick != null){
$('#nickname').val(nick);
}
$('#nickname').on("propertychange change keyup paste input", function(evt) {
setCookie("nick", $('#nickname').val())
});
setInterval(disclaimer, 120);
// Websocket stuff
ws = new WebSocket("ws://" + window.location.host + "/ws");
ws.onmessage = function(evt) {
var message = JSON.parse(evt.data);
switch(message.type){
case 'fallback':
$("#printlist").html(message.filename);
break;
case 'list':
$("div#printlist").fadeTo(400, 0).promise().done(
function() {
addTable(message.list, message.position);
});
break;
case 'progress':
$("#p0").animate({width:message.position*100+"%"}, 100);
break;
}
};
ws.onclose = function(evt) {
$("div#printlist").fadeOut("slow");
$('#nickname').hide("slow");
$("#connection").show("slow");
};
ws.onopen = function(evt) {
$("div#printlist").fadeIn("slow");
$('#nickname').show("slow");
$("#connection").hide("slow");
};
$("html").on("dragover", FileDragHover);
$("html").on("dragleave", FileDragHover);
$("html").on("drop", FileSelectHandler);
$(".child-elements").on("dragover", ChildFileDragHover);
$(".child-elements").on("dragleave", ChildFileDragHover);
$(".child-elements").on("drop", FileSelectHandler);
});
</script>
</head>
<body>
<div id="overlay" class="child-elements">
<p>
Drop files or youtube links here to upload!
</p>
</div>
<section id = "page_body" class="child-elements">
<h1>Welcome to the Deeshu mp3 printer</h1>
<input id="nickname" type ="text" placeholder="Name goes here...">
<div id="connection_details">
<label id="connection">NO CONNECTION<br>Wait a while, or refresh the page.</label>
</div>
<div id ="printlist">
</div>
<div id="terminal">
</div>
</section>
<div id="foot">
<pre><code id="disclaimer"></code></pre>
</div>
</body>
</html>