语法
js
browser.theme.update(
  windowId,    // 整型
  theme        // 对象
)
参数
windowId可选- 
integer。窗口的 ID。如果提供了此参数,主题仅应用于该窗口。如果省略此参数,主题将应用于所有窗口。 theme- 
object。一个Theme对象,指定要修改的 UI 元素的值。 
示例
将浏览器主题设置为使用一个太阳图案,并配有一个互补的背景颜色:
js
const suntheme = {
  images: {
    theme_frame: "sun.jpg",
  },
  colors: {
    frame: "#CF723F",
    tab_background_text: "#111",
  },
};
browser.theme.update(suntheme);
仅为聚焦的窗口设置主题:
js
const day = {
  images: {
    theme_frame: "sun.jpg",
  },
  colors: {
    frame: "#CF723F",
    tab_background_text: "#111",
  },
};
browser.menus.create({
  id: "set-theme",
  title: "设置主题",
  contexts: ["all"],
});
async function updateThemeForCurrentWindow() {
  let currentWindow = await browser.windows.getLastFocused();
  browser.theme.update(currentWindow.id, day);
}
browser.menus.onClicked.addListener(updateThemeForCurrentWindow);
示例扩展
浏览器兼容性
Loading…