No, there is no direct equivalent in the Add-on SDK. However, the widget
module that you are probably using can display any HTML content and not just an icon. And you can script that HTML content, e.g. to show some text when necessary. I tried it with the following lib/main.js
:
var {data} = require("self");
var icon = require("widget").Widget({
id: "my-widget",
label: "My Widget",
contentURL: data.url("icon.html"),
contentScriptFile: data.url("icon.js"),
onClick: function()
{
icon.port.emit("setBadgeText", "123");
}
});
It uses icon.html
file to display the icon and sends a setBadgeText
message to the attached content script whenever the text on top of the icon needs to change. Here is the data/icon.html
file I tested with:
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
#badgeText
{
position: absolute;
bottom: 0px;
right: 0px;
font: 8px Sans-Serif;
color: #FFFFFF;
background-color: #C00000;
border: 1px solid #800000;
}
</style>
</head>
<body>
<img src="http://www.mozilla.org/favicon.ico">
<div id="badgeText" hidden="true"></div>
</body>
</html>
I didn't invest too much effort to make the text look like Chrome's badge text, you can probably improve the styling. The text is hidden by default (I used the HTML5 hidden
attribute for simplicity). And the data/icon.js
content script isn't too complicated either:
self.port.on("setBadgeText", function(text)
{
var element = document.getElementById("badgeText");
element.textContent = text;
element.hidden = (text == null);
});
It receives the setBadgeText
message and sets the text in the HTML document accordingly. It will also hide the badgeText
element if it receives null
as badge text.