Throne3d

NAFlagS

Jun 23rd, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.74 KB | None | 0 0
  1. javascript:
  2. function demFlags(){
  3.     var a = $("div[id*='flags_select_'] div[id*='_content'] tr:has(td) td:nth-child(1)");
  4.     if (a.length <= 0){
  5.         alert("Please open one of the flag change screens!");
  6.     } else {
  7.         var b = prompt("Which row should we use for flags? (e.g. '1' means 'resource production', and so on)");
  8.         if (parseInt(b).toString() !== b) alert("Not a number! D:<");
  9.         else {
  10.             var rowNum = parseInt(b) - 1;
  11.             var flagList = $("td:not(td:nth-child(1))", $("div[id*='flags_select_'] div[id*='_content'] tr:has(td)")[rowNum]);
  12.             var flagCounts = [];
  13.             var flagCount = 0;
  14.             var bit = 0;
  15.             flagList.each(function(){
  16.                 var count = $(this).text().trim();
  17.                 if (count === "") count = 0;
  18.                 else count = parseInt(count);
  19.                 flagCounts[bit] = count;
  20.                 flagCount += count;
  21.                 bit++;
  22.             });
  23.             var villageList = $("#techs_table tr[id*='village'] td[id*='flag']");
  24.             villageList.each(function(){
  25.                 $("a[onclick*='event']", $(this)).click();
  26.             });
  27.             setTimeout(function(){ villageList.each(function(){
  28.                 villageID = $(this).html().match(/FlagsOverview.selectFlag\(event, (\d+)\)/g)[0].match(/(\d+)/)[0];
  29.                 while (flagCounts[bit-1] === 0) { bit--; if (bit <= 0) { alert("No more flags!"); return false; } }
  30.                 FlagsOverview.assignFlag(rowNum+1, bit, villageID);
  31.                 flagCounts[bit-1]--;
  32.                 flagCount--;
  33.             }); alert("WE R BE FINISHED (hopefully - might need to wait for AJAX to load...)"); }, 1000);
  34.         }
  35.     }
  36. }
  37. void(demFlags());
Advertisement
Add Comment
Please, Sign In to add comment