theme.update()

根據 Theme 物件的內容更新瀏覽器主題。

要使用此方法,擴充套件必須在其 manifest.json 檔案中請求 "theme" 許可權

語法

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);

擴充套件程式示例

瀏覽器相容性