我对这一切都很陌生,但这个脚本曾经在firefox上运行,最近停止了。它将Gmail的收件箱中的未读计数放在窗口/标签标题的开头。
unsafeWindow.document.watch('title',
function(prop, oldval, newval) {
if (matches = newval.match(/Inbox \((\d+)\)/)) {
names = newval.match(/\w+/)
newval = '(' + matches[1] + ') unread - ' + names[0] + ' Inbox';
}
return (newval);
});
运行时,错误控制台显示“unsafeWindow.document.watch不是函数”。我尝试在谷歌和这里搜索,但无法弄清楚这一点。任何帮助将不胜感激!
答案 0 :(得分:1)
看起来Greasemonkey的沙盒(XPCNativeWrapper)发生了变化。这似乎是一个可能的错误,但我目前看不到任何未解决的问题。
另外,watch()
是非标准的(可能会消失),而the documentation则是not meant to be used except for temporary debugging。
与此同时,您可以通过将代码注入页面范围来再次使用该代码,如下所示:
function AddTitleWatch () {
document.watch ('title', function (prop, oldval, newval) {
var matches, names;
if (matches = newval.match (/Inbox \((\d+)\)/ ) ) {
names = newval.match (/\w+/)
newval = '(' + matches[1] + ') unread - ' + names[0] + ' Inbox';
}
return (newval);
} );
}
function addJS_Node (text, s_URL, funcToRun) {
var D = document;
var scriptNode = D.createElement ('script');
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);
}
addJS_Node (null, null, AddTitleWatch);
但更智能,更长期,更强大的便携式解决方案是重构代码以使用间隔计时器。 ...
setInterval (RefactorTitle, 200);
function RefactorTitle () {
var oldTitle = RefactorTitle.oldTitle || "";
var docTitle = document.title;
if (docTitle != oldTitle ) {
var matches, names;
if (matches = docTitle.match (/Inbox \((\d+)\)/ ) ) {
names = docTitle.match (/\w+/);
docTitle = '(' + matches[1] + ') unread - ' + names[0] + ' Inbox';
}
document.title = docTitle;
RefactorTitle.oldTitle = docTitle;
}
}