blob: ecc57d155c1e5499d69b12afd4f1259e1c5687f4 [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
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) {
43 if (os == 'linux' || os == 'mac' || os == 'cros') return os;
44 if (os == 'win_7_or_less' || os == 'win_latest') return 'win64';
45 return undefined;
46}
47
48function prettifyOS(os) {
49 if (os == 'linux') return 'Linux';
50 if (os == 'mac') return 'Mac';
51 if (os == 'cros') return 'Chrome OS';
52 if (os == 'win_7_or_less' || os == 'win_latest') return 'Windows';
53 return undefined;
54}
55
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +020056var app = {
57 init: function() {
Adrià Vilanova Martínez7fe3cf22022-04-04 23:43:23 +020058 let promises = [];
59 promises.push(fetch('https://omahaproxy.appspot.com/all.json')
60 .then(res => res.json()));
61 promises.push(detectOS());
62 promises.push(detectCrVersion());
63
64 Promise.all(promises)
65 .then(responses => {
66 const [chromeVersions, os, version] = responses;
67 if (!version) {
68 document.getElementById('version').textContent =
69 'No hemos podido determinar tu versión.';
70 document.getElementById('updated').textContent =
71 'Es posible que no estés usando Chrome o que la página no funcione correctamente.';
72 return;
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +020073 }
Adrià Vilanova Martínez7fe3cf22022-04-04 23:43:23 +020074
75 let majorVersion = version?.split?.('.')?.[0];
76 let omahaOS = convert2OmahaOS(os);
77 let matches = chromeVersions.filter(function(val, index, array) {
78 return val.os === omahaOS;
79 });
80 var actualChrome =
81 matches?.[0]?.versions?.filter?.(function(val, index, array) {
82 return val.channel === 'stable';
83 });
84 actualVersion = actualChrome?.[0]?.version?.split?.('.')?.[0];
85 if (majorVersion < actualVersion) {
86 document.getElementById('updated').innerHTML =
87 '¡Oh, no! Google Chrome ' +
88 '<a href=\'https://support.google.com/chrome/answer/95414\'>no está actualizado</a>.';
89 } else if (majorVersion > actualVersion) {
90 document.getElementById('updated').innerHTML =
91 'No estás usando el canal estable de Chrome. Ve con cuidado ;-)';
92 } else if (version != actualChrome[0].version) {
93 document.getElementById('updated').innerHTML =
94 'Oops, Google Chrome ' +
95 '<a href=\'https://support.google.com/chrome/answer/95414\'>no está actualizado</a>.';
96 } else {
97 document.getElementById('updated').innerHTML =
98 'Chrome está actualizado';
99 }
100 let prettyOS = prettifyOS(os);
101 document.getElementById('version').textContent = 'Usas la versión ' +
102 version + ' de Chrome' + (prettyOS ? ' en ' + prettyOS : '');
103 })
104 .catch(err => {
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +0200105 document.getElementById('version').textContent =
Adrià Vilanova Martínez7fe3cf22022-04-04 23:43:23 +0200106 'Ha ocurrido un error inesperado.';
107 document.getElementById('updated').textContent =
108 'Error: ' + err + '.';
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +0200109 });
110 }
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +0200111};
112
113window.addEventListener('load', _ => {
Adrià Vilanova Martínez849f9dd2021-06-25 20:40:10 +0200114 app.init();
115});