@@ -9,27 +9,14 @@ menuTrigger.onclick = function() {
99}
1010
1111// https://stackoverflow.com/a/19176790
12- function IsOldWindows ( ) {
13- // var os_name = "Unknown";
14- // if (window.navigator.userAgent.indexOf("Windows NT 10.0")!= -1) os_name="Windows 10";
15- if ( window . navigator . userAgent . indexOf ( "Windows NT 6." ) != - 1 ) return true ;
16- // if (window.navigator.userAgent.indexOf("Windows NT 6.2") != -1) os_name="Windows 8";
17- // if (window.navigator.userAgent.indexOf("Windows NT 6.1") != -1) os_name="Windows 7";
18- // if (window.navigator.userAgent.indexOf("Windows NT 6.0") != -1) os_name="Windows Vista";
19- if ( window . navigator . userAgent . indexOf ( "Windows NT 5." ) != - 1 ) return true ;
20- // if (window.navigator.userAgent.indexOf("Windows NT 5.0") != -1) os_name="Windows 2000";
21- // if (window.navigator.userAgent.indexOf("Mac") != -1) os_name="Mac/iOS";
22- // if (window.navigator.userAgent.indexOf("X11") != -1) os_name="UNIX";
23- // if (window.navigator.userAgent.indexOf("Linux") != -1) os_name="Linux";
24- return false ;
12+ function isOldWindows ( ) {
13+ return / W i n d o w s N T [ 5 - 6 ] \. / . test ( navigator . userAgent ) ;
2514}
2615
27- function GetFastAndSlow ( json , old_windows ) {
16+ function getFastAndSlow ( json , old_windows ) {
2817 let fast = { } ;
2918 let slow = { } ;
30- // console.log(json.files);
3119 for ( let obj of json . files ) {
32- // console.log(obj);
3320 if ( obj . tags && obj . tags . includes ( ( old_windows ? 'lt_' : '' ) + 'win10_fast' ) ) {
3421 fast = obj ;
3522 }
@@ -40,25 +27,39 @@ function GetFastAndSlow(json, old_windows) {
4027 return [ fast , slow ] ;
4128}
4229
43- const windows_table = document . getElementById ( 'windows-table' ) ;
44- if ( windows_table ) {
30+ const baseDownloadLink = "https://github.com/official-stockfish/Stockfish/releases/latest/download/" ;
31+
32+ const windowsTable = document . getElementById ( 'windows-table' ) ;
33+ if ( windowsTable ) {
4534 fetch ( '/windows.json?a' ) . then ( response => response . json ( ) ) . then ( data => {
46- // console.log(data);
47- const fast_and_slow = GetFastAndSlow ( data , IsOldWindows ( ) ) ;
48- // console.log(fast_and_slow);
49- windows_table . querySelector ( '.fast' ) . href = fast_and_slow [ 0 ] . file ;
50- windows_table . querySelector ( '.fast span' ) . textContent = fast_and_slow [ 0 ] . arch ;
51- windows_table . querySelector ( '.compat' ) . href = fast_and_slow [ 1 ] . file ;
52- windows_table . querySelector ( '.compat span' ) . textContent = fast_and_slow [ 1 ] . arch ;
35+ const fast_and_slow = getFastAndSlow ( data , isOldWindows ( ) ) ;
36+ windowsTable . querySelector ( '.fast' ) . href = baseDownloadLink + fast_and_slow [ 0 ] . file ;
37+ windowsTable . querySelector ( '.fast span' ) . textContent = fast_and_slow [ 0 ] . arch ;
38+ windowsTable . querySelector ( '.compat' ) . href = baseDownloadLink + fast_and_slow [ 1 ] . file ;
39+ windowsTable . querySelector ( '.compat span' ) . textContent = fast_and_slow [ 1 ] . arch ;
5340 } )
5441}
5542
56- const linux_table = document . getElementById ( 'linux-table' ) ;
57- if ( linux_table ) {
43+ const linuxTable = document . getElementById ( 'linux-table' ) ;
44+ if ( linuxTable ) {
5845 fetch ( '/linux.json?a' ) . then ( response => response . json ( ) ) . then ( data => {
59- linux_table . querySelector ( '.fast' ) . href = data . files [ 0 ] . file ;
60- linux_table . querySelector ( '.fast span' ) . textContent = data . files [ 0 ] . arch ;
61- linux_table . querySelector ( '.compat' ) . href = data . files [ 1 ] . file ;
62- linux_table . querySelector ( '.compat span' ) . textContent = data . files [ 1 ] . arch ;
46+ const fastFile = data . files . find ( file => file . tags && file . tags . includes ( 'fast' ) ) ;
47+ const compatFile = data . files . find ( file => file . tags && file . tags . includes ( 'compat' ) ) ;
48+ linuxTable . querySelector ( '.fast' ) . href = fastFile ? baseDownloadLink + fastFile . file : '' ;
49+ linuxTable . querySelector ( '.fast span' ) . textContent = fastFile ? fastFile . arch : '' ;
50+ linuxTable . querySelector ( '.compat' ) . href = compatFile ? baseDownloadLink + compatFile . file : '' ;
51+ linuxTable . querySelector ( '.compat span' ) . textContent = compatFile ? compatFile . arch : '' ;
52+ } )
53+ }
54+
55+ const armTable = document . getElementById ( 'arm-table' ) ;
56+ if ( armTable ) {
57+ fetch ( '/arm.json?a' ) . then ( response => response . json ( ) ) . then ( data => {
58+ const fastFile = data . files . find ( file => file . tags && file . tags . includes ( 'fast' ) ) ;
59+ const compatFile = data . files . find ( file => file . tags && file . tags . includes ( 'compat' ) ) ;
60+ armTable . querySelector ( '.fast' ) . href = fastFile ? baseDownloadLink + fastFile . file : '' ;
61+ armTable . querySelector ( '.fast span' ) . textContent = fastFile ? fastFile . arch : '' ;
62+ armTable . querySelector ( '.compat' ) . href = compatFile ? baseDownloadLink + compatFile . file : '' ;
63+ armTable . querySelector ( '.compat span' ) . textContent = compatFile ? compatFile . arch : '' ;
6364 } )
6465}
0 commit comments