-
Notifications
You must be signed in to change notification settings - Fork 123
/
ProminentDomain.uc.js
300 lines (266 loc) · 11 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// ==UserScript==
// @name ProminentDomain.uc.js
// @namespace
// @description Prominent Domain
// @include main
// @compatibility Firefox 32.0a1
// @author
// @version 2015/03/11 00:00 change handle overflow
// @version 2014/02/29 00:00 change workaround
// @version 2014/02/28 00:00 Workaround Bug 1014246
// @version 2013/07/12 17:00 by Alice0775 reset horizontal scroll (workaround Bug 893312)
// @version 2012/12/05 21:00 by Alice0775 fixed getValidTld
// ==/UserScript==
// @version 2012/11/24 23:00 by Alice0775 fixed key navigation
// @version 2012/05/13 23:00 by Alice0775 Bug 754498 - Domain should not be highlighted in the address bar when the URL differs from the page
// @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
var ProminentDomain = {
init0: function() {
var xpPref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch2);
try{
if (xpPref.setBoolPref("browser.urlbar.formatting.enabled", false))
return;
} catch(ex) {}
try{
if (xpPref.setBoolPref("browser.urlbar.trimURLs", false))
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 (!(this.label = document.getElementById("textbox-input-box-button"))) {
var icons = document.getElementById("urlbar-icons");
this.label = document.createElement("label");
this.label.setAttribute("id", "textbox-input-box-button");
//this.label.setAttribute("class", "textbox-input-box");
this.label.style.setProperty("-moz-appearance", "label", "important");
this.label.style.setProperty("border", "0px", "");
this.label.style.setProperty("padding", "0px", "");
this.label.style.setProperty("margin-left", "-3px", "");
this.label.style.setProperty("margin-right", "-3px", "");
this.label.style.setProperty("background-color", "transparent", "");
this.label.style.setProperty("visibility", "collapse", "");
this.label.textContent = "";
icons.insertBefore(this.label, icons.firstChild);
}
// Workaround Bug 1014246
setTimeout(function(){this.init();}.bind(this), 0);
var self = this;
window.addEventListener("unload", this, false);
gBrowser.addProgressListener(this);
gNavToolbox.addEventListener("aftercustomization", this, false);
// observ placeContent tree view change
// create an observer instance
this.observer1 = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type == "attributes" &&
mutation.attributeName == "focused") {
ProminentDomain.debug("onFocusChange");
if (ProminentDomain._timer)
clearTimeout(ProminentDomain._timer);
if (mutation.target.getAttribute(mutation.attributeName) == "true" &&
gURLBar.getAttribute("pageproxystate") !="invalid" )
ProminentDomain.plainView();
else
ProminentDomain.prettyView();
}
});
});
// configuration of the observer:
var config1 = { attributes: true }
// pass in the target node, as well as the observer options
this.observer1.observe(gURLBar, config1);
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;
document.getAnonymousElementByAttribute(gURLBar, "anonid", "input").
addEventListener("overflow", this, false);
document.getAnonymousElementByAttribute(gURLBar, "anonid", "input").
addEventListener("underflow", this, false);
},
uninit: function(){
window.removeEventListener("unload", this, false);
gBrowser.removeProgressListener(this);
gNavToolbox.removeEventListener("aftercustomization", this, false);
document.getAnonymousElementByAttribute(gURLBar, "anonid", "input").
removeEventListener("overflow", this, false);
document.getAnonymousElementByAttribute(gURLBar, "anonid", "input").
removeEventListener("underflow", this, false);
//stop observing
if (this.observer1)
this.observer1.disconnect();
},
handleEvent: function(event){
switch(event.type) {
case "aftercustomization":
this.onAftercustomization();
break;
case "overflow":
if(event.detail >= 1)
this.label.textContent = "...";
break;
case "underflow":
if(event.detail >= 1)
this.label.textContent = "";
break;
case "unload":
this.uninit();
break;
}
},
onAftercustomization: function() {
this.init();
this.prettyView();
},
QueryInterface: function(aIID) {
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
aIID.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_NOINTERFACE;
},
onStateChange: function(aWebProgress, aRequest, aFlag, aStatus) { },
onLocationChange: function(aProgress, aRequest, aURI) {
// This fires when the location bar changes; that is load event is confirmed
// or when the user switches tabs. If you use myListener for more than one tab/window,
// use aProgress.DOMWindow to obtain the tab/window which triggered the change.
if (aProgress.DOMWindow == content) {
ProminentDomain.debug("onLocationChange");
if (ProminentDomain._timer)
clearTimeout(ProminentDomain._timer);
ProminentDomain._timer = setTimeout(function(){
if (gURLBar.getAttribute("focused") != "true")
ProminentDomain.prettyView();
else
ProminentDomain.plainView();
}, 0);
}
},
// For definitions of the remaining functions see related documentation
onProgressChange: function(aWebProgress, aRequest, curSelf, maxSelf, curTot, maxTot) { },
onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) { },
onSecurityChange: function(aWebProgress, aRequest, aState) { },
onPrintPreviewExit: function() {
if ( typeof PrintPreviewListener._toggleAffectedChrome == "function" &&
!/gNavToolbox\.collapsed/.test(PrintPreviewListener._toggleAffectedChrome))
this.init();
this.prettyView();
},
prettyView: function()
{
this.debug("prettyView");
//xxx Bug 754498
if(gURLBar.getAttribute("pageproxystate") == "invalid")
return;
var aURI = gURLBar.value;
if (aURI == "") return; //←追加
if (/^(data:|javascript:|chrome:|view-|about:)/.test(aURI))
return;
var ioService = Components.classes['@mozilla.org/network/io-service;1']
.getService(Components.interfaces.nsIIOService);
try {
//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);
document.getAnonymousElementByAttribute(gURLBar, "anonid", "input").selectionStart = 0;
document.getAnonymousElementByAttribute(gURLBar, "anonid", "input").selectionEnd = 0;
},
plainView: function()
{
this.debug("plainView");
this.label.style.setProperty("visibility", "collapse", "");
if (gURLBar.value == "") return; //←追加
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);
var aURI2 = ioService.newURI(aURI, null, null);
var host = aURI2.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){
return;
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.logStringMessage(aMsg);
}
}
ProminentDomain.init0();