Tuesday, August 18, 2009

Scripting...I love weakly typed languages :P

Hi fellas I was a bit busy these few days. I was trying to get the basics of Scripting and i have been pretty successful. So here's my first UserScript for mozilla for the site travian.com. This little script lets you select all the checkboxes on the report page for quick deletion. Have fun :)

// Use this tiny little script to select/unselect all reports on the reports page
// of travian so that you could delete them quickly.
// ==UserScript==
// @name SlectAll
// @namespace obnoxiouscoder.blogspot.com
// @decription "Select All" reports on the page with a click for deletion.
// @include http//*.travian.*/berichte.php*
// @include *.travian.*/berichte.php*
// @email obnoxiouscoder@gmail.com
// ==/UserScript==
// *********************************************************


var nbsp = document.createTextNode( "\u00A0" );
var newChkBox = document.createElement("input");
newChkBox.type = "checkbox";
newChkBox.id = "chk_box";
newChkBox.addEventListener("click",function()
{
var chkBox = document.getElementsByTagName("input");
for(i=0; i
{
if(chkBox[i].getAttribute('type') == "checkbox")
{
if(chkBox[i].getAttribute("id") != "chk_box")
{
if(chkBox[i].checked == true)
{
chkBox[i].checked =false;
}
else
{
chkBox[i].checked = true;
}
}
}
}
},false);

//CheckBox Text
var newTxt = document.createElement("b");
newTxt.setAttribute("style","color: #00CC33;");
var chkboxTxt = document.createTextNode("SelectAll");
newTxt.appendChild(chkboxTxt);

//target Button
var trgtButton = document.getElementById("btn_delete");

//insertAfter Function.
function insertAfter(newElement,targetElement)
{
var parent = targetElement.parentNode;
if (parent.lastChild == targetElement)
{
parent.appendChild(newElement);
}
else
{
parent.insertBefore(newElement,targetElement.nextSibling);
}
}

//Lets Roll Baby
insertAfter(newChkBox,trgtButton);
newChkBox.parentNode.insertBefore(nbsp,newChkBox);
insertAfter(newTxt,newChkBox);

No comments: