]> git.sesse.net Git - remoteglot/blobdiff - www/js/remoteglot.js
Add a very crude function for manual overrides.
[remoteglot] / www / js / remoteglot.js
index 54fc90b46afc5d5e818ddb87bd9a7cfaa41b33b6..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;
 
@@ -1277,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'];
@@ -2214,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 &&
@@ -2459,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; },