[英]Attempt to modify HTMLTableRowElement.prototype
我有两种方法,可以在几页中很好地工作,但是当谈到Greasemonkey脚本时,它们由于某种原因而失败,并抛出“不是函数”错误。
正常情况下,将相同的代码正常附加到页面上即可。
HTMLTableRowElement.prototype.hideRow = function(){this.style.display = 'none'};
HTMLTableRowElement.prototype.showRow = function(){this.style.display = ''};
调用这些功能之一时出现错误。 有什么线索吗?
该代码在Greasemonkey脚本中不起作用,因为GM脚本位于不同的范围内(并且名义上位于沙盒中)。 有关更多信息和解决方法,请参阅“为什么用户脚本中的窗口(和unsafeWindow)与脚本标记中的窗口不相同”(有关详细信息,请@grant none
(也许),或者脚本注入,或unsafeWindow
)。
但是,除非您试图更改由页面添加到页面的现有代码,否则请不要那样做。
使用jQuery的.hide()
.show()
或.toggle()
或使用GM_addStyle()
创建一个类:
GM_addStyle (".GM_hide {display: none !important;}");
并使用DOM函数根据需要添加或删除类。 例如:
//--- Select the 2nd row of the 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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.