Files
webextensions-examples/theme-integrated-sidebar/sidebar.js
rebloor 0d46482e7d Remove retired theme aliases (#430)
* Remove required theme aliases

Replaced uses of headerURL, accentcolor, and textcolor with theme_frame, frame, and tab_background_text. Tested and confirmed all extensions working as expected.

* Fixed another reference to headerURL

Co-authored-by: Richard Bloor <rbloor@atlassian.com>
2020-03-23 17:00:00 -07:00

43 lines
1.3 KiB
JavaScript

function setSidebarStyle(theme) {
const myElement = document.getElementById("myElement");
if (theme.colors && theme.colors.frame) {
document.body.style.backgroundColor =
theme.colors.frame;
} else {
document.body.style.backgroundColor = "white";
}
if (theme.colors && theme.colors.toolbar) {
myElement.style.backgroundColor = theme.colors.toolbar;
} else {
myElement.style.backgroundColor = "#ebebeb";
}
if (theme.colors && theme.colors.toolbar_text) {
myElement.style.color = theme.colors.toolbar_text;
} else {
myElement.style.color = "black";
}
}
// Set the element style when the extension page loads
async function setInitialStyle() {
const theme = await browser.theme.getCurrent();
setSidebarStyle(theme);
}
setInitialStyle();
// Watch for theme updates
browser.theme.onUpdated.addListener(async ({ theme, windowId }) => {
const sidebarWindow = await browser.windows.getCurrent();
/*
Only update theme if it applies to the window the sidebar is in.
If a windowId is passed during an update, it means that the theme is applied to that specific window.
Otherwise, the theme is applied globally to all windows.
*/
if (!windowId || windowId == sidebarWindow.id) {
setSidebarStyle(theme);
}
});