Userscript代码在Firefox中运行,但不在Chrome中运行(unsafeWindow) [英] Userscript code works in Firefox but not in Chrome? (unsafeWindow)

查看:677
本文介绍了Userscript代码在Firefox中运行,但不在Chrome中运行(unsafeWindow)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firefox中使用这个脚本,计算Tweetdeck中未读的推文,并为新的推文着色。

Firefox(Greasemonkey)可以正常工作,但在Chrome中,我没有收到任何东西。这里是代码:

  // == UserScript == 
// @name TweetDeck未读通知
// @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);
$ b函数animate_bg(ele,from,to){
ele.css(background-color,rgba(68,68,68,+(from + = from>到-1:1)/ 10 +));如果(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);

任何帮助都是非常感谢的。
Thanks
Bob

解决方案

IIRC对象unsafewindow特定于Mozilla Firefox,不支持Google Chrome。

您可能想要使用exportFunction功能导出您的函数,而不是使用unsafewindow: https://developer.mozilla.org/zh-CN/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction


I am using this userscript in Firefox that counts unread tweets in Tweetdeck and colors the new tweets.

It works fine with Firefox (Greasemonkey), but in Chrome I'm not getting anything. Here is the code:

// ==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);

Any help with this is much appreciated. Thanks Bob

解决方案

IIRC the object unsafewindow is specific to Mozilla Firefox and isn't supported with Google Chrome.
Instead of using unsafewindow, you might want to export your functions using the exportFunction feature: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction

这篇关于Userscript代码在Firefox中运行,但不在Chrome中运行(unsafeWindow)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆