var autoEndTurnOnce;
var autoEndTurn;
var endTurnButton;
unsafeWindow.onload = stormBot;
function stormBot()
{
var parent = document.getElementById("iogc-FavoritePlayersPanel");
autoEndTurnOnce = checkbox("autoEndTurnOnce", "Auto End Turn (Once)", parent);
autoEndTurn = checkbox("autoEndTurn", "Auto End Turn", parent);
endTurnButton = getElementByClass("gwt-Button");
endTurnButton.addEventListener("DOMAttrModified", endTurnTriggered, false);
}
function endTurnTriggered()
{
if (endTurnButton.style.display != "none")
{
if (autoEndTurnOnce.checked)
{
autoEndTurnOnce.checked = false;
forceClick(endTurnButton);
}
else if (autoEndTurn.checked)
{
forceClick(endTurnButton);
}
}
}
function forceClick(target)
{
var oEvent = document.createEvent( "MouseEvents" );
oEvent.initMouseEvent("click", true, true,window, 1, 1, 1, 1, 1, false, false, false, false, 0, target);
target.dispatchEvent(oEvent);
}
function checkbox(name, str, parent)
{
var box = document.createElement("input");
box.setAttribute("type", "checkbox");
box.setAttribute("name", name);
box.setAttribute("value", "");
box.checked = false;
parent.appendChild(box);
var newCell = parent.appendChild(document.createElement("td"));
var txtCell = document.createTextNode(str);
newCell.appendChild(txtCell);
return box;
}
function getElementByClass(theClass)
{
var allHTMLTags = new Array();
//Create Array of All HTML Tags
var allHTMLTags = document.getElementsByTagName("*");
//Loop through all tags using a for loop
for (i=0; i<allHTMLTags.length; i++)
{
//Get all tags with the specified class name.
if (allHTMLTags[i].className==theClass)
{
return allHTMLTags[i];
}
}
}