2018-09-13 14:22:27 -04:00
|
|
|
var httpRequest
|
2018-09-14 08:02:24 -04:00
|
|
|
|
|
|
|
function load() {
|
|
|
|
document.getElementById('player').addEventListener('ended', function() {
|
|
|
|
if (!document.getElementById('shuffle').checked) { return; }
|
|
|
|
httpRequest = new XMLHttpRequest();
|
|
|
|
httpRequest.onreadystatechange = function() {
|
|
|
|
if (httpRequest.readyState !== XMLHttpRequest.DONE) { return; }
|
|
|
|
if (httpRequest.status !== 200) { return; }
|
|
|
|
let track = httpRequest.responseText;
|
|
|
|
change_track(track);
|
|
|
|
}
|
|
|
|
httpRequest.open('GET', '/musik/get_shuffle', true);
|
|
|
|
httpRequest.send();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-13 14:22:27 -04:00
|
|
|
function navigate(item) {
|
|
|
|
if (/\..{3,5}$/.test(item)) {
|
2018-09-14 08:02:24 -04:00
|
|
|
select_track(item);
|
2018-09-13 14:22:27 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
get_dir(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-14 08:02:24 -04:00
|
|
|
function select_track(item) {
|
2018-09-13 14:22:27 -04:00
|
|
|
let cd = document.getElementById('currentDirectory').innerText;
|
|
|
|
let track = cd + item;
|
2018-09-14 08:02:24 -04:00
|
|
|
change_track(track);
|
|
|
|
}
|
|
|
|
|
|
|
|
function change_track(track) {
|
2018-09-13 14:22:27 -04:00
|
|
|
let source = document.getElementById('stream');
|
|
|
|
source.src = '/musik/stream' + track;
|
|
|
|
let player = document.getElementById('player');
|
|
|
|
player.load();
|
|
|
|
player.play();
|
|
|
|
document.getElementById('nowPlaying').innerHTML = track;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_dir(item) {
|
|
|
|
let cd = document.getElementById('currentDirectory').innerText;
|
|
|
|
item = cd + item;
|
|
|
|
item = item.replace(/\.\./g, 'DOTDOT');
|
|
|
|
httpRequest = new XMLHttpRequest();
|
|
|
|
httpRequest.onreadystatechange = update_nav_items;
|
|
|
|
httpRequest.open('GET', '/musik/get_dir' + item, true);
|
|
|
|
httpRequest.send();
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_nav_items() {
|
|
|
|
if (httpRequest.readyState !== XMLHttpRequest.DONE) { return; }
|
|
|
|
if (httpRequest.status !== 200) { return; }
|
|
|
|
nav_items = JSON.parse(httpRequest.responseText);
|
|
|
|
document.getElementById('currentDirectory').innerText = nav_items.shift();
|
|
|
|
let html_str = '';
|
|
|
|
for (let i = 0; i < nav_items.length; i++) {
|
2018-09-13 15:54:26 -04:00
|
|
|
html_str += `<li><a href="javascript:void(0);" onclick="navigate(\`${nav_items[i]}\`)">${nav_items[i]}</a></li>`;
|
2018-09-13 14:22:27 -04:00
|
|
|
}
|
|
|
|
document.getElementById('navItems').innerHTML = html_str;
|
2018-09-12 13:04:00 -04:00
|
|
|
}
|