Conquer Club

For GC?

Archival storage to keep things organized and uncluttered. Can't find what you need? Search for old topics here.

Moderator: Tech Team

Forum rules
Please read the Community Guidelines before posting.

For GC?

Postby QoH on Mon Dec 20, 2010 4:43 pm

Hi tech team!

I'm wondering if its' possible to make all, or atleast the more popular tools/enhancements available for GC. I know there are precious few, but I' wondering if anytime soon the other scripts will be edited to be compatible for GC.

Also, as a side note, my other computer had FF updated to 4.0 BETA and its' no longer compatible with greasemonkey. Just an FYI ;)

Thanks, Q
Major QoH
 
Posts: 1817
Joined: Fri Aug 20, 2010 12:37 pm

Re: For GC?

Postby AndyDufresne on Mon Dec 20, 2010 4:50 pm

It would be nice indeed---perhaps if some of the other script developers take a look at Sherkaner's recent post about porting from firefox to google chrome---: viewtopic.php?f=529&t=133534


--Andy
User avatar
Corporal 1st Class AndyDufresne
 
Posts: 24919
Joined: Fri Mar 03, 2006 8:22 pm
Location: A Banana Palm in Zihuatanejo

Re: For GC?

Postby sherkaner on Mon Dec 20, 2010 5:23 pm

Well, there aren't that many scripts that have active developers and aren't working in chrome, actually.

viewtopic.php?f=526&t=132420#p2916271 gives a nice overview, chatglove was changed to work with chrome afterwards. So it's mainly chipv's scripts, and a few old ones that don't work on chrome yet. I mainly put it up for ppl interested in it (maybe new developers?).

And about greasemonkey in ff4beta: Scriptish seems to be new, but will need some adaptions. But probably greasemonkey will have a new version too, nightlies can be tried atm: https://arantius.com/misc/gm-nightly/ (likely to be unstable though).
Colonel sherkaner
 
Posts: 1595
Joined: Thu May 03, 2007 3:21 am
Location: Zwolle

Re: For GC?

Postby chipv on Mon Dec 20, 2010 6:05 pm

sherkaner wrote:Well, there aren't that many scripts that have active developers and aren't working in chrome, actually.

viewtopic.php?f=526&t=132420#p2916271 gives a nice overview, chatglove was changed to work with chrome afterwards. So it's mainly chipv's scripts, and a few old ones that don't work on chrome yet. I mainly put it up for ppl interested in it (maybe new developers?).

And about greasemonkey in ff4beta: Scriptish seems to be new, but will need some adaptions. But probably greasemonkey will have a new version too, nightlies can be tried atm: https://arantius.com/misc/gm-nightly/ (likely to be unstable though).


If you can think of a way to emulate multiple AJAX requests safely in Chrome let me know, there is a good reason why those scripts don't work in Chrome.
User avatar
Sergeant 1st Class chipv
 
Posts: 2751
Joined: Mon Apr 28, 2008 5:30 pm

Re: For GC?

Postby sherkaner on Tue Dec 21, 2010 4:38 pm

chipv wrote:
sherkaner wrote:Well, there aren't that many scripts that have active developers and aren't working in chrome, actually.

viewtopic.php?f=526&t=132420#p2916271 gives a nice overview, chatglove was changed to work with chrome afterwards. So it's mainly chipv's scripts, and a few old ones that don't work on chrome yet. I mainly put it up for ppl interested in it (maybe new developers?).

And about greasemonkey in ff4beta: Scriptish seems to be new, but will need some adaptions. But probably greasemonkey will have a new version too, nightlies can be tried atm: https://arantius.com/misc/gm-nightly/ (likely to be unstable though).


If you can think of a way to emulate multiple AJAX requests safely in Chrome let me know, there is a good reason why those scripts don't work in Chrome.


What exactly is the problem then? I might have missed something, but afaik normal javascript techniques for that should work in Chrome, and if chatglove works in chrome with its multiple AJAX requests, so I don't see the problem.
Colonel sherkaner
 
Posts: 1595
Joined: Thu May 03, 2007 3:21 am
Location: Zwolle

Re: For GC?

Postby chipv on Tue Dec 21, 2010 6:23 pm

Ok let me see.

chatglove gets single ajax reqs at a time, maprank for example has to manage multiple simultaneous ajax reqs at a time
and uses arrays for efficiency. Arrays here is mandatory to make sure the order of the incoming pages doesn't matter
(see Map Rank to see why), this is a non-trivial difference and is common with all the scripts that need to poll the API
with results spanning more than one page.

Map Rank also does cross-site requests , something that, at present , is not easy in Chrome if not impossible last time
I checked.

Other changes for Chrome would be relatively trivial.
User avatar
Sergeant 1st Class chipv
 
Posts: 2751
Joined: Mon Apr 28, 2008 5:30 pm

Re: For GC?

Postby sherkaner on Wed Dec 22, 2010 4:03 am

chipv wrote:Ok let me see.

chatglove gets single ajax reqs at a time, maprank for example has to manage multiple simultaneous ajax reqs at a time
and uses arrays for efficiency. Arrays here is mandatory to make sure the order of the incoming pages doesn't matter
(see Map Rank to see why), this is a non-trivial difference and is common with all the scripts that need to poll the API
with results spanning more than one page.

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.

chipv wrote:Map Rank also does cross-site requests , something that, at present , is not easy in Chrome if not impossible last time
I checked.

Yeah, I haven't found a way to do that either. This could be a reason not to support Chrome.
Colonel sherkaner
 
Posts: 1595
Joined: Thu May 03, 2007 3:21 am
Location: Zwolle

Re: For GC?

Postby chipv on Wed Dec 22, 2010 9:21 am

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.
User avatar
Sergeant 1st Class chipv
 
Posts: 2751
Joined: Mon Apr 28, 2008 5:30 pm

Re: For GC?

Postby Dako on Wed Dec 22, 2010 9:35 am

I use multiple page loads in WTG and it seems to work in Chrome.

Code: Select all
/**
 * Watch all tournaments's active games
 *
 * @param {String} tournament name
 * @param {Integer} page id
 */
function watchTournament(tournamentName, page, state) {
  var requestPage, request, data, gamesNumbers, i, e;
  tournamentName = encodeURIComponent(tournamentName);
  requestPage = window.location.protocol + '//www.conquerclub.com/api.php?mode=gamelist&gs=' + state + '&to=' + tournamentName + '&page=' + page;
  request = new XMLHttpRequest();
  request.open('GET', requestPage, true);
  request.overrideMimeType('text/xml');
     
  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      try {
        data = request.responseXML;
       
        maxPages = /\d+ of (\d+)/i.exec(data.getElementsByTagName('page')[0].childNodes[0].nodeValue);
        if (maxPages[1] > page) {
          watchTournament(username, page + 1, state);
        }
       
        gamesNumbers = data.getElementsByTagName('game_number');
        for (i in gamesNumbers) {
          watchGame(gamesNumbers[i].childNodes[0].nodeValue);
        }
      }
      catch (e) {
      //~ alert(e.message);
      }
    }
  };
  request.send(null);
}
Image
User avatar
Colonel Dako
 
Posts: 3987
Joined: Sun Aug 26, 2007 9:07 am
Location: St. Petersburg, Russia

Re: For GC?

Postby chipv on Wed Dec 22, 2010 9:48 am

This is the same issue as chatglove. Neither piece of software needs to know when all pages have been received because both pieces of code
can go ahead and process each request on the fly without caring about the order.

I have a number of things to do after all pages have been received, and cannot do things on the fly as my data is collective.

I still convinced it is possible to do some of my scripts in chrome but not any of those that do cross-site requests.
User avatar
Sergeant 1st Class chipv
 
Posts: 2751
Joined: Mon Apr 28, 2008 5:30 pm

Re: For GC?

Postby chipv on Wed Dec 22, 2010 9:50 am

I think I will have a go at tournament stats and see what happens, cannot do Map Rank as we discussed.
Image
User avatar
Sergeant 1st Class chipv
 
Posts: 2751
Joined: Mon Apr 28, 2008 5:30 pm

Re: For GC?

Postby chipv on Wed Dec 22, 2010 9:55 am

All cross-site, looks like I did have a look at this already.

The 2 that are not cross-site are Clan Rank and Assault Odds.
User avatar
Sergeant 1st Class chipv
 
Posts: 2751
Joined: Mon Apr 28, 2008 5:30 pm

Re: For GC?

Postby Dako on Wed Dec 22, 2010 9:59 am

chipv wrote:This is the same issue as chatglove. Neither piece of software needs to know when all pages have been received because both pieces of code can go ahead and process each request on the fly without caring about the order.

I have a number of things to do after all pages have been received, and cannot do things on the fly as my data is collective.

I do as well - here is one piece of code for you :D.
Code: Select all
function getGameRow(gameNumber) {
  var requestPage, request, data, table, games, game, players, player, playersArray, i, e;
  var gameNumber, tournament, privateGame, speedGame, map, gameType, initialTroops, playOrder, bonusCards, fortifications, warFog, round, timeRemaining;
 
  requestPage = window.location.protocol + '//www.conquerclub.com/api.php?mode=gamelist&gn=' + gameNumber;
  request = new XMLHttpRequest();
  request.open('GET', requestPage, true);
  request.overrideMimeType('text/xml');
 
  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      try {
        data = request.responseXML;
        games = data.getElementsByTagName('games')[0].attributes;
        if (games.getNamedItem('total').nodeValue != '0') {
          gameNumber = data.getElementsByTagName('game_number')[0].childNodes[0].nodeValue;
          gameState = data.getElementsByTagName('game_state')[0].childNodes[0].nodeValue;
          tournament = '';
          if (data.getElementsByTagName('tournament')[0].childNodes.length > 0) {
            tournament = data.getElementsByTagName('tournament')[0].childNodes[0].nodeValue;
          }
          privateGame = data.getElementsByTagName('private')[0].childNodes[0].nodeValue;
          speedGame = data.getElementsByTagName('speed_game')[0].childNodes[0].nodeValue;
          map = data.getElementsByTagName('map')[0].childNodes[0].nodeValue;
         
          // Add unique maps to global array
          if (!(Maps_Array.has(map))) {
            Maps_Array.push(map);
          }
         
          gameType = data.getElementsByTagName('game_type')[0].childNodes[0].nodeValue;
          initialTroops = data.getElementsByTagName('initial_troops')[0].childNodes[0].nodeValue;
          playOrder = data.getElementsByTagName('play_order')[0].childNodes[0].nodeValue;
          bonusCards = data.getElementsByTagName('bonus_cards')[0].childNodes[0].nodeValue;
          fortifications = data.getElementsByTagName('fortifications')[0].childNodes[0].nodeValue;
          warFog = data.getElementsByTagName('war_fog')[0].childNodes[0].nodeValue;
          round = data.getElementsByTagName('round')[0].childNodes[0].nodeValue;
          timeRemaining = data.getElementsByTagName('time_remaining')[0].childNodes[0].nodeValue;
          players = data.getElementsByTagName('player');
 
          playersArray = new Array();
          for (i = 0; i < players.length; i++) {
            player = players[i];

            if (player.attributes.getNamedItem('state').nodeValue == 'Open') {
              player = new playerObject('', '', '', '', '', player.attributes.getNamedItem('state').nodeValue);
            } else {
              player = new playerObject(player.childNodes[0].nodeValue, '', '', '', '', player.attributes.getNamedItem('state').nodeValue);
            }
            playersArray.push(player);
           
            // Add unique players to global array
            if (player.userid != '' && !(Players_Array.has(player.userid))) {
              Players_Array.push(player.userid);
            }
          }
 
          game = new gameObject(gameNumber, gameState, tournament, privateGame, speedGame, map, gameType, initialTroops, playOrder, bonusCards, fortifications, warFog, round, timeRemaining, playersArray);
          Games_Array.push(game);
         
        } else {
          // Remove unexistent game
          toggleGame(gameNumber, false);
          updateTabNumber();
        }
       
        if (Games_Array.length == getWatchedGamesNumber()) {
          addTabContent();
        }
      }
      catch (e) {
        //~ alert(e.message);
      }
    }
  };
  request.send(null);
}


Here Games_Array is a global variable that I check in each request to fire addTabContent which can work only with complete data set.
Image
User avatar
Colonel Dako
 
Posts: 3987
Joined: Sun Aug 26, 2007 9:07 am
Location: St. Petersburg, Russia

Re: For GC?

Postby chipv on Wed Dec 22, 2010 10:04 am

Yes I can see although request is not an array, that is what I am referring to.

Now if this does work (and come to think of it, I did do Clan Rank in Chrome at one point so it should do)
some of my scripts use the old method of polling a text file (cross site) for the version number.

I believe some of you use other methods that would work in both FF and Chrome, is that right?
I could get a lot done if this is circumvented.
User avatar
Sergeant 1st Class chipv
 
Posts: 2751
Joined: Mon Apr 28, 2008 5:30 pm

Re: For GC?

Postby sherkaner on Wed Dec 22, 2010 11:02 am

chipv wrote:I believe some of you use other methods that would work in both FF and Chrome, is that right?
I could get a lot done if this is circumvented.

Not really, checking for versions just doesn't work in chrome so far, it's still a cross-side request. The only thing I do is getting it from userscripts directly, so I don't have to update two files for updating the version.
Colonel sherkaner
 
Posts: 1595
Joined: Thu May 03, 2007 3:21 am
Location: Zwolle

Re: For GC?

Postby Foxglove on Wed Dec 22, 2010 1:51 pm

chatglove does spin off many requests simultaneously (though you're right, chip, it doesn't check for > 200 games). Like Dako, I also do processing once everything is returned. The difference is that I just used a basic counter variable to keep track of my returned requests, I didn't use an array.
Brigadier Foxglove
 
Posts: 1308
Joined: Sun Dec 16, 2007 1:05 pm

Re: For GC?

Postby Foxglove on Wed Dec 22, 2010 1:53 pm

chipv wrote:Yes I can see although request is not an array, that is what I am referring to.

Now if this does work (and come to think of it, I did do Clan Rank in Chrome at one point so it should do)
some of my scripts use the old method of polling a text file (cross site) for the version number.

I believe some of you use other methods that would work in both FF and Chrome, is that right?
I could get a lot done if this is circumvented.


dwilhelmi just went through the process of updating chatglove to work in chrome, and a lot chatglove's handling of version checks/ajax requests was based on your scripts, chip - so maybe he will have ideas on chromifying your code.
Brigadier Foxglove
 
Posts: 1308
Joined: Sun Dec 16, 2007 1:05 pm

Re: For GC?

Postby chipv on Wed Dec 22, 2010 2:05 pm

Thanks Foxy, all makes sense. I think once I get around the version check, should be ok
(should be as Clan Rank used to work), cannot get around Map Rank though, pity,
although I could make it reduced functionality for Chrome perhaps.
User avatar
Sergeant 1st Class chipv
 
Posts: 2751
Joined: Mon Apr 28, 2008 5:30 pm


Return to Tool Archives

Who is online

Users browsing this forum: No registered users