forked from nf/goplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
162 lines (134 loc) · 4.27 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
<!doctype html>
<head>
<title>goplayer</title>
<style>
body { font-family: Calibri, Helvetica, sans-serif; }
#browser, #playlist { border-radius: 10px; padding: 5px 5px 3px 5px; width: 30%; float: left; margin-right: 15px; height: 900px; overflow: auto; }
#browser a, #playlist a { display: block; cursor: pointer; padding: 2px 4px; border-radius: 5px; overflow: hidden; margin-bottom: 2px; }
#browser { background: #8C9A20; }
#browser a.dir { background: #BECD53; color: black; }
#browser a.file { background: #5A640A; color: white; }
#playlist { background: #881C46; }
#playlist a { background: #C44F7C; }
#playlist a.playing { background: #3B1E6C; color: white; }
#browser a:hover, #playlist a:hover { background: #200A46; color: white; }
#controls { margin-top: 10px; }
#controls a { cursor: pointer; background: #eee; padding: 5px 10px 5px 10px; border-radius: 5px; }
audio { width: 400px; }
</style>
<script src=//www.google.com/jsapi></script>
<script>
var root = "/f/";
var path = [];
var cache = {};
function addToPlaylist(f) {
"use strict";
var $p = $('#playlist');
var playnow = ($p.find('a').length === 0);
var $d = $('<a></a>').text(f.Name).data('file', f).appendTo($p).click(function (e) {
play(e.target);
});
if (playnow) {
$d.click();
}
}
function clickFile(e) {
"use strict";
addToPlaylist($(e.target).data('file'));
}
function addAll() {
"use strict";
$('#browser a.file').each(function (i, e) {
addToPlaylist($(e).data('file'));
});
}
function play(el) {
"use strict";
var name = $(el).data('file').Name;
var path = $(el).data('file').Path;
var url = root + path + '/' + name;
$('#playlist a').removeClass('playing');
$(el).addClass('playing');
$('#player').attr('src', url);
}
function next() {
"use strict";
var $next = $('#playlist a.playing').next();
if ($next.length) {
play($next);
}
}
function populate(files) {
var $b = $('#browser').empty();
function add(i, f) {
if (f.Name[0] === '.' || f.Name[0] === ':' || f.Name.indexOf('opml') > 0 || f.Name === 'library.xml') {
return;
}
var dir = (f.Mode & 040000);
var cl = dir ? "dir" : "file";
f.Path = path.join('/');
$('<a></a>').text(f.Name).data('file', f).addClass(cl).appendTo($b).click(dir ? clickDir : clickFile);
}
files.sort(function (a, b) {
a = a.Name.toLowerCase().replace('the ', '');
b = b.Name.toLowerCase().replace('the ', '');
if (a > b) {
return 1;
}
if (a < b) {
return -1;
}
return 0;
});
$b.append(up());
$.each(files, add);
}
function load(path) {
"use strict";
var url = root + path.join('/');
if (typeof cache[url] !== "undefined") {
populate(cache[url]);
return;
}
$.ajax({
url: url,
dataType: "json",
success: function (data) {
populate(data);
cache[url] = data;
}
});
}
function up() {
"use strict";
return $('<a class=dir>..</a>').click(function () {
path.pop();
load(path);
});
}
function clickDir(e) {
"use strict";
path.push($(e.target).data('file').Name);
load(path);
}
function init() {
"use strict";
load(path);
$('#player').bind('ended', next);
$('#addall').click(addAll);
$('#next').click(next);
}
google.load("jquery", "1");
google.setOnLoadCallback(init);
</script>
</head>
<body>
<audio id=player controls autoplay><p>What? Your browser doesn't support <audio>?! Lame.</p></audio>
<div id=browser></div>
<div id=playlist></div>
<div id=controls>
<a id=addall>Add all</a>
<a id=next>Next</a>
<a onclick="$('#playlist').empty();" id=clear>Clear</a>
</div>
</body>