sherkaner wrote:Actually, chatgloves does a request per game, and does them simultaeous. I'm not even sure whether you need to alter code if you use the override-function in the other thread, which uses a normal XMLHttpRequest to simulate the greasemonkey-variant.
I'm clearly not explaining myself well here so I suggest talking to Foxglove (she will for sure know the difference I am referring to her as
she knows AJAX) if you have not already heard from her.
One last attempt at explanation is with illustration
In chatglove getUserGames handles a single returning page for its AJAX request
(for completeness should handle multiple but >200 active games is very rare)
It then calls getGameChatLineCount multiple times, each case handling a single return page for the AJAX request.
Map Rank does not search for active games, it searches for finished games meaning several pages are returned
requiring handling for page count and ordering. I use an array to guarantee distinct objects for each request.
So why is this necessary at all? Because the sequence of returning pages is not guaranteed, they can come in any order.
I have written a short example for you here to illustrate the returning page order
- Code: Select all
var npages = 0;
var ghistobj;
var uname = "Masli";
var gorder = new Array();
function getGamesObj(page) {
var jump = 'http://www.conquerclub.com/api.php?mode=gamelist&events=Y&gs=F&un=' + uname;
if(page > 1) jump += "&page=" + page;
ghistobj = new XMLHttpRequest();
ghistobj.open('GET', jump, true);
ghistobj.onreadystatechange = function() {
if (ghistobj.readyState == 4) {
var parser = new DOMParser();
var dom = parser.parseFromString(ghistobj.responseText,"application/xml");
var games = dom.getElementsByTagName('game');
var pages = dom.getElementsByTagName('page')[0].firstChild.nodeValue;
var numGames = parseInt(dom.getElementsByTagName('games')[0].getAttribute('total'));
var pn;
if(pages.match(/^(\d+) of (\d+)$/)) {
numPages = parseInt(RegExp.$2);
}
if(page == 1) {
if(numPages > 1) {
for(var pg=2;pg<=numPages;pg++) {
getGames(pg);
}
}
}
npages++;
gorder.push(pn);
if(npages == numPages) {
alert(gorder);
}
}
}
ghistobj.send(null);
}
var leftBar = document.getElementById("leftColumn");
if(leftBar) {
var ul = leftBar.getElementsByTagName("ul");
if (ul[0]) {
getGamesObj(1);
}
}
It may still be possible for this code to work in Chrome, that should be easy enough to verify.
This reminds me I should post an AJAX tutorial wrt API.