forked from samdark/opera-xdebug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
55 lines (51 loc) · 1.45 KB
/
background.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
window.addEventListener("load", function() {
var UIItemProperties = {
disabled: true,
title: "Start debug session",
icon: "xdebug-button.png",
badge: {
display: "none", // none
textContent: "on",
color: "#fff",
backgroundColor: "#6f6"
},
onclick: function(){
// Send a message to the currently-selected tab.
var tab = opera.extension.tabs.getFocused();
if(tab){ // Null if the focused tab is not accessible by this extension
tab.postMessage({
idekey: window.widget.preferences['idekey']
});
//xDebugButton.icon = xDebugButtonProperties.iconEnabled;
}
}
};
// Next, we create the button and apply the above properties.
var button = opera.contexts.toolbar.createItem(UIItemProperties);
// Finally, we add the button to the toolbar.
opera.contexts.toolbar.addItem(button);
function enableButton() {
var tab = opera.extension.tabs.getFocused();
if(tab){
button.disabled = false;
} else{
button.disabled = true;
}
}
// Enable the button when a tab is ready.
opera.extension.onconnect = enableButton;
opera.extension.tabs.onfocus = enableButton;
opera.extension.tabs.onblur = enableButton;
opera.extension.onmessage = function(event){
switch(event.data){
case 'xdebug.enabled':
button.title = "Stop Xdebug session";
button.badge.display = "block";
break;
case 'xdebug.disabled':
button.title = "Start Xdebug session";
button.badge.display = "none";
break;
}
}
}, false);