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