-
Notifications
You must be signed in to change notification settings - Fork 15
/
script.js
executable file
·41 lines (40 loc) · 1.08 KB
/
script.js
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
39
40
41
/*Handle requests from background.html*/
function handleRequest(
//The object data with the request params
request,
//These last two ones isn't important for this example, if you want know more about it visit: http://code.google.com/chrome/extensions/messaging.html
sender, sendResponse
) {
if (request.callFunction == "toggleSidebar")
toggleSidebar();
}
chrome.extension.onRequest.addListener(handleRequest);
/*Small function wich create a sidebar(just to illustrate my point)*/
var sidebarOpen = false;
function toggleSidebar() {
if(sidebarOpen) {
var el = document.getElementById('mySidebar');
el.parentNode.removeChild(el);
sidebarOpen = false;
}
else {
var sidebar = document.createElement('div');
sidebar.id = "mySidebar";
sidebar.innerHTML = "\
<h1>Hello</h1>\
World!\
";
sidebar.style.cssText = "\
position:fixed;\
top:0px;\
left:0px;\
width:30%;\
height:100%;\
background:white;\
box-shadow:inset 0 0 1em black;\
z-index:999999;\
";
document.body.appendChild(sidebar);
sidebarOpen = true;
}
}