| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
| 3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
| 4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 Cu.import("resource://gre/modules/Services.jsm"); | 7 Cu.import("resource:///modules/devtools/gDevTools.jsm"); |
|
Wladimir Palant
2014/04/11 11:06:08
While you are at it, please don't use a blind impo
saroyanm
2014/04/11 16:09:10
Got it.
| |
| 8 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | |
| 9 | 8 |
| 10 let InspectorObserver = | 9 let InspectorObserver = |
| 11 { | 10 { |
| 12 init: function() | 11 init: function() |
| 13 { | 12 { |
| 14 Services.obs.addObserver(this, "inspector-opened", true); | 13 gDevTools.on("inspector-ready", this.inspectorReady); |
| 15 onShutdown.add(function() | 14 onShutdown.add(function() |
| 16 { | 15 { |
| 17 Services.obs.removeObserver(this, "inspector-opened"); | 16 gDevTools.off("inspector-ready", this.inspectorReady); |
| 18 | |
| 19 let e = Services.ww.getWindowEnumerator(); | |
| 20 while (e.hasMoreElements()) | |
| 21 { | |
| 22 let window = e.getNext().QueryInterface(Ci.nsIDOMWindow); | |
| 23 let button = window.document.getElementById("inspector-abp-elemhide-tool button"); | |
| 24 if (button) | |
| 25 button.parentNode.removeChild(button); | |
| 26 } | |
| 27 }.bind(this)); | 17 }.bind(this)); |
| 28 }, | 18 }, |
| 29 | 19 |
| 30 get inspectorButton() | 20 get inspectorButton() |
| 31 { | 21 { |
| 32 // Randomize URI to work around bug 719376 | 22 // Randomize URI to work around bug 719376 |
| 33 let stringBundle = Services.strings.createBundle("chrome://elemhidehelper/lo cale/global.properties?" + Math.random()); | 23 let stringBundle = Services.strings.createBundle("chrome://elemhidehelper/lo cale/global.properties?" + Math.random()); |
| 34 let result = [stringBundle.GetStringFromName("inspector.button.label"), stri ngBundle.GetStringFromName("inspector.button.accesskey"), stringBundle.GetString FromName("inspector.button.tooltiptext")]; | 24 let result = [stringBundle.GetStringFromName("inspector.button.label"), stri ngBundle.GetStringFromName("inspector.button.accesskey"), stringBundle.GetString FromName("inspector.button.tooltiptext")]; |
| 35 | 25 |
| 36 delete this.inspectorButton; | 26 delete this.inspectorButton; |
| 37 this.__defineGetter__("inspectorButton", function() result); | 27 this.__defineGetter__("inspectorButton", function() result); |
| 38 return this.inspectorButton; | 28 return this.inspectorButton; |
| 39 }, | 29 }, |
| 40 | 30 |
| 41 observe: function(subject, topic, data) | 31 inspectorReady: function(eventName, listener) |
|
Wladimir Palant
2014/04/11 11:06:08
The second parameter here isn't listener but panel
saroyanm
2014/04/11 16:09:10
Good catch, actually I've tested and seams like th
| |
| 42 { | 32 { |
| 43 if (topic != "inspector-opened") | 33 let toolbox = gDevTools.getToolbox(listener.target); |
|
Wladimir Palant
2014/04/11 11:06:08
I checked why the documentation mentions getToolbo
saroyanm
2014/04/11 16:09:10
Good point: I've tested with FF19 and there is an
| |
| 34 if (!toolbox) | |
| 44 return; | 35 return; |
| 45 | 36 |
| 46 let InspectorUI = subject.wrappedJSObject; | 37 let panel = toolbox.getToolPanels().get("inspector"); |
| 47 let window = InspectorUI.chromeWin; | 38 if (!panel) |
| 48 let button = window.document.getElementById("inspector-abp-elemhide-toolbutt on"); | |
| 49 if (button) | |
| 50 button.parentNode.removeChild(button); | |
| 51 | |
| 52 if (!("@adblockplus.org/abp/public;1" in Cc) || !window._ehhWrapper || !requ ire("aardvark").Aardvark.canSelect(window._ehhWrapper.browser)) | |
| 53 return; | 39 return; |
|
Wladimir Palant
2014/04/11 11:06:08
So you are going from the panel to the toolbox to
saroyanm
2014/04/11 16:09:10
Lol :)
| |
| 54 | 40 |
| 55 let parent = window.document.getElementById("inspector-tools"); | 41 let panelWindow = panel.panelWin; |
| 42 let parent = panelWindow.document.getElementById("inspector-toolbar"); | |
| 56 if (!parent) | 43 if (!parent) |
| 57 return; | 44 return; |
| 58 | 45 |
| 59 let [label, accesskey, tooltiptext] = this.inspectorButton; | 46 let [label, accesskey, tooltiptext] = InspectorObserver.inspectorButton; |
| 60 button = window.document.createElement("toolbarbutton"); | 47 button = panelWindow.document.createElement("toolbarbutton"); |
| 61 button.setAttribute("id", "inspector-abp-elemhide-toolbutton"); | 48 button.setAttribute("id", "inspector-abp-elemhide-toolbutton"); |
| 62 button.setAttribute("label", label); | 49 button.setAttribute("label", label); |
| 63 button.setAttribute("class", "devtools-toolbarbutton"); | 50 button.setAttribute("class", "devtools-toolbarbutton"); |
| 64 button.setAttribute("accesskey", accesskey); | 51 button.setAttribute("accesskey", accesskey); |
| 65 button.setAttribute("tooltiptext", tooltiptext); | 52 button.setAttribute("tooltiptext", tooltiptext); |
| 66 button.setAttribute("tabindex", "0"); | 53 button.setAttribute("tabindex", "0"); |
| 67 button.addEventListener("command", function() | 54 button.addEventListener("command", function() |
| 68 { | 55 { |
| 69 InspectorUI.chromeWin.openDialog("chrome://elemhidehelper/content/composer .xul", "_blank", | 56 panelWindow.openDialog("chrome://elemhidehelper/content/composer.xul", "_b lank", |
| 70 "chrome,centerscreen,resizable,dialog=no" , InspectorUI.selection); | 57 "chrome,centerscreen,resizable,dialog=no", panel.se lection.node); |
| 71 InspectorUI.closeInspectorUI(); | |
| 72 }, false); | 58 }, false); |
| 73 parent.appendChild(button); | 59 parent.appendChild(button); |
|
Wladimir Palant
2014/04/11 11:06:08
Adding the button at the end probably isn't the be
saroyanm
2014/04/11 16:09:10
Good point changed. Thanks for pointing.
| |
| 74 }, | 60 } |
| 75 | |
| 76 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse rver]) | |
| 77 }; | 61 }; |
| 78 | 62 |
| 79 InspectorObserver.init(); | 63 InspectorObserver.init(); |
| OLD | NEW |