因此,我有一个信息按钮,每当用户更新扩展程序时,右上角都会显示一个小红点,表示有警报(新更新)。
我现在的操作方式是在每次查看更新时在localStorage中设置一行-如果未找到该行,则该按钮将带有红点。
问题是,此解决方案要求我在每次更新后每次启动更新时都更改几行,如下所示:
//1.1.2 was the last version
localStorage.removeItem("update-1.1.2");
...
if( localStorage.getItem("update-1.1.3") === null ) {
//show button image with red dot
}
else {
//show button image without red dot
}
...
$('#info').click(function()
{
localStorage.setItem("update-1.1.3", "YES");
//swap the button image w/ red dot, with the same image w/o the red dot
});
如您所见,每次更新时,都必须在3个位置更改“ update-xxx”字符串。
所以我的两个问题是:-有更好的方法吗?也许是一种确定用户是否已更新扩展名的方法?-交换图片是解决此问题的最佳方法吗?还是我应该有一个红点图像并使其消失。在我看来,性能差异似乎很小-它取决于是否交换整个图像,或者使另一个图像隐藏/不隐藏更有效。
chrome.runtime
API可以为您提供两点帮助:
您可以检测到扩展在更新后首次运行:
chrome.runtime.onInstalled.addListener( function(details) {
switch(details.reason) {
case "install":
// First installation
break;
case "update":
// First run after an update
break;
}
});
您可以从清单中提取版本号,而不必对版本号进行硬编码:
chrome.runtime.getManifest().version
就是说,我认为当您有话要对用户说时,更新代码中的一些常量是完全合理的。
至于红点,您可以在调用时通过使用<canvas>
andimageData
属性来尝试使用动态构建的图标setIcon
。或者,为简单起见,请使用带有的徽章setBadgeText
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句