]> git.sesse.net Git - remoteglot/blobdiff - www/js/remoteglot.js
Add a very crude function for manual overrides.
[remoteglot] / www / js / remoteglot.js
index 1218dd3cbe9ae719b4409374564c1fb37510db6f..51a470f502c59af3788255da7c719bab1694b336 100644 (file)
@@ -125,6 +125,9 @@ let reverse_dragging_from = null;
 /** @type {?number} @private */
 let unique = null;
 
+/** @type {?string} @private */
+let admin_password = null;
+
 /** @type {boolean} @private */
 let enable_sound = false;
 
@@ -1114,15 +1117,6 @@ function update_board() {
                headline = 'Analysis';
        }
 
-       // Credits, where applicable. Note that we don't want the footer to change a lot
-       // when e.g. viewing history, so if any of these changed during the game,
-       // use the current one still.
-       if (current_data['using_lomonosov']) {
-               document.getElementById("lomonosov").style.display = null;
-       } else {
-               document.getElementById("lomonosov").style.display = 'none';
-       }
-
        // Credits: The engine name/version.
        if (current_data['engine'] && current_data['engine']['name'] !== null) {
                document.getElementById("engineid").textContent = current_data['engine']['name'];
@@ -1269,8 +1263,6 @@ function update_board() {
        // The search stats.
        if (data['searchstats']) {
                document.getElementById("searchstats").textContent = data['searchstats'];
-       } else if (data['tablebase'] == 1) {
-               document.getElementById("searchstats").textContent = "Tablebase result";
        } else if (data['nodes'] && data['nps'] && data['depth']) {
                let stats = thousands(data['nodes']) + ' nodes, ' + thousands(data['nps']) + ' nodes/sec, depth ' + data['depth'] + ' ply';
                if (data['seldepth']) {
@@ -1288,6 +1280,9 @@ function update_board() {
        } else {
                document.getElementById("searchstats").textContent = "";
        }
+       if (admin_password !== null) {
+               document.getElementById("searchstats").innerHTML += " | <span style=\"color: red;\">ADMIN MODE (if password is right)</span>";
+       }
 
        // Update the board itself.
        base_fen = data['position']['fen'];
@@ -1903,7 +1898,7 @@ function update_move_highlight() {
                        document.getElementById("pvtitle").textContent = "Exploring:";
                        current_display_line.start_display_move_num = 0;
                        display_lines.push(current_display_line);
-                       document.getElementById("pv").append(print_pv(display_lines.length - 1, null));  // FIXME
+                       document.getElementById("pv").replaceChildren(print_pv(display_lines.length - 1, null));  // FIXME
                        display_line_num = display_lines.length - 1;
 
                        // Clear out the PV, so it's not selected by anything later.
@@ -1987,7 +1982,8 @@ function update_displayed_line() {
 function set_board_position(new_fen) {
        board_is_animating = true;
        let old_fen = board.fen();
-       board.position(new_fen);
+       let animate = old_fen !== '8/8/8/8/8/8/8/';
+       board.position(new_fen, animate);
        if (board.fen() === old_fen) {
                board_is_animating = false;
        }
@@ -2224,6 +2220,18 @@ function onSnapEnd(source, target) {
                promotion: 'q' // NOTE: always promote to a queen for example simplicity
        });
 
+       if (admin_password !== null) {
+               let url = '/manual-override.pl';
+               url += '?fen=' + encodeURIComponent(display_fen);
+               url += '&history=' + encodeURIComponent(JSON.stringify(current_analysis_data['position']['history']));
+               url += '&move=' + encodeURIComponent(move.san);
+               url += '&player_w=' + encodeURIComponent(current_analysis_data['position']['player_w']);
+               url += '&player_b=' + encodeURIComponent(current_analysis_data['position']['player_b']);
+               url += '&password=' + encodeURIComponent(admin_password);
+               fetch(url);
+               return;
+       }
+
        // Move ahead on the line we're on -- this includes history if we've
        // gone backwards.
        if (current_display_line &&
@@ -2469,6 +2477,11 @@ function init() {
                set_sound(false);
        }
 
+       let admin_match = window.location.href.match(/\?password=([a-zA-Z0-9_-]+)/);
+       if (admin_match !== null) {
+               admin_password = admin_match[1];
+       }
+
        // Create board.
        board = new window.ChessBoard('board', {
                onMoveEnd: function() { board_is_animating = false; },
@@ -2482,6 +2495,11 @@ function init() {
        document.getElementById("board").addEventListener('mousedown', mousedownSquare);
        document.getElementById("board").addEventListener('mouseup', mouseupSquare);
 
+       if (window['inline_json']) {
+               let j = window['inline_json'];
+               process_update_response(j['data'], { 'get': (h) => j['headers'][h] });
+               delete window['inline_json'];
+       }
        request_update();
        window.addEventListener('resize', function() {
                board.resize();