I posted this on http://userscripts.org/topics/46757 and no one has
found a fix for this, so I'll try asking here, if it's ok.

Basically, I am creating a script that wants to record what link/form
the user is submitting so I can record action to reaction. This is for
a web game called "Billy versus Snakeman", so I wanted to create a
list of reactions and counts to what each link does.

To do this I override the 'HTMLFormElement.prototype.submit' and put
in my function, and during the new submit function I look at the form
name and basically try to save the data using GM_setValue. I am using
this versus 'onclick' watches because other users may be using other
GM scripts that submits the links/forms using hotkeys.

The problem is clear when I run a test GM_getValue directly after the
set, it comes up as undefined. I know 100% that what I'm putting in
isn't undefined, as I have put alerts before the setValue and it comes
up correctly. I have also checked 'about:config' to see if the value
was stored there, but it never was.

Here is basically my code snippet:

///////////// START CODE
window.addEventListener('submit', newFormSubmit, true);
//could unsafeWindow be the problem???
//window.HTMLFormElement comes up as undefined
unsafeWindow.HTMLFormElement.prototype.submit = newFormSubmit;

function newFormSubmit(e) {
//when this fires, 'e' comes up as undefined
//and any attempt to use 'preventDefault' function come up as
undefined.
var target = (e ? event.target : this);
var form;

if (target.tagName.toLowerCase() == 'input') {
form = target.form;
} else {
form = target;
}

if (match = form.name.match("^search(\\d+)$")) {
var i = (parseInt(match[1]) | 1) - 1;

//r00t search clicked
alert(fieldActions[i]); //displays 'Search the landscape'
GM_setValue("r00t_lastaction", fieldActions[i]);
alert(GM_getValue("r00t_lastaction", "")); //displays 'undefined',
which isn't right
//form.submit(); //commented out for testing purposes
} else
form.submit();

//submitting form to target.action
//alert(target.action);
}

///////////// END CODE

This is the full script if its needed:
http://rveach.romhack.org/BvS/bvs_r00t_logger_10.user.js

And this is an example test page (its an exact copy of the page I get
from the game):
http://rveach.romhack.org/BvS/test.html

I'm using GM 0.8.20100211.5 and Firefox 3.6, if it matters.

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en.

Reply via email to