diff --git a/musik.py b/musik.py index 4f5b613..3ad2cc4 100755 --- a/musik.py +++ b/musik.py @@ -50,8 +50,6 @@ def index(): nav_items = os.listdir(MUSIC_DIR) nav_items.sort() nav_items = [item + '/' for item in nav_items] - initial_track = "/Accept/Accept - Balls to the Wall (1983) [FLAC] {74321 93214 2}/01 - Balls to the Wall.flac" - initial_cover = "/Accept/Accept - Balls to the Wall (1983) [FLAC] {74321 93214 2}/folder.jpg" cd = "/" return render_template('index.html', **locals()) diff --git a/static/musik.js b/static/musik.js index ec0c707..9e37b5a 100644 --- a/static/musik.js +++ b/static/musik.js @@ -3,23 +3,20 @@ function load() { document.getElementById('player').addEventListener('ended', function() { // shuffle if (document.getElementById('shuffle').checked) { - ajax('/musik/get_shuffle', function() { + 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(); } }); } -var httpRequest; -function ajax(url, func) { - httpRequest = new XMLHttpRequest(); - httpRequest.onreadystatechange = func; - httpRequest.open('GET', url, true); - httpRequest.send(); -} function navigate(item) { if (/\..{3,5}$/.test(item)) { @@ -62,17 +59,20 @@ function get_dir(item) { else { item = cd + item; } - ajax('/musik/get_dir/' + item, update_nav_items); -} -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 += `
  • ${nav_items[i]}
  • `; - } - document.getElementById('navItems').innerHTML = html_str; + 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 += `
  • ${nav_items[i]}
  • `; + } + document.getElementById('navItems').innerHTML = html_str; + }; + httpRequest.open('GET', '/musik/get_dir/' + item, true); + httpRequest.send(); } diff --git a/templates/index.html b/templates/index.html index e917f07..f75e268 100644 --- a/templates/index.html +++ b/templates/index.html @@ -18,11 +18,11 @@
    - + -

    {{ initial_track }}

    +