語法
js
let getting = browser.theme.getCurrent(
windowId // integer
)
引數
windowId可選-
integer。視窗的 ID。如果提供了此 ID,則解析的主題是應用於該視窗的主題。如果省略此 ID,則解析的主題是應用於最近聚焦的視窗的主題。
返回值
一個 Promise。該 Promise 會以一個 theme.Theme 物件fulfilled,該物件表示應用於給定視窗的主題。如果沒有擴充套件程式提供的主題已應用於給定視窗,則以一個空物件 fulfilled。
示例
獲取當前主題的 frame 和 toolbar 顏色屬性。
js
function getStyle(themeInfo) {
if (themeInfo.colors) {
console.log(`accent color: ${themeInfo.colors.frame}`);
console.log(`toolbar: ${themeInfo.colors.toolbar}`);
}
}
async function getCurrentThemeInfo() {
const themeInfo = await browser.theme.getCurrent();
getStyle(themeInfo);
}
getCurrentThemeInfo();
擴充套件程式示例
瀏覽器相容性
載入中…