It is beyond anything you have ever experienced or imagined
Using GreasyThug to Answer a Greasemonkey Question
On StackOverflow a user asked: How can I create an object of a class which defined in the remote page?
The page includes code like this (which I entered into Firebug):
function foo(){ this.bar = 0; }
Then I verified that it could be read from Greasemonkey with the GreasyThug console by the following expression:
_foo = unsafeWindow.foo;
x = new _foo();
This caused a “Not enough arguments” error, whatever the hell that is. Not quite the poster’s actual error. What if we added an argument? “Illegal Value” Bingo! Replicated the issue. Now to solve it.
Let’s try and migrate the function over into the Greasemonkey script zone.
_foo = eval('(' + unsafeWindow.foo.toSource() + ')')
=> function foo(){ this.bar = 0; }
That’s the ticket! Now to instantiate and verify:

Ship it! Holla!
| Print article | This entry was posted by Daniel X Moore on March 4, 2009 at 8:47 pm, and is filed under Internet Adventures, Programming. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

