网络编程
位置:首页>> 网络编程>> JavaScript>> Firefox 的 Jetpack 扩展案例分析:Gmail 邮件提醒(3)

Firefox 的 Jetpack 扩展案例分析:Gmail 邮件提醒(3)

作者:blank 来源:怿飞博客 发布时间:2009-10-15 12:41:00 

标签:Gtalk,firefox,Jetpack,插件,提醒

全部代码如下:

var count = 0;

function update(widget) {
    var widget = $(widget),
        notify = function(msg) { // 定义通知的公用方法
            jetpack.notifications.show({
                title: "Gmail",
                body: msg,
                icon: "http://mail.google.com/mail/images/favicon.ico"
            });
        };

    $.get("https://mail.google.com/mail/feed/atom", function(xml) {
        var el = $(xml).find("fullcount"); // 记录未读新邮件数的节点
        if(el){
            var newcount = parseInt(el.get(0).textContent);
            if(newcount > count) { // 如果未读新邮件数大于原来的邮件数,则提示来自哪里
                var sender = $(xml).find("name").get(0).textContent;
                notify("New message from "+sender);
            }
            count = newcount;
            widget.find("#count").text(count); //赋给指定的元素

        } else { //如果未登录,提示登录
            widget.find("#count").text( "Login" );
            notify("Please login to Gmail");
        }
    });
}

jetpack.statusBar.append({
    html: '<img src="http://mail.google.com/mail/images/favicon.ico"/><span id="count"></span>', //Gmail邮件图标和未读新邮件数
    width: 40, //状态栏上的宽度为40,预留3位数的宽度
    onReady: function(widget) {
        $("#count", widget).css({ //给未读新邮件数添加样式
            cursor: "pointer",
            paddingLeft:"4px",
            fontFamily: "Tahoma, Arial, sans-serif",
            verticalAlign: "top",
            fontSize: "10px",
            lineHeight:"18px",
        });

        $(widget).click(function() { //设置点击扩展后的链接窗口
            jetpack.tabs.open("http://mail.google.com");
            jetpack.tabs[ jetpack.tabs.length-1 ].focus();
        });

        update(widget);
        setInterval( function() {update(widget) }, 60*1000 );
    }
});

测试Demo:http://www.planabc.net/lab/jetpack/gmail/

对于 Jetpack 详细的 API,可以阅读 about:jetpack 页面的 API Reference 标签部分。

案例源码来自:https://jetpack.mozillalabs.com/demos/gmail-checker.js

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com