📄 functions.js
字号:
/* Use hotkey name (without the "key-" part) as the argument to simulate a hotkey press */ loadXMLDoc( 'requests/status.xml?command=key&val='+str, parse_status );}function update_status(){ loadXMLDoc( 'requests/status.xml', parse_status );}function update_playlist(){ loadXMLDoc( 'requests/playlist.xml', parse_playlist );}function update_playlist_search(key){ loadXMLDoc( 'requests/playlist.xml?search='+encodeURIComponent(key), parse_playlist )}function reset_search(){ var search = document.getElementById('search') if( search ) { search.value = '<search>' update_playlist_search('') }}/********************************************************************** * Parse xml replies to XMLHttpRequests *********************************************************************//* parse request/status.xml */function parse_status(){ if( req.readyState == 4 ) { if( req.status == 200 ) { var status = req.responseXML.documentElement; var timetag = status.getElementsByTagName( 'time' ); if( timetag.length > 0 ) { var new_time = timetag[0].firstChild.data; } else { new_time = old_time; } var lengthtag = status.getElementsByTagName( 'length' ); var length; if( lengthtag.length > 0 ) { length = lengthtag[0].firstChild.data; } else { length = 0; } var slider_position; positiontag = status.getElementsByTagName( 'position' ); if( length < 100 && positiontag.length > 0 ) { slider_position = ( positiontag[0].firstChild.data * 4 ) + "px"; } else if( length > 0 ) { /* this is more precise if length > 100 */ slider_position = Math.floor( ( new_time * 400 ) / length ) + "px"; } else { slider_position = 0; } if( old_time > new_time ) setTimeout('update_playlist()',50); old_time = new_time; set_text( 'time', format_time( new_time ) ); set_text( 'length', format_time( length ) ); if( status.getElementsByTagName( 'volume' ).length != 0 ) set_text( 'volume', Math.floor(status.getElementsByTagName( 'volume' )[0].firstChild.data/5.12)+'%' ); var statetag = status.getElementsByTagName( 'state' ); if( statetag.length > 0 ) { set_text( 'state', statetag[0].firstChild.data ); } else { set_text( 'state', '(?)' ); } if( slider_mouse_down == 0 ) { document.getElementById( 'main_slider_point' ).style.left = slider_position; } var statustag = status.getElementsByTagName( 'state' ); if( statustag.length > 0 ? statustag[0].firstChild.data == "playing" : 0 ) { document.getElementById( 'btn_pause_img' ).setAttribute( 'src', 'images/pause.png' ); document.getElementById( 'btn_pause_img' ).setAttribute( 'alt', 'Pause' ); document.getElementById( 'btn_pause' ).setAttribute( 'title', 'Pause' ); } else { document.getElementById( 'btn_pause_img' ).setAttribute( 'src', 'images/play.png' ); document.getElementById( 'btn_pause_img' ).setAttribute( 'alt', 'Play' ); document.getElementById( 'btn_pause' ).setAttribute( 'title', 'Play' ); } var randomtag = status.getElementsByTagName( 'random' ); if( randomtag.length > 0 ? randomtag[0].firstChild.data == "1" : 0) setclass( document.getElementById( 'btn_shuffle'), 'on' ); else setclass( document.getElementById( 'btn_shuffle'), 'off' ); var looptag = status.getElementsByTagName( 'loop' ); if( looptag.length > 0 ? looptag[0].firstChild.data == "1" : 0) setclass( document.getElementById( 'btn_loop'), 'on' ); else setclass( document.getElementById( 'btn_loop'), 'off' ); var repeattag = status.getElementsByTagName( 'repeat' ); if( repeattag.length > 0 ? repeattag[0].firstChild.data == "1" : 0 ) setclass( document.getElementById( 'btn_repeat'), 'on' ); else setclass( document.getElementById( 'btn_repeat'), 'off' ); var tree = document.createElement( "ul" ); var categories = status.getElementsByTagName( 'category' ); var i; for( i = 0; i < categories.length; i++ ) { var item = document.createElement( "li" ); item.appendChild( document.createTextNode( categories[i].getAttribute( 'name' ) ) ); var subtree = document.createElement( "dl" ); var infos = categories[i].getElementsByTagName( 'info' ); var j; for( j = 0; j < infos.length; j++ ) { var subitem = document.createElement( "dt" ); subitem.appendChild( document.createTextNode( infos[j].getAttribute( 'name' ) ) ); subtree.appendChild( subitem ); if( infos[j].hasChildNodes() ) { var subitem = document.createElement( "dd" ); subitem.appendChild( document.createTextNode( infos[j].firstChild.data ) ); subtree.appendChild( subitem ); } } item.appendChild( subtree ); tree.appendChild( item ); } var infotree = document.getElementById('infotree' ); clear_children( infotree ); infotree.appendChild( tree ); } else { /*alert( 'Error! HTTP server replied: ' + req.status );*/ } }}/* parse playlist.xml */function parse_playlist(){ if( req.readyState == 4 ) { if( req.status == 200 ) { var answer = req.responseXML.documentElement; var playtree = document.getElementById( 'playtree' ); var pos = document.createElement( "div" ); var pos_top = pos; var elt = answer.firstChild; pl_cur_id = 0; /* changed to the current id is there actually * is a current id */ while( elt ) { if( elt.nodeName == "node" ) { if( pos.hasChildNodes() ) pos.appendChild( document.createElement( "br" ) ); var nda = document.createElement( 'a' ); nda.setAttribute( 'href', 'javascript:toggle_show_node(\''+elt.getAttribute( 'id' )+'\');' ); var ndai = document.createElement( 'img' ); ndai.setAttribute( 'src', 'images/minus.png' ); ndai.setAttribute( 'alt', '[-]' ); ndai.setAttribute( 'id', 'pl_img_'+elt.getAttribute( 'id' ) ); nda.appendChild( ndai ); pos.appendChild( nda ); pos.appendChild( document.createTextNode( ' ' + elt.getAttribute( 'name' ) ) ); if( elt.getAttribute( 'ro' ) == 'rw' ) { pos.appendChild( document.createTextNode( ' ' ) ); var del = document.createElement( "a" ); del.setAttribute( 'href', 'javascript:pl_delete('+elt.getAttribute( 'id' )+')' ); var delimg = document.createElement( "img" ); delimg.setAttribute( 'src', 'images/delete_small.png' ); delimg.setAttribute( 'alt', '(delete)' ); del.appendChild( delimg ); pos.appendChild( del ); } var nd = document.createElement( "div" ); setclass( nd, 'pl_node' ); nd.setAttribute( 'id', 'pl_'+elt.getAttribute( 'id' ) ); pos.appendChild( nd ); } else if( elt.nodeName == "leaf" ) { if( pos.hasChildNodes() ) pos.appendChild( document.createElement( "br" ) ); var pl = document.createElement( "a" ); setclass( pl, 'pl_leaf' ); pl.setAttribute( 'href', 'javascript:pl_play('+elt.getAttribute( 'id' )+');' ); pl.setAttribute( 'id', 'pl_'+elt.getAttribute( 'id' ) ); if( elt.getAttribute( 'current' ) == 'current' ) { pl.style.fontWeight = 'bold'; var nowplaying = document.getElementById( 'nowplaying' ); clear_children( nowplaying ); nowplaying.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) ); pl.appendChild( document.createTextNode( '* ')); pl_cur_id = elt.getAttribute( 'id' ); } pl.setAttribute( 'title', elt.getAttribute( 'uri' )); pl.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) ); var duration = elt.getAttribute( 'duration' ); if( duration > 0 ) pl.appendChild( document.createTextNode( " (" + format_time( elt.getAttribute( 'duration' ) / 1000000 ) + ")" ) ); pos.appendChild( pl ); if( elt.getAttribute( 'ro' ) == 'rw' ) { pos.appendChild( document.createTextNode( ' ' ) ); var del = document.createElement( "a" ); del.setAttribute( 'href', 'javascript:pl_delete('+elt.getAttribute( 'id' )+')' ); var delimg = document.createElement( "img" ); delimg.setAttribute( 'src', 'images/delete_small.png' ); delimg.setAttribute( 'alt', '(delete)' ); del.appendChild( delimg ); pos.appendChild( del ); } } if( elt.firstChild ) { elt = elt.firstChild; pos = pos.lastChild; } else if( elt.nextSibling ) { elt = elt.nextSibling; pos = pos; } else { while( ! elt.parentNode.nextSibling ) { elt = elt.parentNode; if( ! elt.parentNode ) break; pos = pos.parentNode; } if( ! elt.parentNode ) break; elt = elt.parentNode.nextSibling; pos = pos.parentNode; } } clear_children( playtree ); playtree.appendChild( pos_top ); } else { /*alert( 'Error! HTTP server replied: ' + req.status );*/ } }}/* parse browse.xml */function parse_browse_dir( ){ if( req.readyState == 4 ) { if( req.status == 200 ) { var answer = req.responseXML.documentElement; if( !answer ) return; var browser = document.getElementById( 'browser' ); var pos = document.createElement( "div" ); var elt = answer.firstChild; while( elt ) { if( elt.nodeName == "element" ) { var item = document.createElement( "a" ); setclass( item, 'browser' ); if( elt.getAttribute( 'type' ) == 'dir' ) { item.setAttribute( 'href', 'javascript:browse_dir(\''+addslashes(escapebackslashes(elt.getAttribute( 'path' )))+'\');'); } else { item.setAttribute( 'href', 'javascript:browse_path(\''+addslashes(escapebackslashes(elt.getAttribute( 'path' )))+'\');' ); } item.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) ); pos.appendChild( item ); if( elt.getAttribute( 'type' ) == 'dir' ) { pos.appendChild( document.createTextNode( ' ' ) ); var item = document.createElement( "a" ); setclass( item, 'browser' ); item.setAttribute( 'href', 'javascript:browse_path(\''+addslashes(escapebackslashes(elt.getAttribute( 'path' )))+'\');'); item.appendChild( document.createTextNode( '(select)' ) ); pos.appendChild( item ); } pos.appendChild( document.createElement( "br" ) ); } elt = elt.nextSibling; } clear_children( browser ); browser.appendChild( pos ); } else { /*alert( 'Error! HTTP server replied: ' + req.status );*/ } }}/********************************************************************** * Input dialog functions *********************************************************************/function hide_input( ){ document.getElementById( 'input_file' ).style.display = 'none'; document.getElementById( 'input_disc' ).style.display = 'none'; document.getElementById( 'input_network' ).style.display = 'none'; document.getElementById( 'input_fake' ).style.display = 'none';}/* update the input MRL using data from the input file helper *//* FIXME ... subs support */function update_input_file(){ var mrl = document.getElementById( 'input_mrl' ); mrl.value = value( 'input_file_filename' );}/* update the input MRL using data from the input disc helper */function update_input_disc(){ var mrl = document.getElementById( 'input_mrl' ); var type = radio_value( "input_disc_type" ); var device = value( "input_disc_dev" ); var title = check_and_replace_int( 'input_disc_title', 0 ); var chapter = check_and_replace_int( 'input_disc_chapter', 0 ); var subs = check_and_replace_int( 'input_disc_subtrack', '' ); var audio = check_and_replace_int( 'input_disc_audiotrack', 0 ); mrl.value = ""; if( type == "dvd" ) { mrl.value += "dvd://"; } else if( type == "dvdsimple" ) { mrl.value += "dvdsimple://"; } else if( type == "vcd" ) { mrl.value += "vcd://"; } else if( type == "cdda" ) { mrl.value += "cdda://"; } mrl.value += device; if( title ) { mrl.value += "@"+title; if( chapter && type != "cdda" ) mrl.value += ":"+chapter; } remove_input_options( ':sub-track' ); remove_input_options( ':audio-track' );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -