]> git.sesse.net Git - remoteglot/blobdiff - www/js/remoteglot.js
Explicitly prefer Opus over MP3.
[remoteglot] / www / js / remoteglot.js
index cd2ffa5ccb04c548aa706cf05be73f6ad2c7c4d9..3574453fa411b31bdaa926650437cd26a16cde98 100644 (file)
@@ -145,7 +145,7 @@ var possibly_play_sound = function(old_data, new_data) {
                return;
        }
        var ding = document.getElementById('ding');
-       if (ding && ding.play !== undefined) {
+       if (ding && ding.play) {
                if (old_data['position'] && old_data['position']['fen'] &&
                    new_data['position'] && new_data['position']['fen'] &&
                    (old_data['position']['fen'] !== new_data['position']['fen'] ||
@@ -652,7 +652,7 @@ var update_board = function(current_data, display_data) {
        // The <title> contains a very brief headline.
        var title_elems = [];
        if (data['short_score'] !== undefined && data['short_score'] !== null) {
-               title_elems.push(data['short_score']);
+               title_elems.push(data['short_score'].replace(/^ /, ""));
        }
        if (last_move !== null) {
                title_elems.push(last_move);
@@ -829,6 +829,9 @@ var format_move_with_number = function(move, move_num, white_to_play) {
  */
 var resort_refutation_lines = function(sort_by_score) {
        sort_refutation_lines_by_score = sort_by_score;
+       if (supports_html5_storage()) {
+               localStorage['sort_refutation_lines_by_score'] = sort_by_score ? 1 : 0;
+       }
        update_refutation_lines();
 }
 window['resort_refutation_lines'] = resort_refutation_lines;
@@ -960,16 +963,38 @@ var set_sound = function(param_enable_sound) {
        if (enable_sound) {
                $("#soundon").html("<strong>On</strong>");
                $("#soundoff").html("<a href=\"javascript:set_sound(false)\">Off</a>");
+
+               // Seemingly at least Firefox prefers MP3 over Opus; tell it otherwise,
+               // and also preload the file since the user has selected audio.
+               var ding = document.getElementById('ding');
+               if (ding && ding.canPlayType && ding.canPlayType('audio/ogg; codecs="opus"') === 'probably') {
+                       ding.src = 'ding.opus';
+                       ding.load();
+               }
        } else {
                $("#soundon").html("<a href=\"javascript:set_sound(true)\">On</a>");
                $("#soundoff").html("<strong>Off</strong>");
        }
+       if (supports_html5_storage()) {
+               localStorage['enable_sound'] = enable_sound ? 1 : 0;
+       }
 }
 window['set_sound'] = set_sound;
 
 var init = function() {
        unique = get_unique();
-       set_sound(false);
+
+       // Load settings from HTML5 local storage if available.
+       if (supports_html5_storage() && localStorage['enable_sound']) {
+               set_sound(parseInt(localStorage['enable_sound']));
+       } else {
+               set_sound(false);
+       }
+       if (supports_html5_storage() && localStorage['sort_refutation_lines_by_score']) {
+               sort_refutation_lines_by_score = parseInt(localStorage['sort_refutation_lines_by_score']);
+       } else {
+               sort_refutation_lines_by_score = true;
+       }
 
        // Create board.
        board = new window.ChessBoard('board', 'start');