-
Notifications
You must be signed in to change notification settings - Fork 0
/
googleChrome.js
executable file
·105 lines (81 loc) · 3 KB
/
googleChrome.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* See license.txt for terms of usage */
Firebug.extend(function(FBL) { with (FBL) {
// ************************************************************************************************
if (!Env.isChromeExtension) return;
// ************************************************************************************************
// local variables
var channel;
var channelEvent;
// ************************************************************************************************
// GoogleChrome Module
Firebug.GoogleChrome = extend(Firebug.Module,
{
initialize: function()
{
var doc = FBL.Env.browser.document;
if (!doc.getElementById("FirebugChannel"))
{
channel = doc.createElement("div");
channel.id = "FirebugChannel";
channel.firebugIgnore = true;
channel.style.display = "none";
doc.documentElement.insertBefore(channel, doc.documentElement.firstChild);
channelEvent = new Event("FirebugChannelEvent"); //replaced old fashioned way of creating events
channel.addEventListener("FirebugChannelEvent", onFirebugChannelEvent);
}
},
dispatch: function(message)
{
channel.innerText = message;
channel.dispatchEvent(channelEvent);
}
});
// ************************************************************************************************
// internals
var onFirebugChannelEvent = function()
{
var name = channel.innerText;
if (name.indexOf("FB_contextMenuClick") == 0)
{
var doc = FBL.Env.browser.document;
var contextMenuElementXPath = name.split(",")[1];
var contextMenuElement = getElementsByXPath(doc, contextMenuElementXPath)[0];
// If not open, open it first
Firebug.chrome.toggle(true);
setTimeout(function(){
// Select the HTML panel
Firebug.chrome.selectPanel("HTML");
// Select the clicked element in the HTML tree
Firebug.HTML.select(contextMenuElement);
},50);
}
else if (name == "FB_toggle")
{
Firebug.chrome.toggle();
}
else if (name == "FB_openInNewWindow")
{
setTimeout(function(){
Firebug.chrome.toggle(true, true);
},0);
}
};
var getElementsByXPath = function(doc, xpath)
{
var nodes = [];
try {
var result = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null);
for (var item = result.iterateNext(); item; item = result.iterateNext())
nodes.push(item);
}
catch (exc)
{
// Invalid xpath expressions make their way here sometimes. If that happens,
// we still want to return an empty set without an exception.
}
return nodes;
};
// ************************************************************************************************
Firebug.registerModule(Firebug.GoogleChrome);
// ************************************************************************************************
}});