灯光与Chrome 51中的深色浏览器动作图标 [英] Light & Dark browserAction icons in Chrome 51

查看:101
本文介绍了灯光与Chrome 51中的深色浏览器动作图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Chrome 51中,隐身窗口现在具有深色的工具栏背景,而以前的版本使用浅色背景.单一的16x16图像在两种情况下都无法提供良好的对比度通常是不可行的:

In Chrome 51, incognito windows now have a dark toolbar background, while previous versions used a light background. It's generally infeasible for a single 16x16 image to provide good contrast in both situations:

通过browserAction图标向用户显示信息时,扩展程序可以通过什么机制提供深色主题和浅色主题图标,并根据当前工具栏颜色在它们之间切换?

When displaying information to the user through a browserAction icon, by what mechanism can an extension provide dark-themed and light-themed icons, and switch between them depending on the current toolbar color?

链接到如图所示扩展名的源代码

推荐答案

还没有这种简单的机制,听起来像

There is no such simple mechanism (yet), and it sounds like an excellent feature request to make at the very least for the manifest.

不过,可以通过检测隐身标签页是否被打开并替换该标签页的浏览器操作图标来对此进行近似估算.

It's possible to approximate this though, by detecting incognito tabs being open and replacing the browser action icon for that tab only.

var incognitoIcons = {
  19: "incognito19.png",
  38: "incognito38.png"
};

chrome.tabs.onCreated.addListener(function(tab) {
  if (tab.incognito) {
    chrome.browserAction.setIcon({
      path: incognitoIcons,
      tabId: tab.id
    });
  }
});

如果您使用的是"split" 隐身行为(非默认值) ),您只需检测一下并更改隐身实例的全局图标即可:

If you're using a "split" incognito behavior (non-default), you can simply detect that and change the global icon for the incognito instance:

// Somewhere in background during initialization
if (chrome.extension.inIncognitoContext) {
  chrome.browserAction.setIcon({path: incognitoIcons});
}

请注意,内容脚本始终可以依赖inIncognitoContext,因此,如果您触发了浏览器操作图标更改,则可以将其传递.

Note that content scripts can always rely on inIncognitoContext, so if you trigger a browser action icon change from them you can pass that along.

很明显,您可以使用imageData而不是path来完成此操作.

Obviously, you can do that with imageData instead of path, as is your case.

您可能需要在使用Chrome时检查它的版本;我没有比提到的这里.

You may want to check the Chrome version while you're at it; I'm not aware of a better way than mentioned here.

这篇关于灯光与Chrome 51中的深色浏览器动作图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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