Path: blob/main/website/themes/beastie/assets/js/theme-chooser.js
18096 views
/*1BSD 2-Clause License23Copyright (c) 1994-2026, The FreeBSD Documentation Project4Copyright (c) 2026, Vladlen Popolitov5All rights reserved.67Redistribution and use in source and binary forms, with or without8modification, are permitted provided that the following conditions are met:9101. Redistributions of source code must retain the above copyright notice, this11list of conditions and the following disclaimer.12132. Redistributions in binary form must reproduce the above copyright notice,14this list of conditions and the following disclaimer in the documentation15and/or other materials provided with the distribution.1617THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"18AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE21FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR23SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER24CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,25OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27*/2829// FreeBSD light/dark theme persists30;(function() {31const toggle = document.getElementById('theme-switch');32if (!toggle) return;3334// restore saved state35const saved = localStorage.getItem('theme-preference');36if (saved === 'dark') {37toggle.checked = true;38} else if (saved === 'light') {39toggle.checked = false;40}41// if state was no saved - use current state (CSS uses prefers-color-scheme)42// save state, when theme switched to or from dark43toggle.addEventListener('change', function() {44localStorage.setItem('theme-preference', this.checked ? 'dark' : 'light');45});46})();474849