diff --git a/index.html b/index.html index 9ebcb1a..d15af05 100644 --- a/index.html +++ b/index.html @@ -133,7 +133,7 @@ >

- +

         
         
diff --git a/main.js b/main.js index 3a123d9..3ae45c0 100644 --- a/main.js +++ b/main.js @@ -642,8 +642,12 @@ function show_game_over() { game_over.innerText = `GAME OVER; player was ${todays_player.name}`; console.log("GAME OVER"); } +function copy_stats_to_clipboard() { + navigator.clipboard.writeText(document.getElementById("stats").innerText); +} function show_win() { wins++; + in_game_over = true; let win_count = document.getElementById("win-count"); win_count.style.display = "block"; win_count.innerText = `You have won ${wins} time${wins == 1 ? "" : "s"} without refreshing${wins_exclamation_marks()}`; @@ -662,7 +666,7 @@ ${history}`; stats.innerText = stats_text; let copy_stats = document.getElementById("copy-stats"); copy_stats.style.display = "block"; - copy_stats.addEventListener("click", _ => navigator.clipboard.writeText(stats_text)); + copy_stats.addEventListener("click", _ => copy_stats_to_clipboard()); let play_again = document.getElementById("play-again"); play_again.style.display = "block"; play_again.addEventListener("click", _ => reset()); @@ -708,6 +712,7 @@ function wins_exclamation_marks() { let wins_divided_by_ten = Math.floor(wins / 10); return wins_divided_by_ten > 0 ? "!".repeat(wins_divided_by_ten) : "."; } +var in_game_over = false; // ERROR: ! // INELEGANT // "HACK"! @@ -715,6 +720,7 @@ function reset() { let play_again = document.getElementById("play-again"); play_again.style.display = "none"; play_again.onclick = _ => console.log("you can't play again again sorry :]"); + in_game_over = false; todays_player = get_todays_player(); game = new Chess(); board.fen = game.fen(); @@ -777,5 +783,13 @@ window.addEventListener("DOMContentLoaded", () => { document .getElementById("finish") .addEventListener("click", _ => show_game_over()); + document.addEventListener("keypress", e => { + if (e.key == "r" && in_game_over) { + reset(); + } + else if (e.key == "c" && in_game_over) { + copy_stats_to_clipboard(); + } + }); append_players_to(document.getElementById("players")); }); diff --git a/main.ts b/main.ts index 236d580..1f4cc15 100644 --- a/main.ts +++ b/main.ts @@ -777,8 +777,12 @@ function show_game_over() { console.log("GAME OVER"); } +function copy_stats_to_clipboard() { + navigator.clipboard.writeText(document.getElementById("stats").innerText); +} function show_win() { wins++; + in_game_over = true; let win_count = document.getElementById("win-count"); win_count.style.display = "block"; win_count.innerText = `You have won ${wins} time${ @@ -802,9 +806,7 @@ ${history}`; let copy_stats = document.getElementById("copy-stats"); copy_stats.style.display = "block"; - copy_stats.addEventListener("click", _ => - navigator.clipboard.writeText(stats_text) - ); + copy_stats.addEventListener("click", _ => copy_stats_to_clipboard()); let play_again = document.getElementById("play-again"); play_again.style.display = "block"; @@ -862,6 +864,7 @@ function wins_exclamation_marks() { return wins_divided_by_ten > 0 ? "!".repeat(wins_divided_by_ten) : "."; } +var in_game_over = false; // ERROR: ! // INELEGANT // "HACK"! @@ -871,6 +874,8 @@ function reset() { play_again.onclick = _ => console.log("you can't play again again sorry :]"); + in_game_over = false; + todays_player = get_todays_player(); game = new Chess(); board.fen = game.fen(); @@ -953,5 +958,13 @@ window.addEventListener("DOMContentLoaded", () => { .getElementById("finish") .addEventListener("click", _ => show_game_over()); + document.addEventListener("keypress", e => { + if (e.key == "r" && in_game_over) { + reset(); + } else if (e.key == "c" && in_game_over) { + copy_stats_to_clipboard(); + } + }); + append_players_to(document.getElementById("players")); });