Ajax code used by Baidu Musicbox

Source: Internet
Author: User

Var names;
Var Cs, St;
Var rorw = "";
Var lrcT;

Function getname (songname ){
If (songname = ""){
Names = $ ("name"). value;
} Else {
Names = songname;
}
Geturl ();
}
Function geturl (){
AJAXCALL ("inc/songurl. asp? Type = url1 & keyword = "+ names," musiclist "," isXML = true ");
Addbox (names );
}
Function top (){
AJAXCALL ("inc/songlist. asp? Ac = new "," toplist "," isXML = true ");
}
Function toplist (doc ){
Var items = getElementsByClass (doc, "item ");
Var linker = new Array ();
Var linkers = new Array ();
Var tmp = "<ul> ";
For (var I = 0; I <items. length; I ++ ){
If (getTagValue (items [I], "singer") = "")
{
Linker [I] = "";
Linkers [I] = "";
}
Else
{
Linker [I] = "(" + getTagValue (items [I], 'singer'). replace (// g, "") + ")";
Linkers [I] = "" + getTagValue (items [I], 'singer'). replace (// g ,"");
}
Var d = I + 1;
Tmp + = '<li>' + d + '. <a href = javascript: getname ("'+ getTagValue (items [I], 'songname '). replace (// g, "") + linkers [I] + '") title ="' + getTagValue (items [I], 'songname '). replace (// g, "") + linker [I] + '">' + getTagValue (items [I], 'songname '). replace (// g, "") + linker [I] + '</a> </li> ';
}
Tmp + = "</ul> ";
$ ("Toplist"). innerHTML = tmp;
}
Function s2 (){
AJAXCALL ("inc/songlist. asp? Ac = all "," s3 "," isXML = true ");
}
Function s3 (doc ){
Var items = getElementsByClass (doc, "item ");
Var linker = new Array ();
Var linkers = new Array ();
Var tmp = "<ul> ";
For (var I = 0; I <items. length; I ++ ){
If (getTagValue (items [I], "singer") = "")
{
Linker [I] = "";
Linkers [I] = "";
}
Else
{
Linker [I] = "(" + getTagValue (items [I], 'singer'). replace (// g, "") + ")";
Linkers [I] = "" + getTagValue (items [I], 'singer'). replace (// g ,"");
}
Var d = I + 1;
Tmp + = '<li>' + d + '. <a href = javascript: getname ("'+ getTagValue (items [I], 'songname '). replace (// g, "") + linkers [I] + '") title ="' + getTagValue (items [I], 'songname '). replace (// g, "") + linker [I] + '">' + getTagValue (items [I], 'songname '). replace (// g, "") + linker [I] + '</a> </li> ';
}
Tmp + = "</ul> ";
$ ("Topalllist"). innerHTML = tmp;
}
Function musiclist (doc ){
Var items = getElementsByClass (doc, "item ");
Var tmp = "<ul> ";
For (var I = 0; I <22 & I <items. length; I ++ ){
Var d = I + 1;
Type = getTagValue (items [I], 'type ');
Tmp + = '<li> <a title = "audition point' + d + '(' + type + ') "href = javascript: play (" '+ getTagValue (items [I], 'type') +' "," '+ getTagValue (items [I], 'link '). replace (// g, '') + '")>' + names. replace (// g, '') + '(' + type + ') </a> </li> ';
}
Tmp + = "</ul> ";
$ ("List"). innerHTML = tmp;
$ ("Msg"). style. display = "none ";
Play (getTagValue (items [0], "type"), getTagValue (items [0], "link "));
}
Function play (obj, url ){
InitLrc ();
$ ("Guanxin"). style. display = "none ";
$ ("Msg"). style. display = "block ";
AJAXCALL ("inc/songurl. asp? Type = url2 & keyword = "+ url +" & attach = "+ obj," gotoplay "," isXML = true ");
AJAXCALL ("inc/lyrics. asp? Song = "+ names," getlrc "," isXML = true ");
}
Var tl;
Function getlrc (doc ){
Tl = "";
Var items = getElementsByClass (doc, "item ");
Var tmp = "<div id = LrcDiv class = LrcDiv> ";
For (var I = 0; I <items. length; I ++ ){
Tmp + = '<div class = div id = T _' + getTagValue (items [I], 'time ') + 'onclick = To (\ ''+ getTagValue (items [I], 'time') + '\')> '+ getTagValue (items [I], 'lrc ') + '</div> ';
Tl + = getTagValue (items [I], 'time') + "| ";
}
Tmp + = "</div> ";
$ ("Lrc"). innerHTML = tmp;
}

Function gotoplay (docs ){
Var type = getTagValue (docs, "type ");
Var link = getTagValue (docs, "link ");
If (type = "rm" | type = "ra" | type = "ram" | type = "rmvb" | type = "mpga" | type = "mp4" | type = "3gp ")
$ ("Players"). innerHTML = realplayer (link );
Else
$ ("Players"). innerHTML = mdplayer (link );
Var link3 = cuturl (link );
$ ("Msg"). style. display = "none ";
$ ("Wmaurl "). innerHTML = "song Source: <a href =" + link. replace (// g, "") + "target = '_ blank' title = 'Right-click Save:" + names. replace (// g, "") + "'>" + link3.replace (// g, "") + "</a> ";
SetTimeout (guanxin, 1000 );
Playobj ();
}

Function initLrc (){
ClearTimeout (lrcT );
Rorw = "";
$ ("Players"). innerHTML = "";
$ ("Lrc"). innerHTML = "";
St = 0;
Cs = 0;
}

Function playobj (){
If ($ ("MPlayer "))
{
Rorw = "wmp ";
LdL ();
}
Else if ($ ("RPlayer "))
{
Rorw = "rmp ";
Try {RPlayer. SetWantErrors (true);} catch (hh ){}
LdL ();
}
Else
Playobj ();
}

Function guanxin (){
$ ("Guanxin"). style. display = "block ";
SetTimeout (guanxin2, 10000 );
}
Function guanxin2 (){
$ ("Guanxin"). style. display = "none ";
}

Var player;
Function mdplayer (str ){
Player = '<object classid = "clsid: 6bf52a52-394a-11d3-b153-00c04f79faa6 "id =" MPlayer "width =" 100% "height =" 64 "> <param name =" url "value =" '+ str +' "> <param name =" enablecontextmenu "value =" 0 "> <param name =" enableerrordialogs "value =" 0 "> </object> ';
Return player;
}

Function realplayer (str ){
Player = '<object classid = "clsid: cfcdaa03-8be4-11cf-b84b-0020afbbccfa "id =" RPlayer "width =" 100% "height =" 60 "> <param name =" src "value =" '+ str +' "> <param name =" controls "value =" controlpanel, statusbar "> <param name =" autostart "value =" true "> </object> ';
Return player;
}

Function cuturl (song_url ){
Var len = getStrActualLen (song_url );
Var MAX_DISP_LEN = 40;
If (len <= MAX_DISP_LEN) return song_url;
Var disp_song_url = song_url;
Var pos1 = song_url.indexOf ("://");
If (pos1> 0 ){
Disp_song_url = song_url.substring (pos1 + 3, len );
Var pos2 = disp_song_url.indexOf ("/");
If (pos2> 0) disp_song_url = song_url.substring (0, pos1 + pos2 + 4 );
Var len2 = MAX_DISP_LEN-3-getStrActualLen (disp_song_url );
If (len2> 0) disp_song_url = disp_song_url + '...' + song_url.substring (len-len2, len );
Return disp_song_url;
}
}

Function getStrActualLen (sChars ){
Return sChars. replace (/[^ \ x00-\ xff]/g, "xx"). length;
}

Function AJAXCALL (url, handleResponse, param ){
Var isXML = false; // false: html or true: xml
Var isCache = false; // false: no-cache or true: cache
Var method = "GET"; // GET or POST
Var attach = "";
If (param ){
Re = // g;
Param = param. replace (re ,"");
Var tmp = param. split (",");
For (var I = 0; I <tmp. length; I ++ ){
Var pa = tmp [I]. substr (0, 3 );
Var ct = tmp [I]. split ("=") [1];
Switch (pa ){
Case "isX ":
If (ct = "true "){
IsXML = true;
} Else {
IsXML = false;
}
Break;
Case "isC ":
If (ct = "true "){
IsCache = true;
} Else {
IsCache = false;
}
Break;
Case "met ":
Method = ct;
Break;
Case "att ":
Attach = ct;
Break;
}
}
}
If (! IsCache ){
Var t = new Date (). getTime ();
If (url. indexOf ("? ")> 0 ){
Url + = "& t =" + t;
} Else {
Url + = "? T = "+ t;
}
}
Var postdata = null;
If (method = "POST "){
Purl = url. split ("? ");
Url = purl [0];
Postdata = purl [1];
}
RequestHTTP (url, handleResponse, method, isXML, postdata, attach );
}

Function RequestHTTP (burl, rdRandleResponse, bmethod, bXML, Formdata, attach ){
Var http_request = false;
Function doHttpRequest (){
If (window. XMLHttpRequest ){
Http_request = new XMLHttpRequest ();
If (http_request.overrideMimeType ){
Http_request.overrideMimeType ('text/xml ');
}
} Else if (window. ActiveXObject ){
Try {
Http_request = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e ){
Try {
Http_request = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (e ){}
}
}
If (! Http_request ){
Alert ('Giving up Cannot create an XMLHTTP instance ');
Return false;
}
Http_request.onreadystatechange = handleStateChange;
Http_request.open (bmethod, burl, true );
If (Formdata ){
Http_request.setRequestHeader ("Content-Length", Formdata. length );
Http_request.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded ");
Http_request.send (Formdata );
} Else {
Http_request.setRequestHeader ("Content-Type", "text/html ");
Http_request.send (null );
}
}
Function handleStateChange (){
If (http_request.readyState = 4 & http_request.status = 200 ){
Var response_content;
If (bXML ){
Response_content = http_request.responseXML;
} Else {
Response_content = http_request.responseText;
}
If (typeof rdRandleResponse = "function "){
RdRandleResponse (response_content, attach );
} Else {
Eval (rdRandleResponse + "(response_content, attach )");
}
}
}
DoHttpRequest ();
}

Function getTagValue (doc, tag ){
Var elems = doc. getElementsByTagName (tag) [0]. firstChild. nodeValue;
Return elems;
}

Function $ (obj ){
Return document. getElementById (obj );
}

Function getElementsByClass (node, tag ){
Var els = node. getElementsByTagName (tag );
Return els;
}
Lyrics function:Copy codeThe Code is as follows: function setcookie (name, value ){
Var Days = 30;
Var exp = new Date ();
Exp. setTime (exp. getTime () + Days x 24x60*60*1000 );
Document. cookie = name + "=" + escape (value) + "; expires =" + exp. toGMTString ();
}
Function getcookie (name ){
Var arr = document. cookie. match (new RegExp ("(^ |)" + name + "= ([^;] *) (; | $ )"));
If (arr! = Null) return unescape (arr [2]); return null;
}
Setcookie ("box", getcookie ("box "));
Function addbox (name ){
Var a1 = name + "| * | ";
Var box = getcookie ("box ");
Box = box. replace (a1 ,"");
Var value = a1 + box;
Setcookie ("box", value );
Listbox ();
}
Function delbox (name ){
Var del = name + "| * | ";
Var s = getcookie ("box ");
S = s. replace (del ,"");
Setcookie ("box", s );
Listbox ();
}
Function listbox (){
Var tmp = "";
Var s2 = getcookie ("box ");
Var s3 = s2.split ("| * | ");
Var s4 = s3.length-1;
If (s4> 8) $ ("boxlist"). style. height = "139px ";
For (var I = 0; I <s4; I ++ ){
Tmp + = "<div id = \" box \ "> <div id = \" del \ "style = \" float: right; \ "> <span onclick = javascript: delbox ('"+ s3 [I] +"')> Delete </span> </div> <div id = \ "boxtitle \"> <a href = javascript: getname ('"+ s3 [I] +"')> "+ s3 [I] +" </a> </div> ";
}
$ ("Boxlist"). innerHTML = tmp;
}

Function GetEBID (id) {return document. getElementById (id );}
Function To (t ){
If (rorw = "") return;
If (rorw = "rmp" & RPlayer. GetPlayState () = 3) RPlayer. SetPosition (t * 1000 );
If (rorw = "wmp" & MPlayer. playState = 3) MPlayer. controls. CurrentPosition = t;
}

Function lrcrun (){
Var rtl = "|" + tl;
If (rtl. indexOf ("|" + Cs + "| "))! =-1 ){
GetEBID ("LrcDiv "). scrollTop = GetEBID ("LrcDiv "). offsetTop-parseInt (GetEBID ("LrcDiv "). offsetHeight/2) + GetEBID ("T _" + Cs ). offsetTop + 10;
GetEBID ("T _" + St). className = "";
GetEBID ("T _" + Cs). className = "B ";
St = Cs;
}
}

Function ldL (){
If (rorw = "rmp" & RPlayer. GetPlayState () = 3) {Cs = Math. floor (RPlayer. GetPosition ()/1000); lrcrun ();}
If (rorw = "wmp" & MPlayer. playState = 3) {Cs = Math. floor (MPlayer. controls. CurrentPosition); lrcrun ();}
LrcT = setTimeout ("ldL ()", 10 );
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.