X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Fjs%2Fbook.js;h=c54fb94e700d9a8e1338f8c9db38ebada169f20e;hb=7948ff31ce0c53b85cccb9c851dbbf36d46f9c0c;hp=ab5e4112e04a28ebf740234609f807e732d59ec9;hpb=95c49ee7d384bef444ee30aad95c7f637bed0e10;p=remoteglot-book diff --git a/www/js/book.js b/www/js/book.js index ab5e411..c54fb94 100644 --- a/www/js/book.js +++ b/www/js/book.js @@ -4,6 +4,20 @@ var board = null; var moves = []; var move_override = 0; +var entity_map = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', +}; + +function escape_html(string) { + return String(string).replace(/[&<>"']/g, function (s) { + return entity_map[s]; + }); +} + var get_game = function() { var game = new Chess(); for (var i = 0; i < move_override; ++i) { @@ -61,7 +75,25 @@ var direction = 1; var show_lines = function(data, game) { var moves = data['moves']; $('#numviewers').text(data['opening']); - $('#rootgame').text(data['root_pgn']); + + if (data['root_game']) { + var text = escape_html(data['root_game']['white']); + if (data['root_game']['white_elo']) { + text += " (" + escape_html(data['root_game']['white_elo']) + ")"; + } + text += " – " + escape_html(data['root_game']['black']); + if (data['root_game']['black_elo']) { + text += " (" + escape_html(data['root_game']['black_elo']) + ")"; + } + text += "  " + escape_html(data['root_game']['result']).replace(/-/, "–") + "
"; + if (data['root_game']['eco']) { + text += "[" + escape_html(data['root_game']['eco']) + "] "; + } + text += "(" + data['root_game']['moves'] + ") "; + text += escape_html(data['root_game']['event']) + "  " + escape_html(data['root_game']['date']); + $('#gamesummary').html(text); + } + var total_num = 0; for (var i = 0; i < moves.length; ++i) { var move = moves[i];