blob: 825a57cbe0d0430109d34306cecccde196948e4d [file] [log] [blame]
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +02001// @Author: avm99963 (https://www.avm99963.com)
2/* @License: The MIT License (MIT)
3
4Copyright (c) 2021 Adrià Vilanova Martínez
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE. */
23
24var actualversion;
25
26var app = {
27 init: function() {
28 fetch('https://omahaproxy.appspot.com/all.json')
29 .then(res => res.json())
30 .then(chromeversions => {
31 var browser = BrowserDetect.browser, version = BrowserDetect.version,
32 version2, os3, os2 = System.OS(), os = BrowserDetect.OS;
33 if (navigator.appVersion.indexOf('OPR') != -1) browser = 'Opera';
34 if (browser == 'Chrome') {
35 version2 = window.navigator.appVersion.match(/Chrome\/(.*?) /)[1];
36 if (navigator.appVersion.indexOf('CrOS') != -1)
37 var os = 'Chrome OS', os2 = 'cros', os3 = 'Chrome OS';
38 else
39 var os3 = os2,
40 os2 = str_replace(
41 ['Windows', 'Mac', 'iPhone/iPod', 'Chrome OS', 'Linux'],
42 ['win64', 'mac', 'ios', 'cros', 'linux'], os);
43 var matches = chromeversions.filter(function(val, index, array) {
44 return val.os === os2;
45 });
46 var actualchrome =
47 matches[0].versions.filter(function(val, index, array) {
48 return val.channel === 'stable';
49 });
50 actualversion = actualchrome[0].version.split('.')[0];
51 if (version < actualversion) {
Adrià Vilanova Martíneze9a9f8e2021-06-25 20:51:42 +020052 document.getElementById('updated').innerHTML =
53 '¡Oh, no! Google Chrome ' +
54 '<a href=\'https://support.google.com/chrome/answer/95414\'>no está actualizado</a>.';
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +020055 } else if (version > actualversion) {
56 document.getElementById('updated').innerHTML =
57 'No estás usando el canal estable de Chrome. Ve con cuidado ;-)';
58 } else if (version2 != actualchrome[0].version) {
59 document.getElementById('updated').innerHTML =
Adrià Vilanova Martíneze9a9f8e2021-06-25 20:51:42 +020060 'Oops, Google Chrome ' +
61 '<a href=\'https://support.google.com/chrome/answer/95414\'>no está actualizado</a>.';
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +020062 } else {
63 document.getElementById('updated').innerHTML =
64 'Chrome está actualizado';
65 }
66 } else {
67 os3 = os2;
68 version2 = version;
69 }
70 document.getElementById('version').textContent =
71 'Usas la versión ' + version2 + ' de ' + browser + ' en ' + os3;
72 });
73 }
74}
75
76// Function to detect navigator (informally browser)
77// Source:
78
79var BrowserDetect = {
80 init: function() {
81 this.browser = this.searchString(this.dataBrowser) || '?';
82 this.version = this.searchVersion(navigator.userAgent) ||
83 this.searchVersion(navigator.appVersion) || '?';
84 this.OS = this.searchString(this.dataOS) || '?';
85 },
86 searchString: function(data) {
87 for (var i = 0; i < data.length; i++) {
88 var dataString = data[i].string;
89 var dataProp = data[i].prop;
90 this.versionSearchString = data[i].versionSearch || data[i].identity;
91 if (dataString) {
92 if (dataString.indexOf(data[i].subString) != -1)
93 return data[i].identity;
94 } else if (dataProp)
95 return data[i].identity;
96 }
97 },
98 searchVersion: function(dataString) {
99 var index = dataString.indexOf(this.versionSearchString);
100 if (index == -1) return;
101 return parseFloat(
102 dataString.substring(index + this.versionSearchString.length + 1));
103 },
104 dataBrowser: [
105 {string: navigator.userAgent, subString: 'Chrome', identity: 'Chrome'}, {
106 string: navigator.userAgent,
107 subString: 'OmniWeb',
108 versionSearch: 'OmniWeb/',
109 identity: 'OmniWeb'
110 },
111 {
112 string: navigator.vendor,
113 subString: 'Apple',
114 identity: 'Safari',
115 versionSearch: 'Version'
116 },
117 {prop: window.opera, identity: 'Opera', versionSearch: 'Version'},
118 {string: navigator.vendor, subString: 'iCab', identity: 'iCab'},
119 {string: navigator.vendor, subString: 'KDE', identity: 'Konqueror'},
120 {string: navigator.userAgent, subString: 'Firefox', identity: 'Firefox'},
121 {string: navigator.vendor, subString: 'Camino', identity: 'Camino'}, {
122 // for newer Netscapes (6+)
123 string: navigator.userAgent,
124 subString: 'Netscape',
125 identity: 'Netscape'
126 },
127 {
128 string: navigator.userAgent,
129 subString: 'MSIE',
130 identity: 'Explorer',
131 versionSearch: 'MSIE'
132 },
133 {
134 string: navigator.userAgent,
135 subString: 'Gecko',
136 identity: 'Mozilla',
137 versionSearch: 'rv'
138 },
139 {
140 // for older Netscapes (4-)
141 string: navigator.userAgent,
142 subString: 'Mozilla',
143 identity: 'Netscape',
144 versionSearch: 'Mozilla'
145 }
146 ],
147 dataOS: [
148 {string: navigator.platform, subString: 'Win', identity: 'Windows'},
149 {string: navigator.platform, subString: 'Mac', identity: 'Mac'},
150 {string: navigator.userAgent, subString: 'iPhone', identity: 'iPhone/iPod'},
151 {string: navigator.platform, subString: 'Linux', identity: 'Linux'}
152 ]
153};
154
155function str_replace(search, replace, subject, count) {
156 // http://kevin.vanzonneveld.net
157 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
158 // + improved by: Gabriel Paderni
159 // + improved by: Philip Peterson
160 // + improved by: Simon Willison (http://simonwillison.net)
161 // + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
162 // + bugfixed by: Anton Ongson
163 // + input by: Onno Marsman
164 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
165 // + tweaked by: Onno Marsman
166 // + input by: Brett Zamir (http://brett-zamir.me)
167 // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
168 // + input by: Oleg Eremeev
169 // + improved by: Brett Zamir (http://brett-zamir.me)
170 // + bugfixed by: Oleg Eremeev
171 // % note 1: The count parameter must be passed as a string in order
172 // % note 1: to find a global variable in which the result will be
173 // given
174 // * example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
175 // * returns 1: 'Kevin.van.Zonneveld'
176 // * example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name},
177 // lars');
178 // * returns 2: 'hemmo, mars'
179 var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0, f = [].concat(search),
180 r = [].concat(replace), s = subject,
181 ra = Object.prototype.toString.call(r) === '[object Array]',
182 sa = Object.prototype.toString.call(s) === '[object Array]';
183 s = [].concat(s);
184 if (count) {
185 this.window[count] = 0;
186 }
187
188 for (i = 0, sl = s.length; i < sl; i++) {
189 if (s[i] === '') {
190 continue;
191 }
192 for (j = 0, fl = f.length; j < fl; j++) {
193 temp = s[i] + '';
194 repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
195 s[i] = (temp).split(f[j]).join(repl);
196 if (count && s[i] !== temp) {
197 this.window[count] += (temp.length - s[i].length) / f[j].length;
198 }
199 }
200 }
201 return sa ? s : s[0];
202}
203
204/**
205 * JavaScript Client Detection
206 * (C) viazenetti GmbH (Christian Ludwig)
207 */
208
209var System = {
210 OS: function() {
211 var unknown = '?';
212
213 // browser
214 var nVer = navigator.appVersion;
215 var nAgt = navigator.userAgent;
216 var browser = navigator.appName;
217 var version = '' + parseFloat(navigator.appVersion);
218 var majorVersion = parseInt(navigator.appVersion, 10);
219 var nameOffset, verOffset, ix;
220
221 // system
222 var os = unknown;
223 var clientStrings = [
224 {s: 'Windows 3.11', r: /Win16/},
225 {s: 'Windows 95', r: /(Windows 95|Win95|Windows_95)/},
226 {s: 'Windows ME', r: /(Win 9x 4.90|Windows ME)/},
227 {s: 'Windows 98', r: /(Windows 98|Win98)/},
228 {s: 'Windows CE', r: /Windows CE/},
229 {s: 'Windows 2000', r: /(Windows NT 5.0|Windows 2000)/},
230 {s: 'Windows XP', r: /(Windows NT 5.1|Windows XP)/},
231 {s: 'Windows Server 2003', r: /Windows NT 5.2/},
232 {s: 'Windows Vista', r: /Windows NT 6.0/},
233 {s: 'Windows 7', r: /(Windows 7|Windows NT 6.1)/},
234 {s: 'Windows 8.1', r: /(Windows 8.1|Windows NT 6.3)/},
235 {s: 'Windows 8', r: /(Windows 8|Windows NT 6.2)/},
236 {s: 'Windows NT 4.0', r: /(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},
237 {s: 'Windows ME', r: /Windows ME/},
238 {s: 'Android', r: /Android/},
239 {s: 'Open BSD', r: /OpenBSD/},
240 {s: 'Sun OS', r: /SunOS/},
241 {s: 'Linux', r: /(Linux|X11)/},
242 {s: 'iOS', r: /(iPhone|iPad|iPod)/},
243 {s: 'Mac OS X', r: /Mac OS X/},
244 {s: 'Mac OS', r: /(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},
245 {s: 'QNX', r: /QNX/},
246 {s: 'UNIX', r: /UNIX/},
247 {s: 'BeOS', r: /BeOS/},
248 {s: 'OS/2', r: /OS\/2/},
249 {
250 s: 'Search Bot',
251 r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/
252 }
253 ];
254 for (var id in clientStrings) {
255 var cs = clientStrings[id];
256 if (cs.r.test(nAgt)) {
257 os = cs.s;
258 break;
259 }
260 }
261
262 var osVersion = 'unknown';
263
264 if (/Windows/.test(os)) {
265 osVersion = /Windows (.*)/.exec(os)[1];
266 os = 'Windows';
267 }
268
269 switch (os) {
270 case 'Mac OS X':
271 osVersion = /Mac OS X (10[\.\_\d]+)/.exec(nAgt)[1];
272 break;
273
274 case 'Android':
275 osVersion = /Android ([\.\_\d]+)/.exec(nAgt)[1];
276 break;
277
278 case 'iOS':
279 osVersion = /OS (\d+)_(\d+)_?(\d+)?/.exec(nVer);
280 osVersion =
281 osVersion[1] + '.' + osVersion[2] + '.' + (osVersion[3] | 0);
282 break;
283 }
284
285 var jscd = {os: os, osVersion: osVersion};
286
287 return (jscd.os + ' ' + jscd.osVersion);
288 }
289};
290
291window.addEventListener('load', _ => {
292 BrowserDetect.init();
293 app.init();
294});