43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
var httpRequest
|
|
function navigate(item) {
|
|
if (/\..{3,5}$/.test(item)) {
|
|
change_track(item);
|
|
}
|
|
else {
|
|
get_dir(item);
|
|
}
|
|
}
|
|
|
|
function change_track(item) {
|
|
let cd = document.getElementById('currentDirectory').innerText;
|
|
let track = cd + item;
|
|
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++) {
|
|
html_str += '<li><a href="javascript:void(0);" onclick="navigate(\'' + nav_items[i] + '\')">' + nav_items[i] + '</a></li>';
|
|
}
|
|
document.getElementById('navItems').innerHTML = html_str;
|
|
}
|