X-Git-Url: https://git.wh0rd.org/?p=chrome-ext%2Fmusic-player-client.git;a=blobdiff_plain;f=main.js;h=5b05cee5e2c101192829762c3b542f40b49f9d86;hp=9155650966c2f3a40c2f14befc72a61a33437080;hb=e9706fb8f28daa5e6b17f335c20adb6112321119;hpb=ea38f3edda02edbdbc0b3f46d58f2d2ba2795f37 diff --git a/main.js b/main.js index 9155650..5b05cee 100644 --- a/main.js +++ b/main.js @@ -14,6 +14,10 @@ TcpClientSender.prototype.send = function(data, cb) { TcpClientSender.prototype.poll = function() { this.tcpclient.poll(); } +TcpClientSender.prototype.reconnect = function() { + this.tcpclient.disconnect(); + this.tcpclient.connect(); +} function tramp_mpc_recv(data) { mpc.recv(data); @@ -56,6 +60,23 @@ window.onload = function() { }); }; +window.onkeypress = function(e) { + switch (e.keyCode) { + case 49: // 1 + show_page('controls'); + break; + case 50: // 1 + show_page('metadata'); + break; + case 51: // 1 + show_page('playlist'); + break; + case 52: // 1 + show_page('options'); + break; + } +}; + function mpc_refresh() { mpc.status(); } @@ -93,6 +114,7 @@ function tramp_mpc_consume() { mpc.consume(val); setToggleButton(this, val); } +function tramp_mpc_deleteid() { mpc.deleteid(this.title); } function tramp_mpc_next() { mpc.next(); } function tramp_mpc_pause() { mpc.pause(); } function tramp_mpc_play() { mpc.play(); } @@ -191,11 +213,17 @@ function update_sync_settings() { } function init_ui(local_keys, sync_keys, options) { + var ele, i; + /* Setup footer */ + i = 1; [ - 'controls', 'metadata', 'options', 'playlist', + 'controls', 'metadata', 'playlist', 'options', ].forEach(function(id) { - document.getElementById('tab.' + id).onclick = show_page; + var ele = document.getElementById('tab.' + id); + ele.onclick = show_page; + ele.title = id + ' [' + i + ']'; + ++i; }); /* Setup control tab */ @@ -207,6 +235,8 @@ function init_ui(local_keys, sync_keys, options) { var ele = window['ui_mpc_' + id] = document.getElementById(id); ele.onchange = ele.onclick = window['tramp_mpc_' + id]; ele.title = id; + if (ele.accessKey) + ele.title += ' [' + ele.accessKey + ']' }); window['ui_mpc_currtime'] = document.getElementById('currtime'); @@ -247,6 +277,16 @@ function pretty_time(time) { return ret + ("00" + sec).substr(-2); } +function playlist_del() { + mpc.deleteid(this.song_id); + this.parentNode.remove(); +} + +function playlist_play() { + mpc.playid(this.song_id); + this.parentNode.style.fontWeight = 'bold'; +} + function update_ui(state, cmd) { if (typeof(state) == 'string') { ui_mpc_status.innerText = ({ @@ -289,9 +329,19 @@ function update_ui(state, cmd) { if (song.Pos == currentsong.Pos) row.style.fontWeight = 'bold'; + cell = row.insertCell(-1); + cell.id = 'playlist_del'; + cell.innerHTML = '¤'; + cell.song_id = song.Id; + cell.title = 'delete'; + cell.onclick = playlist_del; + cell = row.insertCell(-1); cell.innerText = song.Pos; cell.style.textAlign = 'right'; + cell.song_id = song.Id; + cell.title = 'play'; + cell.onclick = playlist_play; if ('Artist' in song) { row.insertCell(-1).innerText = song.Artist;