Coding AJAX-compatible GM scripts

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

Moderators: Global Moderators, Tech Team

Forum rules
Please read the Community Guidelines before posting.

Coding AJAX-compatible GM scripts

Postby lackattack on Tue Sep 11, 2007 6:55 pm

Here's a tip for anyone trying to fix BOB. There is an function I put in called handleResponse() that runs each time an AJAX response comes in. Perhaps the GM script could re-define that function to call gm_ConquerClubGame() at the end?
Last edited by lackattack on Thu Sep 13, 2007 8:57 am, edited 2 times in total.
User avatar
Private 1st Class lackattack
Retired Administrator
 
Posts: 6235
Joined: Sun Jan 01, 2006 10:34 pm
Location: Montreal, QC
Medals: 9
Standard Achievement (1) Doubles Achievement (1) Triples Achievement (1) Freestyle Achievement (1) Speed Achievement (1)
Teammate Achievement (1) Cross-Map Achievement (1) General Achievement (2)

Postby wacicha on Tue Sep 11, 2007 7:25 pm

wow you guys amaze me, I can barly figure how to get this stuff running and you guys talk about all this programing
Image
User avatar
Major wacicha
Retired Team Member
 
Posts: 3953
Joined: Fri Jan 27, 2006 6:51 pm
Medals: 33
Standard Achievement (4) Doubles Achievement (3) Triples Achievement (1) Terminator Achievement (4) Assassin Achievement (1)
Manual Troops Achievement (2) Freestyle Achievement (2) Fog of War Achievement (1) Teammate Achievement (1) Cross-Map Achievement (2)
Ratings Achievement (4) Training Achievement (1) Tournament Contribution (1) General Contribution (6)

Postby jiminski on Tue Sep 11, 2007 7:27 pm

i know Wac .. thank goodness for them!
User avatar
Colonel jiminski
 
Posts: 5416
Joined: Tue Feb 20, 2007 3:30 pm
Location: London
Medals: 29
Standard Achievement (3) Doubles Achievement (3) Triples Achievement (3) Quadruples Achievement (1) Terminator Achievement (2)
Freestyle Achievement (2) Fog of War Achievement (2) Speed Achievement (2) Teammate Achievement (2) Cross-Map Achievement (3)
Ratings Achievement (1) Tournament Achievement (3) Clan Achievement (2)

Postby mfontolan on Tue Sep 11, 2007 9:07 pm

Lack, I see your new code and I can not figure out how capture the refreshed code.
Maybe I am doing something wrong, but I can not intercept your calls!
For example, I can do the clock works but I can get the changes after it, for example, when the turn begins!
Do you have plans to put stats, card count and map inspect on original CC code?

Code: Select all
// ==UserScript==
// @name          Conquer Club - Ajax BOB
// @namespace     http://www.itj.com.br/
// @description   Ajax BOB
// @include       http://*conquerclub.com*
// ==/UserScript==

var TimeStr = document.getElementById('clock').innerHTML;
var TargetTime = TimeStr.split(/hrs\n|min\n|sec/);
var CurrHour = parseInt(TargetTime[0]);
var CurrMinute = parseInt(TargetTime[1]);
var CurrSecond = parseInt(TargetTime[2]);

ClockInterval = window.setInterval(ClockTimer, 1000);

function ClockTimer()
{
   --CurrSecond;
   if(CurrSecond < 0 ){
     --CurrMinute;
     if( CurrMinute < 0 ){
       --CurrHour;
       if( CurrHour < 0 ){
         CurrHour = 0;
       }
       CurrMinute = 59;
     }
     CurrSecond = 59;
   }
   StrClock = document.getElementById('clock');
   if (CurrHour < 10) {
      StrClock.innerHTML = '0' + CurrHour + 'hrs ';
   } else {
      StrClock.innerHTML = CurrHour + 'hrs ';
   }
   if (CurrMinute < 10) {
      StrClock.innerHTML += '0' +   CurrMinute + 'min ';
   } else {
      StrClock.innerHTML += CurrMinute + 'min ';
   }
   if (CurrSecond < 10) {
      StrClock.innerHTML += '0' +   CurrSecond + 'sec ';
   } else {
      StrClock.innerHTML += CurrSecond + 'sec ';
   }
   
   var CurrDate = new Date();
   if (CurrDate.getHours() < 10) {
      StrClock.innerHTML += ' @ <b>0' + (CurrDate.getHours()) + ':</b>';
   } else {
      StrClock.innerHTML += ' @ <b>' + (CurrDate.getHours()) + ':</b>';
   }
   if (CurrDate.getMinutes() < 10) {
      StrClock.innerHTML += '<b>0' + (CurrDate.getMinutes()) + '</b>';
   } else {
      StrClock.innerHTML += '<b>' + (CurrDate.getMinutes()) + '</b>';
   }
}

var handleResponse = function()
{
   alert('Nothing will happen');
}
Brazil #3 @ Agu, 2007.
User avatar
Private 1st Class mfontolan
 
Posts: 23
Joined: Wed Feb 21, 2007 5:48 pm
Location: South
Medals: 7
Standard Achievement (3) Terminator Achievement (2) Ratings Achievement (2)

Postby DiM on Tue Sep 11, 2007 9:14 pm

hmm and i though the xml is a bugger. now look at that pretty code :lol:
“In the beginning God said, the four-dimensional divergence of an antisymmetric, second rank tensor equals zero, and there was light, and it was good. And on the seventh day he rested.”- Michio Kaku
Image
User avatar
Major DiM
 
Posts: 10387
Joined: Wed Feb 14, 2007 6:20 pm
Location: making maps for scooby snacks
Medals: 45
Standard Achievement (2) Doubles Achievement (2) Triples Achievement (1) Terminator Achievement (2) Assassin Achievement (2)
Freestyle Achievement (1) Nuclear Spoils Achievement (1) Fog of War Achievement (2) Speed Achievement (1) Teammate Achievement (1)
Cross-Map Achievement (2) Ratings Achievement (3) Tournament Achievement (4) General Achievement (4) Map Contribution (10)
Tournament Contribution (4) General Contribution (3)

Postby lackattack on Tue Sep 11, 2007 9:41 pm

What if you had

Code: Select all
function handleResponse()
{
   alert('Nothing will happen');
}

instead of

Code: Select all
var handleResponse = function()
{
   alert('Nothing will happen');
}
User avatar
Private 1st Class lackattack
Retired Administrator
 
Posts: 6235
Joined: Sun Jan 01, 2006 10:34 pm
Location: Montreal, QC
Medals: 9
Standard Achievement (1) Doubles Achievement (1) Triples Achievement (1) Freestyle Achievement (1) Speed Achievement (1)
Teammate Achievement (1) Cross-Map Achievement (1) General Achievement (2)

Postby AAFitz on Tue Sep 11, 2007 9:45 pm

lackattack wrote:Here's a tip for anyone trying to fix BOB. There is an function I put in called handleResponse() that runs each time an AJAX response comes in. Perhaps the GM script could re-define that function to call gm_ConquerClubGame() at the end?


tell you what.......you install this crap for me on my computer, and ill make your moves in your game so you can win one

this would have been so much funnier if it wasnt for that "neverland game we played"
User avatar
Major AAFitz
 
Posts: 7216
Joined: Sun Sep 17, 2006 9:47 am
Location: On top of the World 2.1
Medals: 84
Monthly Leader Bronze (1) Standard Achievement (4) Doubles Achievement (4) Triples Achievement (4) Quadruples Achievement (3)
Terminator Achievement (2) Assassin Achievement (3) Manual Troops Achievement (4) Freestyle Achievement (4) Polymorphic Achievement (2)
Nuclear Spoils Achievement (3) Fog of War Achievement (4) Trench Warfare Achievement (2) Speed Achievement (4) Teammate Achievement (3)
Random Map Achievement (2) Cross-Map Achievement (3) Ratings Achievement (4) Tournament Achievement (8) General Achievement (2)
Clan Achievement (8) Tournament Contribution (8) General Contribution (2)

Postby lackattack on Tue Sep 11, 2007 10:48 pm

:lol:
User avatar
Private 1st Class lackattack
Retired Administrator
 
Posts: 6235
Joined: Sun Jan 01, 2006 10:34 pm
Location: Montreal, QC
Medals: 9
Standard Achievement (1) Doubles Achievement (1) Triples Achievement (1) Freestyle Achievement (1) Speed Achievement (1)
Teammate Achievement (1) Cross-Map Achievement (1) General Achievement (2)

Postby mfontolan on Wed Sep 12, 2007 6:33 am

Here is where I think we can go for...

Code: Select all
var bob_gameLog = unsafeWindow.gameLog;
var newhandleResponse = unsafeWindow.handleResponse;
unsafeWindow.handleResponse = function() {
  bob_gameLog.innerHTML += 'I am here!<br>';
  return newhandleResponse();
}
Brazil #3 @ Agu, 2007.
User avatar
Private 1st Class mfontolan
 
Posts: 23
Joined: Wed Feb 21, 2007 5:48 pm
Location: South
Medals: 7
Standard Achievement (3) Terminator Achievement (2) Ratings Achievement (2)

Postby Ishiro on Wed Sep 12, 2007 7:13 am

This might work... I'm looking at trying it now.
Image
User avatar
Corporal 1st Class Ishiro
 
Posts: 324
Joined: Mon Jul 17, 2006 5:53 pm
Location: Under the Rainbow
Medals: 10
Standard Achievement (2) Doubles Achievement (1) Triples Achievement (1) Terminator Achievement (1) Assassin Achievement (1)
Cross-Map Achievement (1) Ratings Achievement (1) General Contribution (2)

Postby Ishiro on Wed Sep 12, 2007 9:21 am

lackattack wrote:What if you had

Code: Select all
function handleResponse()
{
   alert('Nothing will happen');
}

instead of

Code: Select all
var handleResponse = function()
{
   alert('Nothing will happen');
}


I tried that and it didn't work. Your version of the function executed, and not mine.
Image
User avatar
Corporal 1st Class Ishiro
 
Posts: 324
Joined: Mon Jul 17, 2006 5:53 pm
Location: Under the Rainbow
Medals: 10
Standard Achievement (2) Doubles Achievement (1) Triples Achievement (1) Terminator Achievement (1) Assassin Achievement (1)
Cross-Map Achievement (1) Ratings Achievement (1) General Contribution (2)

Postby Ishiro on Wed Sep 12, 2007 12:09 pm

mfontolan wrote:Here is where I think we can go for...

Code: Select all
var bob_gameLog = unsafeWindow.gameLog;
var newhandleResponse = unsafeWindow.handleResponse;
unsafeWindow.handleResponse = function() {
  bob_gameLog.innerHTML += 'I am here!<br>';
  return newhandleResponse();
}


This works for inserting code into the AJAX, or replacing functions entirely. Now just the hard work of converting the old scripts to work in the new formats.
Image
User avatar
Corporal 1st Class Ishiro
 
Posts: 324
Joined: Mon Jul 17, 2006 5:53 pm
Location: Under the Rainbow
Medals: 10
Standard Achievement (2) Doubles Achievement (1) Triples Achievement (1) Terminator Achievement (1) Assassin Achievement (1)
Cross-Map Achievement (1) Ratings Achievement (1) General Contribution (2)

Postby mfontolan on Wed Sep 12, 2007 1:37 pm

Ishiro wrote:This works for inserting code into the AJAX, or replacing functions entirely. Now just the hard work of converting the old scripts to work in the new formats.


We can work together and make a new tool.

This are working and calling CC original function (...I think... :D )
Code: Select all
// ==UserScript==
// @name          Conquer Club - Ajax BOB
// @namespace     http://www.itj.com.br/
// @description   Ajax BOB
// @include       http://*conquerclub.com*
// ==/UserScript==

var bob_gameLog = unsafeWindow.gameLog;
var newhandleResponse = unsafeWindow.handleResponse;
unsafeWindow.handleResponse = function() {
  bob_gameLog.innerHTML += 'I am here!<br>';
  return newhandleResponse();
}


var TimeStr = document.getElementById('clock').innerHTML;
var TargetTime = TimeStr.split(/hrs\n|min\n|sec/);
var CurrHour = parseInt(TargetTime[0]);
var CurrMinute = parseInt(TargetTime[1]);
var CurrSecond = parseInt(TargetTime[2]) - 2;

ClockInterval = window.setInterval(ClockTimer, 1000);


function ClockTimer()
{
   --CurrSecond;
   if(CurrSecond < 0 ){
     --CurrMinute;
     if( CurrMinute < 0 ){
       --CurrHour;
       if( CurrHour < 0 ){
         CurrHour = 0;
       }
       CurrMinute = 59;
     }
     CurrSecond = 59;
   }
   StrClock = document.getElementById('clock');
   StrClock.innerHTML = zslash(CurrHour, 2) + 'hrs ' + zslash(String(CurrMinute), 2) + 'min ' + zslash(CurrSecond, 2) + 'sec ';
   var CurrDate = new Date();
   StrClock.innerHTML += ' @ <b>' + zslash(CurrDate.getHours(), 2) + ':' + zslash(CurrDate.getMinutes(), 2) + '</b>';
}

function zslash(svalue, iwidth)
{
   var szero = String(svalue);
   var ch = szero.substr(0,1);
   while (ch == ' ')
   {
      szero = szero.substr(1, szero.length);
      ch = szero.substr(0,1);
   }
   ch = szero.substr(szero.length - 1, szero.length);
   while (ch == ' ')
   {
      szero = szero.substr(0, szero.length - 1);
   ch = szero.substr(szero.length - 1, szero.length);
   }
   
   var i=0;
   for (i=0; i < (iwidth - szero.length); i++)
   {
      szero = '0' + szero;
   }   

   return szero;
}
Brazil #3 @ Agu, 2007.
User avatar
Private 1st Class mfontolan
 
Posts: 23
Joined: Wed Feb 21, 2007 5:48 pm
Location: South
Medals: 7
Standard Achievement (3) Terminator Achievement (2) Ratings Achievement (2)

Postby Ishiro on Wed Sep 12, 2007 2:07 pm

I can't seem to get the Options serializations to work like it does in the BOB script, so I'm back to coding in options that will have to be edited by the user.

The following code snippet put in a greasemonkey script will put the confirmation popups back on the various buttons.
Code: Select all
var confirmEnds = true;
var confirmAutoAttack = true;
var confirmDeploy = true;
var confirmChat = true;
var dashboard = document.getElementById('dashboard');

var newsendRequest = unsafeWindow.sendRequest;

unsafeWindow.sendRequest = function(command) {
/* ---    Confirmation Popups --- */
   if (((command == 'End Attacks' || command == 'End Fortification' || (command == 'Fortify' && !dashboard.innerHTML.has("Unlimited"))) && confirmEnds) || (command == 'Auto-Attack' && confirmAutoAttack) || (command == 'Deploy' && confirmDeploy) || (command == 'Post Message' && confirmChat))
   {
      if (confirm("Are you sure?"))
      {
         return newsendRequest(command);
      }
      else {
         return false;
      }
   }
   else {
      return newsendRequest(command);
   }
}
Image
User avatar
Corporal 1st Class Ishiro
 
Posts: 324
Joined: Mon Jul 17, 2006 5:53 pm
Location: Under the Rainbow
Medals: 10
Standard Achievement (2) Doubles Achievement (1) Triples Achievement (1) Terminator Achievement (1) Assassin Achievement (1)
Cross-Map Achievement (1) Ratings Achievement (1) General Contribution (2)

Postby Ishiro on Wed Sep 12, 2007 3:54 pm

Progress update...

I have everything working on page load, except color blind armies.

However, currently nothing updates as the AJAX updates. The reason is that the script was written to execute once per page, so, no care was given to being able to rebuild already built sections. The result right now is that every time you take an action, items like the player stats, text maps and menus will build 4 times. After taking a regular simple turn (begin, deploy, attack, advance, end attack, end fortification) you'll have 24 copies of each of the BOB items.

Working on it, but may not have a solution until next week. I'll put up what I have later when I have access to a place to upload the script.
Image
User avatar
Corporal 1st Class Ishiro
 
Posts: 324
Joined: Mon Jul 17, 2006 5:53 pm
Location: Under the Rainbow
Medals: 10
Standard Achievement (2) Doubles Achievement (1) Triples Achievement (1) Terminator Achievement (1) Assassin Achievement (1)
Cross-Map Achievement (1) Ratings Achievement (1) General Contribution (2)

Next

Return to Tool Archives

Who is online

Users browsing this forum: No registered users and 1 guest

Login