mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-17 06:48:37 +02:00
The manifest 'all_frames' property defaults to false, so the contentscript should not need to perform the window.parent check.
35 lines
940 B
JavaScript
35 lines
940 B
JavaScript
var toolbarUI;
|
|
|
|
// Create the toolbar ui iframe and inject it in the current page
|
|
function initToolbar() {
|
|
var iframe = document.createElement("iframe");
|
|
iframe.setAttribute("src", chrome.runtime.getURL("toolbar/ui.html"));
|
|
iframe.setAttribute("style", "position: fixed; top: 0; left: 0; z-index: 10000; width: 100%; height: 36px;");
|
|
document.body.appendChild(iframe);
|
|
|
|
return toolbarUI = {
|
|
iframe: iframe, visible: true
|
|
};
|
|
}
|
|
|
|
function toggleToolbar(toolbarUI) {
|
|
if (toolbarUI.visible) {
|
|
toolbarUI.visible = false;
|
|
toolbarUI.iframe.style["display"] = "none";
|
|
} else {
|
|
toolbarUI.visible = true;
|
|
toolbarUI.iframe.style["display"] = "block";
|
|
}
|
|
}
|
|
|
|
// Handle messages from the add-on background page
|
|
chrome.runtime.onMessage.addListener(function(msg) {
|
|
if (msg == "toggle-in-page-toolbar") {
|
|
if (toolbarUI) {
|
|
toggleToolbar(toolbarUI);
|
|
} else {
|
|
toolbarUI = initToolbar();
|
|
}
|
|
}
|
|
});
|