blob: 977e86557a77e6fb42e219d15278b74960cc940f [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
Adrià Vilanova Martínez182a82d2022-05-03 23:13:41 +02004Copyright (c) 2022 Adrià Vilanova Martínez
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +02005
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
Adrià Vilanova Martínez7fe3cf22022-04-04 23:43:23 +020026function detectCrVersion() {
27 if (!navigator?.userAgentData)
28 return Promise.resolve(
29 window.navigator.appVersion.match(/Chrome\/(.*?) /)?.[1]);
30
31 return navigator.userAgentData.getHighEntropyValues(['fullVersionList'])
32 .then(res => {
33 let brands = res?.fullVersionList ?? [];
34 for (const b of brands)
35 if (b?.brand == 'Chromium' || b?.brand == 'Google Chrome')
36 return b?.version;
37
38 return undefined;
39 });
40}
41
42function convert2OmahaOS(os) {
Adrià Vilanova Martínez182a82d2022-05-03 23:13:41 +020043 if (os == 'linux' || os == 'mac' || os == 'cros' || os == 'android')
44 return os;
Adrià Vilanova Martínez7fe3cf22022-04-04 23:43:23 +020045 if (os == 'win_7_or_less' || os == 'win_latest') return 'win64';
46 return undefined;
47}
48
49function prettifyOS(os) {
50 if (os == 'linux') return 'Linux';
51 if (os == 'mac') return 'Mac';
52 if (os == 'cros') return 'Chrome OS';
53 if (os == 'win_7_or_less' || os == 'win_latest') return 'Windows';
Adrià Vilanova Martínez182a82d2022-05-03 23:13:41 +020054 if (os == 'android') return 'Android';
Adrià Vilanova Martínez7fe3cf22022-04-04 23:43:23 +020055 return undefined;
56}
57
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +020058var app = {
59 init: function() {
Adrià Vilanova Martínez7fe3cf22022-04-04 23:43:23 +020060 let promises = [];
61 promises.push(fetch('https://omahaproxy.appspot.com/all.json')
62 .then(res => res.json()));
63 promises.push(detectOS());
64 promises.push(detectCrVersion());
65
66 Promise.all(promises)
67 .then(responses => {
68 const [chromeVersions, os, version] = responses;
69 if (!version) {
70 document.getElementById('version').textContent =
71 'No hemos podido determinar tu versión.';
72 document.getElementById('updated').textContent =
73 'Es posible que no estés usando Chrome o que la página no funcione correctamente.';
74 return;
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +020075 }
Adrià Vilanova Martínez7fe3cf22022-04-04 23:43:23 +020076
77 let majorVersion = version?.split?.('.')?.[0];
78 let omahaOS = convert2OmahaOS(os);
79 let matches = chromeVersions.filter(function(val, index, array) {
80 return val.os === omahaOS;
81 });
82 var actualChrome =
83 matches?.[0]?.versions?.filter?.(function(val, index, array) {
84 return val.channel === 'stable';
Adrià Vilanova Martínez182a82d2022-05-03 23:13:41 +020085 }) ??
86 [];
Adrià Vilanova Martínez7fe3cf22022-04-04 23:43:23 +020087 actualVersion = actualChrome?.[0]?.version?.split?.('.')?.[0];
Adrià Vilanova Martínez182a82d2022-05-03 23:13:41 +020088 if (actualVersion === undefined) {
89 document.getElementById('updated').innerHTML = '';
90 } else if (majorVersion < actualVersion) {
Adrià Vilanova Martínez7fe3cf22022-04-04 23:43:23 +020091 document.getElementById('updated').innerHTML =
92 '¡Oh, no! Google Chrome ' +
93 '<a href=\'https://support.google.com/chrome/answer/95414\'>no está actualizado</a>.';
94 } else if (majorVersion > actualVersion) {
95 document.getElementById('updated').innerHTML =
96 'No estás usando el canal estable de Chrome. Ve con cuidado ;-)';
97 } else if (version != actualChrome[0].version) {
98 document.getElementById('updated').innerHTML =
99 'Oops, Google Chrome ' +
100 '<a href=\'https://support.google.com/chrome/answer/95414\'>no está actualizado</a>.';
101 } else {
102 document.getElementById('updated').innerHTML =
103 'Chrome está actualizado';
104 }
105 let prettyOS = prettifyOS(os);
106 document.getElementById('version').textContent = 'Usas la versión ' +
107 version + ' de Chrome' + (prettyOS ? ' en ' + prettyOS : '');
108 })
109 .catch(err => {
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +0200110 document.getElementById('version').textContent =
Adrià Vilanova Martínez7fe3cf22022-04-04 23:43:23 +0200111 'Ha ocurrido un error inesperado.';
112 document.getElementById('updated').textContent =
113 'Error: ' + err + '.';
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +0200114 });
115 }
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +0200116};
117
118window.addEventListener('load', _ => {
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +0200119 app.init();
120});