This repository has been archived by the owner on Apr 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
idevice.js
150 lines (134 loc) · 3.18 KB
/
idevice.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
/*!
iDevice.js v2.1.0
(c) Alexandre Dieulot
dieulot.fr/idevice/license
*/
var iDevice = (function() {
var canvasElement = document.createElement('canvas')
try {
var context = canvasElement.getContext('webgl')
var extension = context.getExtension('WEBGL_debug_renderer_info')
var gpu = context.getParameter(extension.UNMASKED_RENDERER_WEBGL)
}
catch (e) {
return
}
var matches = gpu.match(/^Apple (.+) GPU$/)
var cpu = matches && matches[1]
var s = screen.width + 'x' + screen.height
var dpr = devicePixelRatio
if (!cpu) {
if (gpu == 'PowerVR SGX 535' && s == '768x1024' && dpr == 1) {
return 'iPad 2/mini 1'
}
if (gpu == 'PowerVR SGX 543' && dpr == 2) {
if (s == '320x480') {
return 'iPhone 4s'
}
if (s == '768x1024') {
return 'iPad 3'
}
if (s == '320x568') {
if (navigator.userAgent.indexOf('iPod') > -1) {
return 'iPod Touch 5'
}
return 'iPhone 5/5c'
}
}
if (gpu == 'PowerVR SGX 554' && s == '768x1024' && dpr == 2) {
return 'iPad 4'
}
return
}
if (cpu == 'A7') {
if (s == '320x568') {
return 'iPhone 5s'
}
if (s == '768x1024') {
return 'iPad Air/mini 2/mini 3'
}
}
if (s == '320x568') {
if (cpu == 'A8' && navigator.userAgent.indexOf('iPod') > -1) {
return 'iPod Touch 6'
}
if (cpu == 'A9') {
return 'iPhone SE (or 6s with Display Zoom)'
}
}
var models = ['6', '6s', '7', '8']
var cpuGeneration = parseInt(cpu.substr(1))
if (cpuGeneration >= 8 && cpuGeneration <= 11) {
if (dpr == 2 && (s == '375x667' || s == '320x568')) {
return 'iPhone ' + models[cpuGeneration - 8]
}
if (dpr == 3 && (s == '414x736' || s == '375x667')) {
return 'iPhone ' + models[cpuGeneration - 8] + ' Plus'
}
}
if (cpu == 'A8' && s == '768x1024') {
return 'iPad mini 4'
}
if (cpu == 'A8X' && s == '768x1024') {
return 'iPad Air 2'
}
if (cpu == 'A9' && s == '768x1024') {
return 'iPad (2017)'
}
if (cpu == 'A9X') {
if (s == '768x1024') {
return 'iPad Pro 9.7" (2016)'
}
if (s == '1024x1366') {
return 'iPad Pro 12.9" (2015)'
}
}
if (cpu == 'A10') {
if (s == '768x1024') {
return 'iPad (2018)'
}
}
if (cpu == 'A10X') {
if (s == '834x1112') {
return 'iPad Pro 10.5" (2017)'
}
if (s == '1024x1366') {
return 'iPad Pro 12.9" (2017)'
}
}
if (cpu == 'A11') {
if (s == '375x812') {
return 'iPhone X'
}
}
if (cpu == 'A12') {
if (dpr == 2) {
if (s == '375x812' || s == '414x896') {
return 'iPhone XR'
}
if (s == '834x1112') {
return 'iPad Air (2019)'
}
if (s == '768x1024') {
return 'iPad mini (2019)'
}
}
if (dpr == 3) {
if (s == '375x812') {
return 'iPhone XS (or XS Max with Display Zoom)'
}
if (s == '414x896') {
return 'iPhone XS Max'
}
}
}
if (cpu == 'A12X') {
if (s == '834x1194') {
return 'iPad Pro 11" (2018)'
}
if (s == '1024x1366') {
return 'iPad Pro 12.9" (2018)'
}
}
return 'Unidentified ' + cpu + ' ' + s + '@' + dpr
})();