MediaWiki:Gadget-vsk-hosts.js

/* */ /* VirtualSkipper Live List */ function show_alert(sMsg) { if (sMsg.length) alert("Gadget-vsk-hosts : "+sMsg); };

function echoXML(data) { $("div .vskosloadingarea") .append(" Data received: "+data+" "); };

function writeVskHosts(data){ // Write the table(s) for (var i=0;i "+data.getElementsByTagName("server")[i].login+                        "  "+data.getElementsByTagName("server")[i].name+                        "  "+data.getElementsByTagName("server")[i].servername+                        "  "+data.getElementsByTagName("server")[i].path+                        "  "+data.getElementsByTagName("server")[i].isprivate+                        "  "+data.getElementsByTagName("server")[i].isfull+                        "  "+data.getElementsByTagName("server")[i].playercount+                        "  "); //};   };    // Show table, hide loading info $('.vskosloadingarea').hide("slow"); $('.vskostablearea').show("slow"); };

function echoXHR(XHR, txt, errThrwn) { $("div .vskosloadingarea") .append(       " Error received: "+txt+        " XHR ready: "+XHR.readytState+        " XHR status: "+XHR.status+        " XHR response text: "+XHR.responseText+        " XHR response XML: "+XHR.responseXML+        //" Errorthrown: "+errThrwn+        //" Options: "+this+        " "    ); };

function errorHandler(XMLHttpRequest, textStatus, errorThrown) { // typically only one of textStatus or errorThrown will have info //this; // the options for this ajax request //$("div .vskhosts").append(" Error: "+textStatus+" AJAX request: "+XMLHttpRequest+   //    " Errorthrown: "+errorThrown+" Options: "+this+" "); alert("Error: "+textStatus+" "+this); };

importScriptURI('http://test-najevi.wikia.com/wiki/MediaWiki:Gadget-vsk-hosts/ajax-setup'); // any additional debug/error handling

function vskHosts { // listen for various Ajax events -- debug $(".vskosloadingarea").bind("ajaxSend", function{       $(this).show;        }).bind("ajaxComplete", function{            $(this).hide;            });

// Show the loading info $("div .vskhosts") .append(" Loading data ...  ");

// set defaults for ajax requests -- find out if there a way to obfuscate the cleartext password here /*   $.ajaxSetup({        user: "vsk5-public01",        password: "maqBzAdvFq"        //global: false, //default is true    }); if ($("div .vskhosts").length) { show_alert("Get live data via XMLHttpRequest"); // Get live data via XMLHttpRequest oXHR=$.ajax({       //dataType: "xml", // Nadeo will *not* support JSON        type: "GET",        url: "http://scripts.ac32.virtualskipper.com/getPlayersOnline.php",        //url: "http://scripts.ac32.virtualskipper.com/getServersOnline.php",        error: echoXHR, //show_alert("error"), //errorHandler(XMLHttpRequest, textStatus, errorThrown),        success: echoXML, //show_alert("success"), //writeVskHosts(data),        cache: false,        user: "vsk5-public01",        password: "maqBzAdvFq"    }); $("div .vskhosts") .append(       " Error received: "+oXHR.textStatus+        " XHR: "+oXHR.XMLHttpRequest+        " Errorthrown: "+oXHR.errorThrown+        " Options: "+oXHR.this+" "    ); }; }; $( vskHosts );

/* */ /* */ // === XML parsing methods ===

/* - - - vskonlineservers - - - data.getElementsByTagName("nbservers")[0]; // number of hosts currently hosting races data.getElementsByTagName("server").length; // number of hosts currently hosting races data.getElementsByTagName("server")[i].login; data.getElementsByTagName("server")[i].name; data.getElementsByTagName("server")[i].servername; data.getElementsByTagName("server")[i].path; data.getElementsByTagName("server")[i].isprivate; data.getElementsByTagName("server")[i].isfull; data.getElementsByTagName("server")[i].playercount;

/* - - - ranking - - - data.getElementsByTagName("nbplayers")[0]; // this is the total number of players (login accounts) ever ranked data.getElementsByTagName("player").length; // records for only the top 100 ranked players are returned data.getElementsByTagName("player")[i].ranking; data.getElementsByTagName("player")[i].login; data.getElementsByTagName("player")[i].nickname; data.getElementsByTagName("player")[i].path; data.getElementsByTagName("player")[i].rating;

/* - - - onlineplayers - - - data.getElementsByTagName("nbplayers")[0]; // number of players currently online data.getElementsByTagName("player").length; // number of players currently online data.getElementsByTagName("player")[i].login; data.getElementsByTagName("player")[i].nickname;

/* */