Files
webextensions-examples/themed-icons/extpage.js
rebloor f4d0193956 Bug-2001318 example showing SVG icon reacting to theme (#620)
* Bug-2001318 example showing SVG icon reacting to theme

* Updates for feedback
2026-03-12 04:42:31 +13:00

30 lines
858 B
JavaScript

let activeThemeEl = document.querySelector("#active-theme");
let readmeEl = document.querySelector("#read-me");
function updateThemeInfo(info) {
activeThemeEl.textContent = `${info.name} (${info.id})`;
}
// Include the README.md file content into the test page.
fetch("/README.md").then(r => r.text()).then(text => {
readmeEl.textContent = text;
});
// Set active theme info element content on page load.
browser.management.getAll().then(addons => {
updateThemeInfo(addons.find(addon => addon.type == "theme" && addon.enabled));
});
// Show pageAction icon on the extension page.
browser.tabs.getCurrent().then(tabInfo => {
browser.pageAction.show(tabInfo.id);
});
// Update active theme info when a theme is enabled.
browser.management.onEnabled.addListener(info => {
if (info.type !== "theme") {
return;
}
updateThemeInfo(info);
});