語法
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);
擴充套件程式示例
瀏覽器相容性
載入中…