-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentScript.js
More file actions
39 lines (35 loc) · 1.11 KB
/
contentScript.js
File metadata and controls
39 lines (35 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var toolbarUI;
function initOverlay() {
var iframe = document.createElement('iframe');
iframe.setAttribute('id', 'toolbar');
iframe.setAttribute('src', chrome.runtime.getURL('toolbar/ui.html'));
iframe.setAttribute('style', 'position: absolute; top: 0; left: 0; z-index: 1000000; width: 100%; height: 100%;');
document.body.appendChild(iframe);
chrome.runtime.sendMessage({ name: 'overlay-initialized' });
return toolbarUI = {
iframe: iframe, visible: true
};
}
function toggleOverlay(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 background page (only in top level iframes)
console.log('registering message listener');
chrome.runtime.onMessage.addListener((msg) => {
if (window.parent == window) {
console.log('message received');
if (msg.name == 'toggle-in-page-toolbar') {
if (toolbarUI) {
toggleOverlay(toolbarUI);
} else {
toolbarUI = initOverlay();
}
}
}
});