Nintendo Wii forums Forum for writers phpBB mods Essays on copyright Dating advice Narnia forums

GreaseMonkey script for Bioware forums

I wanted to do a little bit of JavaScript work, and I figured that creating my first GreaseMonkey script would be an ideal way to do it.  Even more, I figured a simple one-liner would be an easy start.  Ha ha on me.  I was wrong.

What I wanted to do was to stop the Bioware forums from setting the focus on the login field.  Because they do that, I cannot scroll with the mouse wheel.  It is very annoying to have to click outside of the login box on every single page that I read.  So I figured I'd just use the JavaScript blur() to stop the page from being lame, right?  Wrong.

Even with my simple one-liner, I encountered a show-stopping problem that uncovered a nuance in how GreaseMonkey scripts are run.  The Bioware site runs this:

window.onload = startItUp;

...And that "startItUp" function is what puts the focus on the field.  The problem?  GreaseMonkey scripts are run before window.onload, effectively removing their ability to rewrite the page.  If you are a page owner and would like to defeat any GreaseMonkey scripts, all you have to do is run your functions on window.onload, and GreaseMonkey scripts will not be able to overwrite you.

Mostly.

Admitting defeat is not easy, so I worked with Rod Mcguire on the GreaseMonkey group, and we found that adding a setTimeout to my code would effectively delay the code execution until after the window.onload.  This is possible because setTimeout is asynchronous.  So my little one-liner, which took 2 minutes to write, took 3 or 4 hours to debug and complete – and in the end, wasn't much of a one-liner anymore.  Here it is:

window.addEventListener(
'load',
function() {
setTimeout(
function () {
document.getElementById('username').blur();
},
10);
},
false
);

If you read the Bioware forums and are annoyed with how it interferes with scrolling, then you are free to install this script in your GreaseMonkey-compatible browser.

Navigate

« Some lolcatz 4 u | Main | GreaseMonkey script for Digg friends stuff »

Nav by tag: greasemonkey
Main | GreaseMonkey script for Digg friends stuff »
Nav by tag: tech
« Custom Profile Fields 1.2.1 for phpBB | Main | GreaseMonkey script for Digg friends stuff »
Bookmark It! Technorati del.icio.us Netvouz DZone ThisNext Wists blinkbits BlinkList blogmarks blogtercimlap Blue Dot Bumpzee co.mments connotea DotNetKicks Fark feedmelinks Fleck Furl Gwar Haohao Hemidemi IndiaGram IndianPad Internetmedia kick.ie LinkaGoGo Linkter Ma.gnolia MyShare Netscape NewsVine PlugIM PopCurrent ppnow RawSugar Reddit Shadows Simpy Slashdot Smarking Spurl Webride YahooMyWeb
TrackBack

TrackBack URL for this entry:
http://www.outshine.com/cgi-bin/outshine/trackback.cgi/22

Post a comment

Verification (needed to reduce spam):