/
setCurrentProfileNameToTitlebar.uc.js
94 lines (85 loc) · 4.36 KB
/
setCurrentProfileNameToTitlebar.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
// ==UserScript==
// @name setCurrentProfileNameToTitlebar
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description Profilbezeichnung in der Titelleiste angezeigen
// @include main
// @compatibility Firefox 19 - 38.*
// @author Alice0775
// @version 2012/12/31 00:00 Bug 818800 Remove the global private browsing service
// ==/UserScript==
// @version 2015/06/06 fix
// @version 2012/08/06 08:00 remove hack privatebrowsingUI
// @version 2010/09/25 23:00 Bug 598221 - Page Title not shown in Title Bar on Session Restore
// @version 2009/07/25 18:00 Bug 506437 - The titlebar of a tear off window is not updated correctly after having detached a tab
// @version 2008/03/06 15:00
// @Note Offizielle Win32 Version, Start und andere Profil-Optionen, bei Verwendung des Standardpfades.
(function(){
//Aktuelle Profilbezeichnung abrufen
//auch wenn die Bezeichnung geändert wurde
//(nsIToolkitProfileService)zum Arbeiten verwenden
//Bootoptionen und Informationen der offizielle Win32 Version auslesen, bei Verwendung des Standardpfades.
function getCurrentProfileName(){
function readFile(aFile){
var stream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream); stream.init(aFile, 0x01, 0, 0);
var cvstream = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
cvstream.init(stream, "UTF-8", 1024, Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
var content = "", data = {};
while (cvstream.readString(4096, data)) {
content += data.value;
}
cvstream.close();
return content.replace(/\r\n?/g, "\n");
}
var PrefD = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("PrefD", Components.interfaces.nsILocalFile);
var ini = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("AppRegD", Components.interfaces.nsILocalFile);
ini.append("profiles.ini");
var ini = readFile(ini);
var profiles = ini.match(/Name=.+/g);
var profilesD = ini.match(/Path=.+/g);
for ( var i = 0; i < profiles.length;i++) {
if ((profilesD[i]+"$").indexOf(PrefD.leafName+"$") >= 0) {
profiles[i].match(/Name=(.+)$/);
return RegExp.$1;
}
}
return null;
}
window.setCurrentProfileNameToTitlebar = function(){
var profile = getCurrentProfileName();
if (!profile) return;
// Set the title modifer to include the build ID.
var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULAppInfo);
var appBuildID = appInfo.appBuildID;
var mainWindow = document.getElementById("main-window");
if ('gPrivateBrowsingUI' in window && gPrivateBrowsingUI.privateBrowsingEnabled)
var originalName = mainWindow.getAttribute("title_privatebrowsing");
else
var originalName = mainWindow.getAttribute("title_normal");
["title_normal", "title_privatebrowsing", "titlemodifier", "titlemodifier_normal", "titlemodifier_privatebrowsing"].
forEach(callback);
function callback(attrname){
var originalName = mainWindow.getAttribute(attrname);
var titlemodifier = "[" + profile+ "] " +originalName;// + " - " + appBuildID;
// Set the new title modifier
mainWindow.setAttribute(attrname, titlemodifier);
}
// Now set the title of the window
// Bug 506437 - The titlebar of a tear off window is not updated correctly after having detached a tab
if ('gPrivateBrowsingUI' in window && gPrivateBrowsingUI.privateBrowsingEnabled)
document.title = content.document.title + " - " + "[" + profile+ "] " + originalName;
else
document.title = document.title.replace(new RegExp(originalName+"$", ""), "[" + profile+ "] " + originalName);
};
if ('gPrivateBrowsingUI' in window &&
typeof gPrivateBrowsingUI._privateBrowsingService == 'undefined')
try {
gPrivateBrowsingUI._privateBrowsingService = Cc["@mozilla.org/privatebrowsing;1"].
getService(Ci.nsIPrivateBrowsingService);
} catch(e){}
setTimeout(function(){
setCurrentProfileNameToTitlebar();
//xxx Bug 598221
gBrowser.updateTitlebar()
}, 500);
})();