|
|
OK, so I confess to being a Greasemonkey newbie. This means it is entirely possible that the answer to this question is blindingly obvious - I apologize if that is the case. I want to modify a small portion of the source code of a Javascript function on a web page. However, the function contains dynamically-generated code, so I cannot simply replace it with my own function. Also, this may not matter at all, but the function is called periodically with setInterval. Here's an example: function foobar() {
Say I want to replace the formula with: a = (b + c + d)/10; Is this possible? Thanks! |
|
|
I don't think it's possible if you got dynamically generated content.
|
|
|
Something like that should work:
You can also use uneval() or toSource() instead of toString(). |
|
|
Thanks a bunch Mikado, that works - sort of. The function replacement works, but then I ran into another problem. The Javascript block where the function is defined also contains other code that define a number of variables outside the function that are used within it. For example:
So once I replace foobar with the modified version, I get a bunch of "a is not defined" errors in the console, presumably since the function is no longer within its original scope. Of course the value of a is dynamically generated by the web page. I suppose I could pull that code out of the DOM and push those variables into my modified function, but is there any other way to do this? |
|
|
Try doing the replacement within page scope. E.g. using location hack:
|
|
|
Could you maybe give us the page you are doing this on? We could probably help more. |
|
|
sweet thanks guys. this helps me too. can some one spicify what the problem with using unsafewindow is? |
|
|
can some one spicify what the problem with using unsafewindow is?http://wiki.greasespot.net/UnsafeWindow |