javascript - Attempt to modify HTMLTableRowElement.prototype -
i have 2 methods, working nicely in couple of pages, when comes greasemonkey script fail reason, throwing 'is not function' error.
same code, while attached page, works perfectly.
htmltablerowelement.prototype.hiderow = function(){this.style.display = 'none'}; htmltablerowelement.prototype.showrow = function(){this.style.display = ''}; error appearing upon calling 1 of these functions. clues?
that code doesn't work greasemonkey script due gm script being in different scope , (nominally) in sandbox. see "why window (and unsafewindow) not same userscript script tag" more information , workarounds (@grant none (maybe), or script injection, or unsafewindow).
however, unless trying alter existing code added by/to page, don't things way.
use jquery's .hide(), .show(), or .toggle().
or create class using gm_addstyle(), eg:
gm_addstyle (".gm_hide {display: none !important;}");
and use dom functions add or remove class desired. eg:
//--- select 2nd row of first table var somerow = document.queryselector ("table tr:nth-of-type(2)"); somerow.classlist.add ("gm_hide"); somerow.classlist.remove ("gm_hide"); somerow.classlist.toggle ("gm_hide");
Comments
Post a Comment