diff options
author | nea <nea@nea.moe> | 2023-03-12 00:25:33 +0100 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-03-12 00:25:33 +0100 |
commit | 56d31408bf14749a211ea87835f99bbb0ec1caf1 (patch) | |
tree | d0dfeb73b4e1ddb8a35ee9c57862889faa4bc908 /index.html | |
parent | 3236ef30b19e5e7a8a0e692b3c780fe5ca0786b1 (diff) | |
download | chess-56d31408bf14749a211ea87835f99bbb0ec1caf1.tar.gz chess-56d31408bf14749a211ea87835f99bbb0ec1caf1.tar.bz2 chess-56d31408bf14749a211ea87835f99bbb0ec1caf1.zip |
Diffstat (limited to 'index.html')
-rw-r--r-- | index.html | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -149,7 +149,7 @@ <div id="choice" class=""> </div> <div id="admodal"> - <div><a href="#" onclick="adinfoClose()">x</a></div> + <div><a href="javascript:void(0)" onclick="adinfoClose()">x</a></div> <ul> <li>Created by Linnea Gräf</li> <li><a href="https://git.nea.moe/nea/chess">Source</a></li> @@ -162,6 +162,8 @@ </div> <script> + const admodal = document.getElementById("admodal") + function adinfo() { admodal.classList.add('visible'); } @@ -175,6 +177,7 @@ constructor(elem) { this.socket = new WebSocket(`${location.protocol.includes('s') ? 'wss' : 'ws'}://${window.location.host}/socket`) this.ended = false + this.pgn = null this.boardState = {} this.lastMove = '' window.addEventListener('beforeunload', () => { @@ -198,11 +201,11 @@ this.legalMoves = [] this.socket.addEventListener('message', ev => { const message = JSON.parse(ev.data) - console.log(message) this.playerColor = message.player_color || this.playerColor this.boardState = parseFEN(message.board) this.lastMove = message.lastmove || '' this.ended ||= message.event === 'game_over' + this.pgn = message.pgn || this.pgn this.result = message.result this.legalMoves = message.legalmoves || [] this.awaitResync = false @@ -267,7 +270,7 @@ let uci = fromField + toField this.preTransformationMove = uci if (((toField[1] === '8' && this.playerColor === 'white') - || (toField[2] === '1' && this.playerColor === 'black')) + || (toField[1] === '1' && this.playerColor === 'black')) && (this.boardState[fromField].toUpperCase() === 'P')) { this.choiceButton.classList.add('selectingmove') } else { @@ -300,6 +303,10 @@ <p><a href="https://youtu.be/yIRT6xRQkf8"><b>${this.result}</b></a></p> ` } + if(this.pgn) { + this.turnIndicator.innerHTML += ` + <p><a href="data:application/vnd.chess-pgn;base64,${btoa(this.pgn)}" download="game.pgn" >Download PGN</a></p>` + } for (let field in this.fields) { const fieldDOM = this.fields[field] fieldDOM.innerHTML = "" |