Remove MooTools events using a Greasemonkey script? -


i'm trying modify page uses mootools add event-listeners fields, so:

$('inputpassword').addevents({     keypress: function(){         new workspacemodalbox({'href':'someurl.phtml', 'width':500, 'height':140, 'title':'foo'});     } }); 


need remove behavior using greasemonkey/tampermonkey. tried:

// ==userscript== // @require  http://userscripts.org/scripts/source/44063.user.js // ==/userscript== window.addeventlistener("load", function(e) {     $('inputpassword').removeevents('keypress'); }, false); 

where removeevents function mootools, opposite 1 addevents.

but script doesn't work. (editor's note: there no reported errors)

why? because code executed before code real page?

the event installed in page scope script running in script scope. also, depending on browser , on @grant settings, there may sandbox involved.

so, remove event, must use script injection (moo tools doesn't seem play nice unsafewindow.)

this script works on both greasemonkey , tampermonkey:

// ==userscript== // @name     _remove moo event listener // @include  http://your_server.com/your_path/* // @grant    gm_addstyle // ==/userscript== /*- @grant directive needed work around design change     introduced in gm 1.0.   restores sandbox. */  window.addeventlistener ("load", function (e) {     addjs_node ("$('inputpassword').removeevents('keypress');"); }, false);   //-- addjs_node standard(ish) function function addjs_node (text, s_url, functorun, runonload) {     var d                                   = document;     var scriptnode                          = d.createelement ('script');     if (runonload) {         scriptnode.addeventlistener ("load", runonload, false);     }     scriptnode.type                         = "text/javascript";     if (text)       scriptnode.textcontent  = text;     if (s_url)      scriptnode.src          = s_url;     if (functorun)  scriptnode.textcontent  = '(' + functorun.tostring() + ')()';      var targ = d.getelementsbytagname ('head')[0] || d.body || d.documentelement;     targ.appendchild (scriptnode); } 


note there no need @require-in moo tool this, since page's instance of moo tools must 1 remove event(s).


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -