I visit a website with a javascript file in the head of the HTML
It's not clear that update
is a global function. If it isn't then that approach won't work.
But you can override the keypress handler with:
unsafeWindow.document.onkeypress = function(){};
For a general, high-powered way to selectively block, or replace, any JS (on Firefox), use @run-at document-start and the checkForBadJavascripts function, like so:
// ==UserScript==
// @name _Replace select javascript on a page
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @require https://gist.github.com/raw/2620135/checkForBadJavascripts.js
// @run-at document-start
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
checkForBadJavascripts ( [
[ false,
/document\.onkeypress\s*=\s*update/,
function () {
addJS_Node (myKeypressFunction.toString() );
addJS_Node ('document.onkeypress = myKeypressFunction;');
}
]
] );
function myKeypressFunction (evt) {
/* DO WHATEVER HERE BUT USE NO GREASEMONKEY FUNCTIONS INSIDE
THIS FUNCTION.
*/
console.log ("Keypress function fired.");
}
See this answer, for more information on checkForBadJavascripts.