A simple yet daunting script

24 views
Skip to first unread message

NinjaTaiken

unread,
Jun 10, 2007, 8:19:00 AM6/10/07
to greasemonkey-users
Im new to greasemonkey, and I've been trying to do something really
simple with it without any luck.
I want to get past a textarea letter limit. This certain limit works
like this, (I presume):
Theres a function called textCounter which takes 3 parameters, only
the third matters.
It looks like this
textCounter(this,this.form.counter,300);
and its activated onkeypress.
The textarea has no ID, so what I tried doing was use a script taken
from the greasemonkey guide and modify it slightly to make it simple
and to make it work, regardless of efficiency:

var alltext, thistext;
alltext = document.evaluate(
'//*[@onkeypress]',
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
for (var i = 0; i < alltext.snapshotLength; i++) {
thistext = alltext.snapshotItem(i);
thistext.onkeypress = "";
}

This obviously doesnt work. I havent a clue how to change the
onkeypress event attribute of the textarea automatically whenever the
page loads.
Can anyone help me please?
This is the entire textarea code

<TEXTAREA NAME="body" ROWS="18"
COLS="70" WRAP="virtual"
onkeypress="textCounter(this,this.form.counter,300);"></TEXTAREA>

esquifit

unread,
Jun 10, 2007, 10:40:05 AM6/10/07
to greasemon...@googlegroups.com
Since you are new to GM I strongly recommend reading [1] before
spending much time struggling with situations like this ;-) Briefly,
not every piece of code that runs in a 'normal' web page can do it
unmodified in GM, there are a couple of situations where a definite
syntax must be obeyed. In the present case, I'd say you'd just need
to change

thistext.onkeypress = "";

by something like

thistext.setAttribute("onkeypress", "");

the reason being pitfall #2 "Event Handlers". After having read what
is said there, note that Mark Pilgrim's article gives a clue as to how
to *add* event handlers from inside GM; however, in order to
*override* them, you may have to do something like the above.

[1] http://www.oreillynet.com/lpt/a/6257

2007/6/10, NinjaTaiken <Ninja...@gmail.com>:

Matt Sargent

unread,
Jun 10, 2007, 1:56:44 PM6/10/07
to NinjaTaiken, greasemon...@googlegroups.com
You should check first that bypassing this function will accomplish what you want. Generally, when restrictions like this are put in, they are done so for a good reason. You can check this by simply pasting in (via the context menu) a text string longer than 300 characters. This will not trigger the onkeypress event. You may find that it still won't let you continue, or that only a portion of your text is actually saved. If that's the case, bypassing this function is a futile effort.

Anthony Lieuallen

unread,
Jun 10, 2007, 4:10:49 PM6/10/07
to greasemon...@googlegroups.com
On 6/10/2007 8:19 AM, NinjaTaiken wrote:
> Im new to greasemonkey, and I've been trying to do something really
> simple ...

Unless it is completely impossible (internal company intranet, password
protected page, etc) it is *always* a good idea to give a link to the
exact page in question. Without it, anyone helping you has to guess at
a lot of things they might otherwise know.

That said, guess what? I have to guess at some details below, but the
simplest way to this would probably be using the location hack [1] to
override the textCounter function, make it always return true, false,
whatever the "string is ok" value is.

Basically, something simple like "textCounter=function(){return true}".

[1] http://wiki.greasespot.net/Location_hack

Reply all
Reply to author
Forward
0 new messages