Saturday, January 29, 2011

Creates a second attack button on the top of a espionage report.


// ==UserScript==
// @name           spy attack
// @namespace      marshen
// @description    Creates a second attack button on the top of a espionage report.
// @include        http://*.ogame.*/game/index.php?page=showmessage*
// @author         marshen
// ==/UserScript==

(function() {

 function getElementsByClass (cName, domNode) {
  if (cName == undefined || cName.length == 0) return;
  if (domNode == undefined) domNode = document;
  
  if (domNode.getElementsByClassName)
   return domNode.getElementsByClassName(cName);
  
  // browser doesn't support getElementsByClassName
  cName = " " + cName + " "; // add spaces here so that we won't find class "a" in className == "abc"
  var elements = domNode.getElementsByTagName('*');
  var res = new Array();
  for (var i = 0; i < elements.length; i++) {
   var className = " " + elements[i].className + " ";
   if (className.indexOf(cName) > -1) {
    res.push(elements[i]);
   }
  }
  
  return res;
 }

 var wrap = document.getElementById('wrapper');
 if (wrap) {
  var attackButton = getElementsByClass('attack', wrap);
  
  if (attackButton.length > 0) {
   var spyTable = getElementsByClass('spy', wrap);
   
   if (spyTable.length > 0) {
    var newAttackButton = attackButton[0].cloneNode(true);
    newAttackButton.setAttribute('colspan', '6');
    var newTR = document.createElement('tr');
    newTR.appendChild(newAttackButton);
    
    spyTable[0].appendChild(newTR);
   }
  }
 }
 
})();

0 comments:

Post a Comment