79 lines
2.2 KiB
JavaScript
79 lines
2.2 KiB
JavaScript
function load() {
|
|
// track has ended
|
|
document.getElementById('player').addEventListener('ended', function() {
|
|
// shuffle
|
|
if (document.getElementById('shuffle').checked) {
|
|
var httpRequest;
|
|
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();
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function navigate(item) {
|
|
if (/\..{3,5}$/.test(item)) {
|
|
select_track(item);
|
|
}
|
|
else {
|
|
get_dir(item);
|
|
}
|
|
}
|
|
|
|
function select_track(item) {
|
|
let cd = document.getElementById('currentDirectory').innerText;
|
|
let track = cd + item;
|
|
change_track(track);
|
|
}
|
|
|
|
function change_track(track) {
|
|
let source = document.getElementById('stream');
|
|
source.src = '/musik/stream' + encodeURIComponent(track);
|
|
let player = document.getElementById('player');
|
|
player.load();
|
|
player.play();
|
|
document.getElementById('nowPlaying').innerHTML = track;
|
|
|
|
let arr = track.split('/');
|
|
let art = document.getElementById('albumCover');
|
|
art.firstChild.src = '/musik/album_cover' + arr.slice(0, arr.length-1).join("/") + '/folder.jpg';
|
|
}
|
|
|
|
function get_dir(item) {
|
|
let cd = document.getElementById('currentDirectory').innerText;
|
|
if (item === "../") {
|
|
if (cd !== "/") {
|
|
item = cd.slice(0, cd.slice(0, -1).lastIndexOf("/")+1);
|
|
}
|
|
else {
|
|
return;
|
|
}
|
|
}
|
|
else {
|
|
item = cd + item;
|
|
}
|
|
|
|
var httpRequest;
|
|
httpRequest = new XMLHttpRequest();
|
|
httpRequest.onreadystatechange = function () {
|
|
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;
|
|
};
|
|
httpRequest.open('GET', '/musik/get_dir/' + item, true);
|
|
httpRequest.send();
|
|
}
|