Files
webextensions-examples/inpage-toolbar-ui/contentscript.js
luke crouch 0b34b991bf remove window.parent check from contentscript
The manifest 'all_frames' property defaults to false, so the contentscript should not need to perform the window.parent check.
2016-07-21 11:26:31 -05:00

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();
}
}
});