语法
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();
扩展程序示例
浏览器兼容性
加载中…