forked from browser-update/browser-update
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.js
310 lines (282 loc) · 11.5 KB
/
update.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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
//(c)2017, MIT Style License <browser-update.org/LICENSE.txt>
//it is recommended to directly link to this file because we update the detection code
"use strict";
var $bu_= new function() {
var s=this;
this.vsakt = {e:17,i:15,f:62,o:56,o_a:47,s:11.1,c:69,y:18.6,v:2.0,uc:12.9,samsung:7.4,ios:12};
//severly insecure below(!) this version, insecure means remote code execution that is actively being exploited
this.vsinsecure_below = {i:11,e:15,c:64,f:59,y:18.4,s:"10.1.2",ios:"9.3.5",v:"1.14",uc:"12.6",samsung:"6.4",o_a:44,o:51};
this.vsdefault = {e:-3,i:11,f:-3,o:-3,o_a:-3,s:-1,c:-3,a:535,y:18.6,v:1.12,uc:12.1,samsung:6.4,ios:9};
this.names={i:'Internet Explorer',e:"Edge",f:'Firefox',o:'Opera',o_a:'Opera',s:'Safari',c:"Chrome",a:"Android Browser", y:"Yandex Browser",v:"Vivaldi",uc:"UC Browser",samsung:"Samsung Internet",x:"Other",ios:"iOS",silk:"Silk"};
this.get_browser = function(ua) {
var n,ua=(ua||navigator.userAgent).replace("_","."),r={n:"x",v:0,t:"other browser",age_years:undefined,no_device_update:false,available:s.vsakt};
function ignore(reason,pattern){if (new RegExp(pattern,"i").test(ua)) return reason;return false}
r.other=ignore("bot","bot|spider|archiver|transcoder|crawl|checker|monitoring|prerender|screenshot|python-|php|uptime|validator|fetcher|facebook|slurp|google|yahoo|node|mail.ru|github|cloudflare|addthis|thumb|proxy|feed|fetch|favicon|link|http|scrape|seo|page|search console|AOLBuild|Teoma|Expeditor")||
// ignore("discontinued browser","camino|flot|fennec|galeon|coolnovo") ||
ignore("TV","SMART-TV|SmartTV") ||
ignore("niche browser","Dorado|LBBROWSER|waterfox|Firefox/56.2|Firefox/56.3|Whale|MIDP|k-meleon|sparrow|wii|Chromium|Puffin|Opera Mini|maxthon|maxton|dolfin|dolphin|seamonkey|opera mini|netfront|moblin|maemo|arora|kazehakase|epiphany|konqueror|rekonq|symbian|webos|PaleMoon|QupZilla|Otter|Midori|qutebrowser") ||
ignore("mobile without upgrade path or landing page","cros|kindle|tizen|silk|blackberry|bb10|RIM|PlayBook|meego|nokia|ucweb|ZuneWP7|537.85.10");
// ignore("android(chrome) web view","; wv");
r.mobile=(/iphone|ipod|ipad|android|mobile|phone|ios|iemobile/i.test(ua));
var pats=[
["CriOS.VV","c",'ios'],
["FxiOS.VV","f",'ios'],
["Trident.*rv:VV","i",'i'],
["Trident.VV","io",'i'],
["UCBrowser.VV","uc",'c'],
["MSIE.VV","i",'i'],
["Edge.VV","e",'e'],
["Vivaldi.VV","v",'c'],
["Android.*OPR.VV","o_a",'c'],
["OPR.VV","o",'c'],
["YaBrowser.VV","y",'c'],
["SamsungBrowser.VV","samsung",'c'],
["Silk.VV","silk",'c'],
["Chrome.VV","c",'c'],
["Firefox.VV","f",'f'],
[" OS.VV.*Safari","ios",'ios'],
["Version.VV.*Safari","s",'s'],
["Safari.VV","so",'s'],
["Opera.*Version.VV","o"],
["Opera.VV","o"]
];
var VV="(\\d+\\.?\\d+\\.?\\d*\\.?\\d*)";
for (var i=0; i < pats.length; i++) {
if (ua.match(new RegExp(pats[i][0].replace("VV",VV),"i"))) {
r.n=pats[i][1];
r.engine=pats[i][2];
break;
}
}
r.fullv=RegExp.$1;
r.v=parseFloat(r.fullv);
// Special treatment of some systems
//do not notify old systems since there is no up-to-date browser available
if (/windows.nt.5.0|windows.nt.4.0|windows.95|windows.98|os x 10.2|os x 10.3|os x 10.4|os x 10.5/i.test(ua)) {
r.no_device_update=true;
r.available={}
}
//iOS
if (/iphone|ipod|ipad|ios/i.test(ua)) {
ua.match(new RegExp("OS."+VV,"i"));//
r.n="ios";
r.fullv=RegExp.$1;
r.v=parseFloat(r.fullv);
r.engine='ios';
r.available = {"ios": s.available_ios(ua,v)}
if (r.available.ios<11)
r.no_device_update=true;
}
//winxp/vista/2003
if (/windows.nt.5.1|windows.nt.5.2|windows.nt.6.0/i.test(ua)) {
r.available={"c":49.9,"f":52.9}
}
//old mac
if (/os x 10.6/i.test(ua)) {
r.available = {"s": "5.1.10", "c": 49.9, "f": 48}
r.no_device_update=true;
}
if (/os x 10.7|os x 10.8/i.test(ua)) {
r.available = {"s": "6.2.8", "c": 49.9, "f": 48}
r.no_device_update=true;
}
if (/os x 10.9/i.test(ua))
r.available.s="9.1.3"
if (/os x 10.10/i.test(ua))
r.available.s="10.1.2"
//check for android stock browser
if (ua.indexOf('Android')>-1 && r.n==="s") {
var v=parseInt((/WebKit\/([0-9]+)/i.exec(ua) || 0)[1],10) || 2000;
if (v <= 534) {
r.n="a";
r.fullv=r.v=v;
r.is_insecure=true;
}
}
// Special treatment of some browsers
if (r.n==="so") {
r.v=r.fullv=4.0;
r.n="s";
}
if (r.n==="io") {
r.n="i";
if (r.v>6) r.v=11;
else if (r.v>5) r.v=10;
else if (r.v>4) r.v=9;
else if (r.v>3.1) r.v=8;
else if (r.v>3) r.v=7;
else r.v=9;
r.fullv=r.v;
}
r.t=s.names[r.n]+" "+r.v;
r.is_supported=r.is_latest= !s.vsakt[r.n] ? undefined : s.less(r.fullv,s.vsakt[r.n])<=0;
r.vmaj=Math.round(r.v);
r.is_insecure= r.is_insecure|| !s.vsinsecure_below[r.n] ? undefined : s.less(r.fullv,s.vsinsecure_below[r.n])===1;
if ((r.n==="f" && (r.vmaj===52 || r.vmaj===60)) || (r.n==="i" && r.vmaj===11)) {
r.is_supported=true;
r.is_insecure=false;
if (r.n==="f")
r.esr=true;
}
if ((r.n==="c"||r.n==="f"||r.n==="o") && s.less(r.fullv,parseFloat(s.vsakt[r.n])-1)<=0)
r.is_supported=true; //mark also the version before the current version as supported to make the transitions smoother
if (r.n==="ios" && r.v>10.3)
r.is_supported=true;
if (r.n==="a" || r.n==="x")
r.t=s.names[r.n];
if (r.n==="e")
r.t=s.names[r.n]+" "+r.vmaj;
var releases_per_year={'f':7,'c':8,'o':8,'i':1,'e':1,'s':1}//,'v':1}
if (releases_per_year[r.n]) {
r.age_years=Math.round(((s.vsakt[r.n]-r.v)/releases_per_year[r.n])*10)/10 || 0
}
var engines={e:"Edge.VV",c:"Chrome.VV",f:"Firefox.VV",s:"Version.VV",i:"MSIE.VV","ios":" OS.VV"}
if (r.engine) {
ua.match(new RegExp(engines[r.engine].replace("VV",VV),"i"))
r.engine_version=parseFloat(RegExp.$1)
}
return r;
}
this.semver = function(vstr) {
if (vstr instanceof Array)
return vstr
var x = (vstr+(".0.0.0")).split('.')
return [parseInt(x[0]) || 0, parseInt(x[1]) || 0, parseInt(x[2]) || 0, parseInt(x[3]) || 0]
}
this.less= function(v1,v2) {
//semantic version comparison: returns 1 if v1<v2 , 0 if equal, -1 if v1>v2
v1=s.semver(v1)
v2=s.semver(v2)
for (var i=0; ;i++) {
if (i>=v1.length) return i>=v2.length ? 0 : 1;
if (i>=v2.length) return -1;
var diff = v2[i]-v1[i]
if (diff) return diff>0 ? 1 : -1;
}
}
this.available_ios=function(ua,v) {
var h = Math.max(window.screen.height, window.screen.width),pr = window.devicePixelRatio
if (/ipad/i.test(ua)) {
if (h == 1024 && pr == 2) // iPad 3 (iOS 9), 4, 5, Mini 2, Mini 3, Mini 4, Air, Air 2, Pro 9.7
return 10//? only ipad 4 has ios 10, all other can have ios 11
if (h == 1112)// iPad Pro 10.5
return 15;
if (h == 1366)//iPad Pro 12.9, Pro 12.9 (2nd Gen)
return 15
if (h == 1024 && v < 6)
return 5 // iPad
return 9 // iPad 2, iPad Mini
}
if (pr == 1)// 1/3G/3GS
return 6//for 3GS
if (h == 812)// && pr == 3)// X
return 11 + 4
if ((h == 736 || h == 667))// && pr == 3)// 6+/6s+/7+ and 8+ or // 6+/6s+/7+ and 8+ in zoom mode + // 6/6s/7 and 8
return 8 + 5
if (h == 568) // 5/5C/5s/SE or 6/6s/7 and 8 in zoom mode
return 10
if (h == 480) // i4/4s
return 7
return 6
}
/*
this.sub= function(v,minus) {
//semantic version subtraction
v=s.semver(v)
minus=s.semver(minus)
for (var i=0; ;i++) {
if (i>=v.length||i>minus.length) break;
v[i]-=v[minus];
}
return v.join('.')
}
*/
}
window.$bu_getBrowser=$bu_.get_browser;
var $buo = function(op,test) {
var n = window.navigator,b;
op=window._buorgres=op||{};
var ll = op.l||(n.languages ? n.languages[0] : null) || n.language || n.browserLanguage || n.userLanguage||document.documentElement.getAttribute("lang")||"en";
op.llfull=ll.replace("_","-").toLowerCase().substr(0,5);
op.ll=op.llfull.substr(0,2);
op.domain=op.domain!==undefined?op.domain:(/file:/.test(location.href)?"https:":"")+"//browser-update.org";
op.apiver=op.api||op.c||-1;
op.jsv="3.2.2";
var required_min=(op.apiver<2018&&{i:10,f:11,o:21,s:8,c:30})||{};
var vs=op.notify||op.vs||{};//old style config: maximum version to notify
vs.e=vs.e||vs.i;
vs.i=vs.i||vs.e;
var required=op.required||{};//minimum browser versions needed
required.e=required.e||required.i;
required.i=required.i||required.e;
for (b in $bu_.vsdefault) {
if (vs[b]) {//old style: browsers to notify
if ($bu_.less(vs[b],0)>=0) // required <= 0
required[b]= parseFloat($bu_.vsakt[b])+parseFloat(vs[b])+0.01
else
required[b] = parseFloat(vs[b]) + 0.01
}
if (!required[b])
required[b]=$bu_.vsdefault[b]
if ($bu_.less(required[b],0)>=0) // required <= 0
required[b]=$bu_.vsakt[b]+required[b]
if (required_min[b] && $bu_.less(required[b],required_min[b])===1) // required < required_min
required[b]=required_min[b]
}
required.ios=required.ios||required.s;
op.required=required;
op.reminder=op.reminder<0.1 ? 0 : op.reminder||(24*7);
op.reminderClosed=op.reminderClosed<1 ? 0 : op.reminderClosed||(24*7);
op.onshow = op.onshow||function(o){};
op.onclick = op.onclick||function(o){};
op.onclose = op.onclose||function(o){};
op.pageurl = op.pageurl || location.hostname || "x";
op.newwindow=(op.newwindow!==false);
op.test=test||op.test||(location.hash==="#test-bu")||false;
if (Math.random()*1200<1 && !op.test) {
var i = new Image(); i.src="//browser-update.org/count.php?what=brow&jsv="+op.jsv;
}
op.test=test||op.test||location.hash==="#test-bu";
op.reasons=[];
op.hide_reasons=[];
function check_show(op) {
var bb=$bu_.get_browser(op.override_ua);
op.is_below_required = required[bb.n] && $bu_.less(bb.fullv,required[bb.n])===1; //bb.fullv<required
if (bb.other!==false)
op.hide_reasons.push("is other browser:" + bb.other)
if ( bb.esr && !op.notify_esr)// || (bb.is_supported && !op.notify_also_supported))
op.hide_reasons.push("Extended support (ESR)")
if (bb.mobile&&op.mobile===false)
op.hide_reasons.push("do not notify mobile")
if (bb.no_device_update)
op.hide_reasons.push("no device update")
if (op.is_below_required)
op.reasons.push("below required")
if ((op.insecure||op.unsecure) && bb.is_insecure)
op.reasons.push("insecure")
if (op.unsupported && !bb.is_supported)
op.reasons.push("no vendor support")
if (op.hide_reasons.length>0)
return false
if (op.reasons.length>0)
return true
return false
}
op.notified=check_show(op);
op.already_shown=document.cookie.indexOf("browserupdateorg=pause")>-1;
if (!op.test && (!op.notified || op.already_shown))
return;
op.setCookie=function(hours) {
document.cookie = 'browserupdateorg=pause; expires='+(new Date(new Date().getTime()+3600000*hours)).toGMTString()+'; path=/';
};
if (op.reminder>0)
op.setCookie(op.reminder);
if (op.nomessage) {
op.onshow(op);
return;
}
var e=document.createElement("script");
e.src = op.jsshowurl||op.domain+"/update.show.min.js";
document.body.appendChild(e);
};
$buo(window.$buoop);