[Greasemonkey] accessing js functions outside of GM scope
Chris McKeever
techjedi at gmail.com
Sat Apr 8 02:17:41 EDT 2006
On 4/6/06, Lenny Domnitser <ldrhcp at gmail.com> wrote:
There is a function called GM_executeContentScript in Greasemonkey's
> CVS, that does this. You can use it for now by just copying it into
> your script from miscapis.js [1]. Then call it like so:
>
This was actually what I was looking for - but of course, now I have
run into a whole new problem. I am trying to get tricky and rework
some of the .js code from the Google Local.
I have it all working very nice except this one little part. I
thought I could use the magic of overwriting their functions, but for
some reason if I do this, it returns errors that objects or functions
aren;t available - and this is if I copy the code directly and
overwrite.
Example:
Original code (obtained from GM_log(unsafeWindow.GEvent.addListener) ):
window.GEvent.addListener =
function Tb(a, b, c) {
var d = new Fa(a, b, c, 0);
mb.push(d);
return d;
}
if I:
window.location.href = "javascript:(function(){"
+ " window.GEvent.addListener = function(a, b, c){"
+ " function Tb(a, b, c) {"
+ " var d = new Fa(a, b, c, 0);"
+ " mb.push(d);"
+ "return d;"
+ " }; " // ends overwrite function
+ " }) ()";
I get an error the Fa is not defined. The function looks identical
in GM_log(unsafeWindow.GEvent.addListener)
However, if I:
window.location.href = "javascript:(function(){"
+ " window.GEvent.VaddListener = window.GEvent.addListener; "
+ " window.GEvent.addListener = function(a, b, c){"
+ " window.GEvent.VaddListener(a, b, c); alert(b); "
+ " }; " // ends overwrite function
+ " }) ()";
addListener calls Vaddlistener and appends the alert to the end.
Granted, I want to do more with the overwriting, such as add an entire
line of code to the Td function. But this is just an example.
Does this have something to do with the scope? or is this something
to do with the obfuscated compression? More importantly, any ideas?
Thanks
Chris
--
----------------------------------
please respond to the list .. if you need to contact me direct
cgmckeever is the account
prupref.com is the domain
<A href="http://www.prupref.com">Simply Chicago Real Estate</A>
More information about the Greasemonkey
mailing list