尝试将通知添加到Google Chrome扩展程序

时间:2013-10-22 15:13:33

标签: google-chrome google-chrome-extension

我试图向Google Chrome扩展程序添加通知,这意味着每当我的网站上有新帖子时,通知就会在扩展程序图标上显示一个小红框,其中没有1-10就像Feedly扩展程序一样或谷歌浏览器中的unboxtherapy扩展。

1 个答案:

答案 0 :(得分:0)

显示此类通知应该很简单:

var notification = '#FA2E05'
function showNotification() {
   chrome.browserAction.setBadgeText({text: ' '});
   chrome.browserAction.setBadgeBackgroundColor({color: notification});
}

function clearNotification() {
   chrome.browserAction.setBadgeText({text: ''});
}

这是我在使用徽章时倾向于使用的助手:

function updateBadge(options) {
    var t = options.text,
        c = options.color||options.colour;

    if(t !== undefined){
        chrome.browserAction.setBadgeText({text: (t||'')});
    }
    if(c !== undefined) {
        chrome.browserAction.setBadgeBackgroundColor({color: c});
    }
}

可让您使用
更新徽章的颜色和/或文字 updateBadge({text:'55'}) //保持相同颜色或
updateBadge({colour:'#FA2E05', text:' '}) //显示徽章(相当于showBadge())