Overwrite an object function from an external script before it is called
<p>I'm trying to write a Greasemonkey script or Userscript to fix a bug in a website, which deals with an erroneous function of an object. I can fix the problem manually, by adding a breakpoint at the line of code which generates the function prototype, and manually overwriting the function prototype using the js console. However, I don't think there is any way to do this with code. The external script is loaded at the end of the html body, but the problem code is executed within that same script.</p>

<p>Is there any way to somehow inject javascript code into the page, so that when this Ft.prototype.J is created, I can immediately modify it? The problem is that the code is also obfuscated and minified, so I'm not sure what half of it does.</p>

<p>Here is the basic rundown of the code:</p>

<pre><code>//What does this do?????
function A(a, b) {
    function c() {}
    c.prototype = b.prototype;
    a.f = b.prototype;
    a.prototype = new c;
    a.prototype.constructor = a
}

function Ft(a, b) {
    $.call(this, b);
    //some stuff
}
//doing something with jQuery?
A(Ft, $);
Ft.prototype.J = function (a) {
   //modifies the DOM content
};
//Code soon after that calls some object.J
</code></pre>

<p>If I add in the line of code <code>Ft.prototype.J = function() {} //my own function</code>, into my greasemonkey script, it gives me back the error, as expected, <code>Ft not defined</code>. But, if I execute that line at the end of the load, the broken function has already been run, and the DOM is already infected.</p>

<p>Thanks.</p>
