Search code examples
javascriptjquerygreasemonkey

GreaseMonkey, change some js functions


I use Greasemonkey for some changes in pages.

There's a web page that has SomeFunction() placed in a javascript file. I ignored the javascript file with some add-ons. Now SomeFunction() should be overwritten.

But when I define SomeFunction() in GM script, I get "SomeFunction() is not defined" which has not been resolved by run-at document-start in GM script neither by adding SomeFunction() in a file and writing that on the page with document.getElementsByTagName('head')[0].appendChild(js);.

How can I define a custom Somefunction()?

Thank you


Solution

  • Consider reading exportFunction and all the others stuff about unsafeWindow.

    Basically:

    exportFunction(SomeFunction, unsafeWindow, {defineAs: "SomeFunction"});