我在Firefox中使用这个脚本,计算Tweetdeck中的未读推文并着色新的推文。Userscript代码适用于Firefox,但不适用于Chrome? (unsafeWindow)
它适用于Firefox(Greasemonkey),但在Chrome中我没有收到任何东西。这里是代码:
// ==UserScript==
// @name TweetDeck Unread Notifications
// @include https://tweetdeck.twitter.com
// @include https://tweetdeck.twitter.com/*
// @grant none
// ==/UserScript==
var head, style;
head = document.getElementsByTagName('head')[0];
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = ".tdUnreadUnread { background-color: #444444; }";
head.appendChild(style);
function animate_bg(ele, from, to) {
ele.css("background-color", "rgba(68, 68, 68, " + (from += from > to ? -1 : 1)/10 + ")");
if (from != to) setTimeout(function() {
animate_bg(ele, from, to)
}, 20);
}
var counter = 0;
var loadingTime = true;
unsafeWindow.tdUnreadRefresh = function() {
var detail = $(".js-detail-content");
$("article").each(function (i) {
if (detail.length == 0) {
if (!$(this).hasClass("tdUnreadUnread")) {
$(this).addClass("tdUnreadUnread");
if (!loadingTime) {
counter++;
$(this).mouseenter(function() {
counter--;
$(this).off("mouseenter");
animate_bg($(this), 10, 0);
});
} else animate_bg($(this), 10, 0);
}
}
});
if (counter > 0) {
document.title = "(" + counter + ") TweetDeck";
} else {
document.title = "TweetDeck"
}
}
unsafeWindow.tdUnreadLoadingOver = function() {
loadingTime = false;
}
setInterval("tdUnreadRefresh()", 1000);
setTimeout("tdUnreadLoadingOver()", 30000);
任何帮助,这是非常感谢。 谢谢 Bob
这已在其他问题中涵盖。但是在这里你的脚本的底线,因为你正在使用'@grant none':(1)用'window.'替换所有'unsafeWindow.'。 (2)确保您的Chrome用户已安装并使用Tampermonkey。 ...如果您尝试使用纯Chrome,那么您的脚本需要注入 - 无论如何,这是一个坏主意。 –
感谢Brock的提示,它在Chrome中完美运行。 – BobC
不客气。它也适用于Firefox,对吧? ;) –