[Greasemonkey] Bug: User script doesn't always execute in GM 0.5

Michael Kraft mjk4984 at yahoo.com
Sat Aug 6 11:51:10 EDT 2005

I'm using Firefox 1.0.6 under Windows XP SP2.

I wrote a script that will keep clicking on a button or a link depending on
which is on the page at the time.  I use it to automate playing
KingdomOfLoathing.  The script works great in GM 0.3.5, but haphazzardly in GM
0.5.  In 0.5 sometimes it works and sometimes it does not.

The strange thing is if I put in an alert() call to spit out something at the
beginning of the script that won't even execute even though the script is set
to execute on that page.  Yet if I put the same alert() call at the end of the
script not only will the alert popup, but the script will execute correctly
every single time.  

Any ideas why this is happening?

Here is the script:

// ==UserScript==
// @name           Kingdom of Loathing auto adventure
// @namespace      http://mywebsite.com/myscripts
// @description    Automatically repeats adventuring in Kingdom of Loathing
// @include        http://*.kingdomofloathing.com/fight.php
// @include        http://*.kingdomofloathing.com/adventure.php
// ==/UserScript==

(function() {
   if (typeof(document.attack) != 'undefined')
   else {
      var xpath = '//a/text()[contains(., "Adventure again")]/..';
      var theLink = document.evaluate(xpath, document, null,    
                    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
      linkElement = theLink.snapshotItem(0);
      if (linkElement != null) {
         actualMessage = linkElement.getAttribute("href");
         document.location = actualMessage;

More information about the Greasemonkey mailing list