forked from alice0775/userChrome.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProminentDomain.uc.js
211 lines (189 loc) · 7.24 KB
/
ProminentDomain.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// ==UserScript==
// @name ProminentDomain.uc.js
// @namespace
// @description Prominent Domain
// @include main
// @compatibility Firefox 6.0 7.0
// @author
// @version 2012/01/31 11:00 by Alice0775 12.0a1 about:newtab
// @version 2011/06/24 data:等は無視
// @version 2011/06/24 Bug 665580
// @version 2011/06/10
// @Note
// ==/UserScript==
var ProminentDomain = {
init0: function() {
var xpPref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch2);
try{
if (xpPref.getBoolPref("browser.urlbar.formatting.enabled"))
return;
} catch(ex) {}
try{
if (xpPref.getBoolPref("browser.urlbar.trimURLs"))
return;
} catch(ex) {}
// xxx Bug 660391 - After closing Print preview, the favicon and the domain name highlighting disappears from the navigation bar, and Back/Forward buttons are disabled
if ('PrintUtils' in window &&
!/gNavToolbox\.collapsed/.test(PrintPreviewListener._toggleAffectedChrome.toString())) {
if (!/ProminentDomain/.test(PrintUtils.exitPrintPreview.toSource()))
eval('PrintUtils.exitPrintPreview = '+PrintUtils.exitPrintPreview.toString().replace(
/}$/,
'ProminentDomain.onPrintPreviewExit(); }'
));
}
if (!document.getElementById("textbox-input-box-button")) {
var icons = document.getElementById("urlbar-icons");
this.label = document.createElementNS("http://www.w3.org/1999/xhtml", "button");
this.label.setAttribute("id", "textbox-input-box-button");
this.label.setAttribute("class", "textbox-input-box");
this.label.style.setProperty("-moz-appearance", "textfield", "important");
this.label.style.setProperty("border", "0px", "");
this.label.style.setProperty("padding", "0px", "");
this.label.style.setProperty("margin-left", "-3px", "");
this.label.style.setProperty("background-color", "transparent", "");
this.label.style.setProperty("visibility", "collapse", "");
this.label.textContent = "";
icons.insertBefore(this.label, icons.firstChild);
}
this.init();
var self = this;
gURLBar.addEventListener("ValueChange", function() {
if (!self.hasFocus)
{
self.prettyView();
}
}, false);
gURLBar.addEventListener("blur", function() {
self.hasFocus = false;
self.prettyView();
}, true);
gURLBar.addEventListener("focus", function() {
self.hasFocus = true;
self.plainView();
}, true);
document.getElementById("cmd_CustomizeToolbars").addEventListener("DOMAttrModified", function(aEvent) {
if (aEvent.attrName == "disabled" && !aEvent.newValue)
{
self.init();
self.prettyView();
dump("Initialized Prominent Domain");
}
}, false);
if (document.focusedElement != gURLBar)
gURLBar.value = "";
setTimeout(function(self){
gURLBar.value = gURLBar.value || gBrowser.currentURI.spec;
self.prettyView();
}, 250, this);
},
init: function() {
if (!gURLBar ||
!document.getAnonymousElementByAttribute(gURLBar, "anonid", "input") ||
!document.getAnonymousElementByAttribute(gURLBar, "anonid", "input")
.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor)
return;
this.nNormal = document.createElementNS("http://www.w3.org/1999/xhtml", "label");
this.nNormal.appendChild(document.createTextNode(""));
this.nStrong = document.createElementNS("http://www.w3.org/1999/xhtml", "label");
this.nStrong.style.color='blue';
this.nStrong.style.marginLeft = this.nStrong.style.marginRight = "0.0em";
this.nStrong.appendChild(document.createTextNode(""));
this.nBase = document.getAnonymousElementByAttribute(gURLBar, "anonid", "input").QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor.rootElement;
var self = this;
document.getAnonymousElementByAttribute(gURLBar, "anonid", "input").
addEventListener("overflow", function() {
self.label.textContent = "...";
}, false);
document.getAnonymousElementByAttribute(gURLBar, "anonid", "input").
addEventListener("underflow", function() {
self.label.textContent = "";
}, false);
},
onPrintPreviewExit: function() {
if ( typeof PrintPreviewListener._toggleAffectedChrome == "function" &&
!/gNavToolbox\.collapsed/.test(PrintPreviewListener._toggleAffectedChrome))
this.init();
this.prettyView();
},
prettyView: function()
{
var aURI = gURLBar.value;
if (/^(data:|javascript:|chrome:|view-|about:)/.test(aURI))
return;
try {
var ioService = Components.classes['@mozilla.org/network/io-service;1']
.getService(Components.interfaces.nsIIOService);
//aURI = ioService.newURI(aURI, null, null).spec;
aURI = losslessDecodeURI(ioService.newURI(aURI, null, null))
} catch(ex) {}
if (!/^(.+?\/\/(?:[^\/]+@)?)(.+?)((:\d+)?(\/.*)?)$/.test(aURI))
{
return;
}
if ("isBlankPageURL" in window ? !isBlankPageURL(aURI) : aURI != "about:blank")
gURLBar.removeAttribute("isempty");
this.label.style.setProperty("visibility", "visible", "");
while (this.nBase.hasChildNodes())
{
this.nBase.removeChild(this.nBase.lastChild);
}
var a1 = RegExp.$1;
var a2 = RegExp.$2;
var a3 = RegExp.$3;
//alert (a1 +" , "+ a2 +" , "+ a3)
var tld = this.getValidTld(aURI);
//alert(tld.replace(/^\[/, "\\[").replace(/\]$/, "\\]")+"$")
var r = new RegExp(tld.replace(/^\[/, "\\[").replace(/\]$/, "\\]")+"$", "");
a1 += a2.replace(r, '');
[a1, tld, a3].forEach(function(aPart, aIx) {
var node = (aIx == 1 ? this.nStrong : this.nNormal).cloneNode(true);
node.firstChild.nodeValue = aPart;
this.nBase.appendChild(node);
}, this);
},
plainView: function()
{
if (gURLBar.value == "") return; //←追加
this.label.style.setProperty("visibility", "collapse", "");
this.nBase.replaceChild(document.createTextNode(gURLBar.value), this.nBase.firstChild);
while (this.nBase.childNodes.length > 1)
{
this.nBase.removeChild(this.nBase.lastChild);
}
gURLBar.select();
},
getValidTld: function(aURI){
try {
var ioService = Components.classes['@mozilla.org/network/io-service;1']
.getService(Components.interfaces.nsIIOService);
aURI = ioService.newURI(aURI, null, null);
var host = aURI.host;
} catch(e) {
if (aURI.match(/^(.+?\/\/(?:[^\/]+@)?)((?::\d+)?[^\/]+)(.*)$/)) {
var host = RegExp.$2;
} else {
return "";
}
}
var eTLDService = Components.classes["@mozilla.org/network/effective-tld-service;1"]
.getService(Components.interfaces.nsIEffectiveTLDService);
try {
var tld = eTLDService.getBaseDomainFromHost(host);
if (host.indexOf(tld) > -1)
return tld;
else
return host;
} catch(e) {
if (/::/.test(host))
host = "[" + host + "]";
return host;
}
},
debug: function(aMsg){
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.logStringMessage(aMsg);
}
}
ProminentDomain.init0();