Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
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 | |
4 * http://mozilla.org/MPL/2.0/. | |
5 */ | |
6 | |
7 Cu.import("resource://gre/modules/Services.jsm"); | |
8 | |
9 let {Prefs} = require("prefs"); | |
Wladimir Palant
2012/09/21 15:36:18
You aren't using prefs so you should remove that l
| |
10 let {WindowObserver} = require("windowObserver"); | |
11 | |
12 let knownWindowTypes = | |
13 { | |
14 "navigator:browser": true, | |
15 "mail:3pane": true, | |
16 "mail:messageWindow": true, | |
Wladimir Palant
2012/09/21 15:36:18
I think that you only know navigator:browser - mea
| |
17 __proto__: null | |
18 }; | |
19 | |
20 new WindowObserver({ | |
21 applyToWindow: function(window) | |
22 { | |
23 let type = window.document.documentElement.getAttribute("windowtype"); | |
24 if (!(type in knownWindowTypes)) | |
25 return; | |
26 | |
27 window.addEventListener("popupshowing", popupShowingHandler, false); | |
28 window.addEventListener("popuphidden", popupHiddenHandler, false); | |
29 }, | |
30 | |
31 removeFromWindow: function(window) | |
32 { | |
33 let type = window.document.documentElement.getAttribute("windowtype"); | |
34 if (!(type in knownWindowTypes)) | |
35 return; | |
36 | |
37 window.removeEventListener("popupshowing", popupShowingHandler, false); | |
38 window.removeEventListener("popuphidden", popupHiddenHandler, false); | |
39 } | |
40 }); | |
41 | |
42 function getMenuItem() | |
43 { | |
44 // Randomize URI to work around bug 719376 | |
45 let stringBundle = Services.strings.createBundle("chrome://abpcrawler/locale/g lobal.properties?" + Math.random()); | |
46 let result = [stringBundle.GetStringFromName("crawler.label")]; | |
47 | |
48 getMenuItem = function() result; | |
49 return getMenuItem(); | |
50 } | |
51 | |
52 function popupShowingHandler(event) | |
53 { | |
54 let popup = event.target; | |
55 if (!/^(abp-(?:toolbar|status|menuitem)-)popup$/.test(popup.id)) | |
56 return; | |
57 | |
58 popupHiddenHandler(event); | |
59 | |
60 let [label] = getMenuItem(); | |
61 let item = popup.ownerDocument.createElement("menuitem"); | |
62 item.setAttribute("label", label); | |
63 item.setAttribute("class", "abpcrawler-item"); | |
64 | |
65 item.addEventListener("command", popupCommandHandler, false); | |
66 | |
67 let insertBefore = null; | |
68 for (let child = popup.firstChild; child; child = child.nextSibling) | |
69 if (/-options$/.test(child.id)) | |
70 insertBefore = child; | |
71 popup.insertBefore(item, insertBefore); | |
72 } | |
73 | |
74 function popupHiddenHandler(event) | |
75 { | |
76 let popup = event.target; | |
77 if (!/^(abp-(?:toolbar|status|menuitem)-)popup$/.test(popup.id)) | |
78 return; | |
79 | |
80 let items = popup.getElementsByClassName("abpcrawler-item"); | |
81 while (items.length) | |
82 items[0].parentNode.removeChild(items[0]); | |
83 } | |
84 | |
85 function popupCommandHandler(event) | |
86 { | |
87 if (!("@adblockplus.org/abp/public;1" in Cc)) | |
88 return; | |
89 | |
90 let crawlerWnd = Services.wm.getMostRecentWindow("abpcrawler:crawl"); | |
91 if (crawlerWnd) | |
92 crawlerWnd.focus(); | |
93 else | |
94 event.target.ownerDocument.defaultView.openDialog("chrome://abpcrawler/conte nt/crawler.xul", "_blank", "chrome,centerscreen,resizable,dialog=no"); | |
95 } | |
OLD | NEW |