-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdetect.js
235 lines (233 loc) · 6.72 KB
/
detect.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
var BrowserDetect = {
init: function () {
var info = this.searchString(this.dataBrowser) || {identity:"unknown"}
this.browser = info.identity;
this.version = this.searchVersion(navigator.userAgent)
|| this.searchVersion(navigator.appVersion)
|| "an unknown version";
this.platformInfo = this.searchString(this.dataPlatform) || this.dataPlatform["unknown"];
this.platform = this.platformInfo.identity;
var browserInfo = this.urls[this.browser];
if (!browserInfo) {
browserInfo = this.urls["unknown"];
} else if (browserInfo.platforms) {
var info = browserInfo.platforms[this.platform];
if (info) {
browserInfo = info;
}
}
this.urls = browserInfo;
this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function (data) {
for (var i = 0; i < data.length; i++){
var info = data[i];
var dataString = info.string;
var dataProp = info.prop;
this.versionSearchString = info.versionSearch || info.identity;
if (dataString) {
if (dataString.indexOf(info.subString) != -1) {
return info;
}
} else if (dataProp) {
return info;
}
}
},
searchVersion: function (dataString) {
var index = dataString.indexOf(this.versionSearchString);
if (index == -1) {
return;
}
return parseFloat(dataString.substring(
index + this.versionSearchString.length + 1));
},
dataOS : [
{
string: navigator.platform,
subString: "Win",
identity: "Windows"
},
{
string: navigator.platform,
subString: "Mac",
identity: "Mac"
},
{
string: navigator.userAgent,
subString: "iPhone",
identity: "iPhone/iPod"
},
{
string: navigator.platform,
subString: "Linux",
identity: "Linux"
}
],
dataBrowser: [
{ string: navigator.userAgent,
subString: "Chrome",
identity: "Chrome"
},
{ string: navigator.userAgent,
subString: "OmniWeb",
versionSearch: "OmniWeb/",
identity: "OmniWeb"
},
{ string: navigator.vendor,
subString: "Apple",
identity: "Safari",
versionSearch: "Version"
},
{ string: navigator.userAgent,
subString: "Android",
identity: "Android"
},
{ prop: window.opera,
identity: "Opera"
},
{ string: navigator.vendor,
subString: "iCab",
identity: "iCab"
},
{ string: navigator.vendor,
subString: "KDE",
identity: "Konqueror"
},
{ string: navigator.userAgent,
subString: "Firefox",
identity: "Firefox"
},
{ string: navigator.vendor,
subString: "Camino",
identity: "Camino"
},
{// for newer Netscapes (6+)
string: navigator.userAgent,
subString: "Netscape",
identity: "Netscape"
},
{ string: navigator.userAgent,
subString: "MSIE",
identity: "Explorer",
versionSearch: "MSIE"
},
{ string: navigator.userAgent,
subString: "Gecko",
identity: "Mozilla",
versionSearch: "rv"
},
{ // for older Netscapes (4-)
string: navigator.userAgent,
subString: "Mozilla",
identity: "Netscape",
versionSearch: "Mozilla"
}
],
dataPlatform: [
{ string: navigator.platform,
subString: "Win",
identity: "Windows",
browsers: [
{url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"},
// add back in when opera is stable {url: "http://www.opera.com/browser/next/" name: "Opera Next"},
{url: "http://www.google.com/chrome/", name: "Google Chrome"}
]
},
{ string: navigator.platform,
subString: "Mac",
identity: "Mac",
browsers: [
{url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"},
{url: "http://www.google.com/chrome/", name: "Google Chrome"},
// add back in when opera is stable {url: "http://www.opera.com/browser/next/", name: "Opera Next"},
{url: "http://www.webkit.org/", name: "WebKit Developer Builds"}
]
},
{ string: navigator.userAgent,
subString: "iPhone",
identity: "iPhone/iPod",
browsers: [
{url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"}
]
},
{ string: navigator.platform,
subString: "iPad",
identity: "iPad",
browsers: [
{url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"}
]
},
{ string: navigator.userAgent,
subString: "Android",
identity: "Android",
browsers: [
{url: "https://market.android.com/details?id=org.mozilla.firefox", name: "Mozilla Firefox"}
]
},
{ string: navigator.platform,
subString: "Linux",
identity: "Linux",
browsers: [
{url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"},
{url: "http://www.google.com/chrome/", name: "Google Chrome"},
{url: "http://www.opera.com/browser/next/", name: "Opera Next"}
]
},
{ string: "unknown",
subString: "unknown",
identity: "unknown",
browsers: [
{url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"},
{url: "http://www.google.com/chrome/", name: "Google Chrome"},
{url: "http://www.opera.com/browser/next/", name: "Opera Next"},
{url: "http://www.webkit.org/", name: "WebKit Developer Builds"}
]
}
],
/*
upgradeUrl: Tell the user how to upgrade their browser.
troubleshootingUrl: Help the user.
platforms: Urls by platform. See dataPlatform.identity for valid platform names.
*/
urls: {
"Chrome": {
upgradeUrl: "http://www.google.com/support/chrome/bin/answer.py?answer=95346",
troubleshootingUrl: "http://www.google.com/support/chrome/bin/answer.py?answer=1220892"
},
"Firefox": {
upgradeUrl: "http://www.mozilla.com/en-US/firefox/new/",
troubleshootingUrl: "https://support.mozilla.com/en-US/kb/how-do-i-upgrade-my-graphics-drivers"
},
"Opera": {
upgradeUrl: "http://www.opera.com/browser/next/",
troubleshootingUrl: "http://my.opera.com/desktopteam/blog/"
},
"Android": {
upgradeUrl: null,
troubleshootingUrl: null
},
"Safari": {
platforms: {
"iPhone/iPod": {
upgradeUrl: "http://www.apple.com/ios/",
troubleshootingUrl: "http://www.apple.com/support/iphone/"
},
"iPad": {
upgradeUrl: "http://www.apple.com/ios/",
troubleshootingUrl: "http://www.apple.com/support/ipad/"
},
"Mac": {
upgradeUrl: "http://www.webkit.org/",
troubleshootingUrl: "http://www.webkit.org/blog/919/webgl-draft-specification-now-available/"
}
},
upgradeUrl: "http://www.webkit.org/",
troubleshootingUrl: "http://www.webkit.org/blog/919/webgl-draft-specification-now-available/"
},
"unknown": {
upgradeUrl: null,
troubleshootingUrl: null
}
}
};