Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python
1.4 KB
Raw Blame
{#- The theme saved with the user's account (D#419). Include first in <head>,
    before includes/theme_bootstrap.html and any script that reads the theme.
    A saved value replaces this browser's copy in localStorage, which every
    page reads. Nothing is saved until the user changes the mode or scheme
    (window.speakrSaveTheme), so until then each browser keeps its own. -#}
{% if account_theme %}
<script>
  (function () {
    var saved = {{ account_theme|tojson }};
    try {
      if (saved.dark !== null) localStorage.setItem('darkMode', saved.dark ? 'true' : 'false');
      if (saved.scheme) localStorage.setItem('colorScheme', saved.scheme);
    } catch (e) {}
    var pending = {}, timer = null;
    window.speakrSaveTheme = function (key) {
      try {
        if (key === 'darkMode') pending.dark_mode = localStorage.getItem('darkMode') === 'true';
        if (key === 'colorScheme') pending.color_scheme = localStorage.getItem('colorScheme') || 'blue';
      } catch (e) { return; }
      clearTimeout(timer);
      timer = setTimeout(function () {
        var body = pending; pending = {};
        fetch('/api/user/preferences', {
          method: 'POST', credentials: 'same-origin',
          headers: {'Content-Type': 'application/json', 'X-CSRFToken': {{ csrf_token()|tojson }}},
          body: JSON.stringify(body)
        }).catch(function () {});
      }, 300);
    };
  })();
</script>
{% endif %}