forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOS.js
More file actions
262 lines (218 loc) · 5.37 KB
/
Copy pathOS.js
File metadata and controls
262 lines (218 loc) · 5.37 KB
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
var OS = {
/**
* @property {boolean} desktop - Is running on a desktop?
* @default
*/
desktop: false,
/**
* @property {boolean} webApp - Set to true if running as a WebApp, i.e. within a WebView
* @default
*/
webApp: false,
/**
* @property {boolean} iOS - Is running on iOS?
* @default
*/
iOS: false,
/**
* @property {number} iOSVersion - If running in iOS this will contain the major version number.
* @default
*/
iOSVersion: 0,
/**
* @property {boolean} iPhone - Is running on iPhone?
* @default
*/
iPhone: false,
/**
* @property {boolean} iPad - Is running on iPad?
* @default
*/
iPad: false,
/**
* @property {boolean} cocoonJS - Is the game running under CocoonJS?
* @default
*/
cocoonJS: false,
/**
* @property {boolean} cocoonJSApp - Is this game running with CocoonJS.App?
* @default
*/
cocoonJSApp: false,
/**
* @property {boolean} cordova - Is the game running under Apache Cordova?
* @default
*/
cordova: false,
/**
* @property {boolean} node - Is the game running under Node.js?
* @default
*/
node: false,
/**
* @property {boolean} nodeWebkit - Is the game running under Node-Webkit?
* @default
*/
nodeWebkit: false,
/**
* @property {boolean} electron - Is the game running under GitHub Electron?
* @default
*/
electron: false,
/**
* @property {boolean} ejecta - Is the game running under Ejecta?
* @default
*/
ejecta: false,
/**
* @property {boolean} crosswalk - Is the game running under the Intel Crosswalk XDK?
* @default
*/
crosswalk: false,
/**
* @property {boolean} android - Is running on android?
* @default
*/
android: false,
/**
* @property {boolean} chromeOS - Is running on chromeOS?
* @default
*/
chromeOS: false,
/**
* @property {boolean} linux - Is running on linux?
* @default
*/
linux: false,
/**
* @property {boolean} macOS - Is running on macOS?
* @default
*/
macOS: false,
/**
* @property {boolean} windows - Is running on windows?
* @default
*/
windows: false,
/**
* @property {boolean} windowsPhone - Is running on a Windows Phone?
* @default
*/
windowsPhone: false,
/**
* @property {boolean} vita - Is running on a PlayStation Vita?
* @default
*/
vita: false,
/**
* @property {boolean} kindle - Is running on an Amazon Kindle?
* @default
*/
kindle: false,
/**
* @property {number} pixelRatio - PixelRatio of the host device?
* @default
*/
pixelRatio: 1
};
function init ()
{
var ua = navigator.userAgent;
if (/Windows/.test(ua))
{
OS.windows = true;
}
else if (/Mac OS/.test(ua))
{
OS.macOS = true;
}
else if (/Linux/.test(ua))
{
OS.linux = true;
}
else if (/Android/.test(ua))
{
OS.android = true;
}
else if (/iP[ao]d|iPhone/i.test(ua))
{
OS.iOS = true;
(navigator.appVersion).match(/OS (\d+)/);
OS.iOSVersion = parseInt(RegExp.$1, 10);
}
else if (/Kindle/.test(ua) || (/\bKF[A-Z][A-Z]+/).test(ua) || (/Silk.*Mobile Safari/).test(ua))
{
OS.kindle = true;
// This will NOT detect early generations of Kindle Fire, I think there is no reliable way...
// E.g. "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true"
}
else if (/CrOS/.test(ua))
{
OS.chromeOS = true;
}
else if ((/Playstation Vita/).test(ua))
{
OS.vita = true;
}
if (/Windows Phone/i.test(ua) || (/IEMobile/i).test(ua))
{
OS.android = false;
OS.iOS = false;
OS.macOS = false;
OS.windows = true;
OS.windowsPhone = true;
}
var silk = (/Silk/).test(ua);
if (OS.windows || OS.macOS || (OS.linux && !silk) || OS.chromeOS)
{
OS.desktop = true;
}
// Windows Phone / Table reset
if (OS.windowsPhone || ((/Windows NT/i.test(ua)) && (/Touch/i.test(ua))))
{
OS.desktop = false;
}
// WebApp mode in iOS
if (navigator.standalone)
{
OS.webApp = true;
}
if (window.cordova !== undefined)
{
OS.cordova = true;
}
if ((typeof process !== 'undefined') && (typeof process.versions.node !== 'undefined'))
{
OS.node = true;
}
if (OS.node && typeof process.versions === 'object')
{
OS.nodeWebkit = !!process.versions['node-webkit'];
OS.electron = !!process.versions.electron;
}
if (navigator.isCocoonJS)
{
OS.cocoonJS = true;
try
{
OS.cocoonJSApp = (typeof CocoonJS !== 'undefined');
}
catch (error)
{
OS.cocoonJSApp = false;
}
}
if (window.ejecta !== undefined)
{
OS.ejecta = true;
}
if ((/Crosswalk/).test(ua))
{
OS.crosswalk = true;
}
OS.iPhone = ua.toLowerCase().indexOf('iphone') !== -1;
OS.iPad = ua.toLowerCase().indexOf('ipad') !== -1;
OS.pixelRatio = window['devicePixelRatio'] || 1;
return OS;
}
module.exports = init();