forked from alice0775/userChrome.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addBuildIdToAboutDialogueBox.uc.js
155 lines (146 loc) · 6.3 KB
/
addBuildIdToAboutDialogueBox.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
// ==UserScript==
// @name addBuildIdToAboutDialogueBox.uc.js
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description
// @include chrome://browser/content/aboutDialog.xul
// @compatibility Firefox 3.0 3.1
// @author Alice0775
// @version 2008/11/22 12:00
// @Note Help > About画面に にBuilsIDを付加するとともにクリップボードにUA+IDをコピー
// ==/UserScript==
var addBuildid = {
buildid: function (){
// after Fx1.5
if ("@mozilla.org/xre/app-info;1" in Components.classes &&
Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULAppInfo) &&
Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULAppInfo).appBuildID)
var buildid = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULAppInfo).appBuildID;
return buildid;
},
addBuildid: function () {
var userAgentField = document.getElementById("userAgent");
if (userAgentField) {
var ua = userAgentField.value;
var label = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", 'description');
label.textContent = ua;
userAgentField.parentNode.appendChild(label);
} else {
ua = navigator.userAgent;
userAgentField = document.getElementById("rightBox");
var label = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", 'textbox');
userAgentField = userAgentField.appendChild(label);
userAgentField.setAttribute("id", "agent");
userAgentField.setAttribute("value", ua);
userAgentField.setAttribute("multiline", true);
userAgentField.setAttribute("rows", "5");
}
var name = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULAppInfo).name +
"/" +
Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULAppInfo).version;
ua.match(/(.*Gecko\/\d+\b)/);
ua = RegExp.$1 + " " + this.convUA(name) + " ID:" + this.buildid();
userAgentField.value = this.getBuildSource() + "\n" + ua;
userAgentField.setAttribute("value", this.getBuildSource() + "\n" + ua);
window.resizeBy(0, 120);
},
convUA: function(ua){
var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
/*
var e = mainWindow.document.getElementById('menu_openHelp');
if (e) {
var l = e.getAttribute('label');
var n = l.match(/(.*)\s/)[1];
ua = ua.replace(/Firefox/, n);
return ua;
}
*/
// if user overrides build id of useragent identifier, try to get original value.
var pref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch);
const kUA = "general.useragent.extra.firefox";
const kUA2 = "general.useragent.override";
var UA = navigator.userAgent;
if (pref.prefHasUserValue(kUA) || pref.prefHasUserValue(kUA2)){
try {
var oldId = pref.getCharPref(kUA);
pref.clearUserPref(kUA);
} catch (e) {
oldId = "";
}
try {
var oldId2 = pref.getCharPref(kUA2);
pref.clearUserPref(kUA2);
} catch (e) {
oldId2 = "";
}
UA = navigator.userAgent;
if (!!oldId)
pref.setCharPref(kUA, oldId);
if (!!oldId2)
pref.setCharPref(kUA2, oldId2);
};
if (/Firefox/.test(UA))
return ua;
if (/4\.0[ab]?.?\d?pre/.test(ua))
ua = ua.replace(/Firefox/, 'Minefield');
if (/3\.7[ab]?.?\d?pre/.test(ua))
ua = ua.replace(/Firefox/, 'Minefield');
if (/3\.6[ab]?.?\d?pre/.test(ua))
ua = ua.replace(/Firefox/, 'Namoroka');
if (/3\.5[ab]?\d?pre/.test(ua))
ua = ua.replace(/Firefox/, 'Shiretoko');
if (/3\.1[ab]?.?\d?pre/.test(ua))
ua = ua.replace(/Firefox/, 'Shiretoko');
if (/3\.0\.\d[ab]?.?\d?pre/.test(ua))
ua = ua.replace(/Firefox/, 'GranParadiso');
return ua;
},
copyUA: function (){
var userAgentField = document.getElementById("userAgent");
if (!userAgentField)
userAgentField = document.getElementById("agent");
Components.classes["@mozilla.org/widget/clipboardhelper;1"]
.getService(Components.interfaces.nsIClipboardHelper).copyString(userAgentField.value);
},
getBuildSource: function (){
const Cc = Components.classes;
const Ci = Components.interfaces;
const ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
const fph = ios.getProtocolHandler("file").QueryInterface(Ci.nsIFileProtocolHandler);
const ds = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var file = ds.get("CurProcD", Ci.nsIFile);
file.append("application.ini");
var text = this.readFile(file);
var SourceRepository = text.match(/SourceRepository=(.*)/)[1];
var SourceStamp = text.match(/SourceStamp=(.*)/)[1];
//alert(SourceRepository + "/rev/" + SourceStamp);
return SourceRepository + "/rev/" + SourceStamp;
},
readFile: function (aFile){
var stream = Components.classes["@mozilla.org/network/file-input-stream;1"].
createInstance(Components.interfaces.nsIFileInputStream);
stream.init(aFile, 0x01, 0, 0);
var cvstream = Components.classes["@mozilla.org/intl/converter-input-stream;1"].
createInstance(Components.interfaces.nsIConverterInputStream);
cvstream.init(stream, "UTF-8", 1024,
Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
var content = "", data = {};
while (cvstream.readString(4096, data)) {
content += data.value;
}
cvstream.close();
return content.replace(/\r\n?/g, "\n");
}
}
addBuildid.addBuildid();
addBuildid.copyUA();