]> git.sesse.net Git - remoteglot/blobdiff - www/js/remoteglot.js
Use innerHTML slightly less (it is costly).
[remoteglot] / www / js / remoteglot.js
index c96335feb62baeacd88435fcc65c91c6375920b2..f4581cf72644032c0b4a6515e1320c7926648222 100644 (file)
@@ -897,8 +897,11 @@ let update_refutation_lines = function() {
                        continue;
                }
 
-               let move = "<a class=\"move\" href=\"javascript:show_line(" + display_lines.length + ", " + 0 + ");\">" + line['move'] + "</a>";
-               move_td.innerHTML = move;
+               let move_link = document.createElement("a");
+               move_link.classList.add("move");
+               move_link.setAttribute("href", "javascript:show_line(" + display_lines.length + ", 0)");
+               move_link.textContent = line['move'];
+               move_td.appendChild(move_link);
 
                let score_td = document.createElement("td");
                tr.appendChild(score_td);
@@ -1395,7 +1398,10 @@ let update_sparkline = function(data) {
                                scores.push(last_score);
                        }
                        if (data['score']) {
-                               scores.push(compute_plot_score(data['score']));
+                               let score = compute_plot_score(data['score']);
+                               scores.push(score);
+                               if (score < min_score) min_score = score;
+                               if (score > max_score) max_score = score;
                        }
 
                        const h = scorespark.getBoundingClientRect().height;
@@ -1441,7 +1447,7 @@ let update_sparkline = function(data) {
                                rect.addEventListener('mouseenter', (e) => draw_hover(e, hlcolor, tooltip));
                                rect.addEventListener('mousemove', (e) => draw_hover(e, hlcolor, tooltip));
                                rect.addEventListener('mouseleave', (e) => hide_hover(e, color));
-                               rect.addEventListener('click', (e) => show_line(0, i + first_move_num - 1));
+                               rect.addEventListener('click', (e) => { hide_hover(e, color); show_line(0, i + first_move_num - 1) });
                                scorespark.appendChild(rect);
                        }
                }
@@ -2175,6 +2181,8 @@ let onSnapEnd = function(source, target) {
                promotion: 'q' // NOTE: always promote to a queen for example simplicity
        });
 
+       // Move ahead on the line we're on -- this includes history if we've
+       // gone backwards.
        if (current_display_line &&
            current_display_move < current_display_line.pv.length - 1 &&
            current_display_line.pv[current_display_move + 1] === move.san) {
@@ -2184,15 +2192,16 @@ let onSnapEnd = function(source, target) {
 
        // Walk down the displayed lines until we find one that starts with
        // this move, then select that. Note that this gives us a good priority
-       // order (history first, then PV, then multi-PV lines).
-       for (let i = 0; i < display_lines.length; ++i) {
+       // order (PV, then multi-PV lines; history was already dealt with above,
+       // as it's the only line that originates backwards).
+       for (let i = 1; i < display_lines.length; ++i) {
                if (i == 1 && current_display_line) {
                        // Do not choose PV if not on it.
                        continue;
                }
                let line = display_lines[i];
                if (line.pv[line.start_display_move_num] === move.san) {
-                       show_line(i, 0);
+                       show_line(i, line.start_display_move_num);
                        return;
                }
        }