-
Notifications
You must be signed in to change notification settings - Fork 123
/
ZZZZ-launchMainWindowFrom.uc.js
107 lines (94 loc) · 4.03 KB
/
ZZZZ-launchMainWindowFrom.uc.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
106
107
// ==UserScript==
// @name ZZZZ-launchMainWindowFrom.uc.js
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description ダウンロードマネージャーからメインウインドウを再構築
// @include *
// @exclude chrome://browser/content/browser.xul
// @compatibility Firefox 3.0 more
// @author Alice0775
// @version 2014/10/26 fix
// @version 2014/06/07 fix
// @version 2014/06/07 menupopup
// @version 2009/12/12 TypeがあったのでZZZ-inspectChrome.uc.jsが無いと動かなかった
// @version 2009/12/12
// @note ZZZ-inspectChrome.uc.jsがある場合はZZZ-inspectChrome.uc.jsの方が先に動くようにしておく
// ==/UserScript==
var launchMainWindowFrom = {
init: function() {
let menuitem = document.createElement("menuitem");
menuitem.setAttribute("class", "launchMainWindowFrom-menuitem");
menuitem.setAttribute("label", "Launch Main Window");
menuitem.setAttribute("accesskey","L");
menuitem.setAttribute("oncommand", "launchMainWindowFrom.openBrowserWindow();");
let menupopup = null;
if (!document.documentElement.hasAttribute("context")) {
menupopup = document.createElement("menupopup");
menupopup.setAttribute("id", "launchMainWindowFrom-popup");
document.documentElement.appendChild(menupopup);
document.documentElement.setAttribute("context", "launchMainWindowFrom-popup");
menupopup.appendChild(menuitem.cloneNode(true));
} else {
document.getElementById(document.documentElement.getAttribute("context"))
.appendChild(menuitem.cloneNode(true));
}
let menupopups = document.getElementsByTagName("menupopup");
for(let i= 0; i < menupopups.length; i++) {
let menupopup = menupopups[i];
menupopup.addEventListener("popupshowing", this, false);
}
},
isExistMainWindow: function() {
var mediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
if(mediator.getMostRecentWindow("navigator:browser"))
return true;
return false;
},
handleEvent: function(aEvent) {
switch(aEvent.type) {
case "popupshowing":
this.onPopupshowing(aEvent);
break;
}
},
onPopupshowing: function(aEvent) {
let menupopup = aEvent.target;
let menuitems = menupopup.getElementsByClassName("launchMainWindowFrom-menuitem");
if (menuitems.length < 1)
return;
if (this.isExistMainWindow()) {
menuitems[0].setAttribute("hidden", true);
} else {
menuitems[0].removeAttribute("hidden");
}
},
openBrowserWindow: function() {
var charsetArg = new String();
var handler = Components.classes["@mozilla.org/browser/clh;1"]
.getService(Components.interfaces.nsIBrowserHandler);
var defaultArgs = handler.defaultArgs;
var wintype = "navigator:browser"; //document.documentElement.getAttribute('windowtype');
// if and only if the current window is a browser window and it has a document with a character
// set, then extract the current charset menu setting from the current document and use it to
// initialize the new browser window...
var win;
if (window && (wintype == "navigator:browser") && window.content && window.content.document)
{
var DocCharset = window.content.document.characterSet;
charsetArg = "charset="+DocCharset;
//we should "inherit" the charset menu setting in a new window
win = window.openDialog("chrome://browser/content/", "_blank", "chrome,all,dialog=no", defaultArgs, charsetArg);
}
else // forget about the charset information.
{
win = window.openDialog("chrome://browser/content/", "_blank", "chrome,all,dialog=no", defaultArgs);
}
return win;
},
debug: function(str) {
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.logStringMessage(str);
}
}
launchMainWindowFrom.init();