首先,是学校的教务网页使用了innerText属性,所以我想自己写一个UserScript脚本来实现innerText属性。
其实,只要执行如下脚本后,就有了innerText属性了:
if (!!document.getBoxObjectFor || window.mozInnerScreenX != null) {
HTMLElement.prototype.__defineGetter__("innerText", function() {
return this.textContent;
});
HTMLElement.prototype.__defineSetter__("innerText", function (value) {
this.textContent = value;
});
}
但是,我自己写了脚本之后,仍然无法设置innerText属性,提示TypeError: HTMLElement.prototype.__defineGetter__ is not a function
请问如何解决?
另外,innerText属性在onload代码中就使用了。
我觉得Scriptish的权限控制也是需要考虑的。
附上我写的测试脚本:
// ==UserScript==
// @name Test
// @namespace www.example.com
// @include *
// @version 1
// ==/UserScript==
if (!!document.getBoxObjectFor || window.mozInnerScreenX != null) {
HTMLElement.prototype.__defineGetter__("innerText", function() {
return this.textContent;
});
HTMLElement.prototype.__defineSetter__("innerText", function (value) {
this.textContent = value;
});
}
引用自 http://forum.moztw.org/viewtopic.php?t=33679
所以,我最后的代码是这样的:
不是权限的原因,而是它本身就没有那个
__defineSetter__
属性。Firebug 控制台测试可行。文档
我不是很确定原因……
你可以试试这样执行:
这是我尝试出的在所有可以用userscript的浏览器中,执行js权限最高的方法……如果这个不行的话,我觉不知到了。。