const darkModeDefault = false; // CSS class used to set Dark Mode properties const DARK_MODE_CSS = 'dark-mode'; // LocalStorage key used to store Dark Mode state const DARK_MODE_STORAGE = 'dark-mode'; // CSS id used for Dark Mode icon const DARK_MODE_ICON = "icon-darkmode"; // could be `icon-${DARK_MODE_CSS}`; // CSS id used for Dark Mode button const DARK_MODE_BUTTON = "dark-mode-button"; // could be `button-${DARK_MODE_CSS}`; const darkModeSymbol = ` `; // moon icon const lightModeSymbol = ` `; // sun icon const darkModeToggleText = { 'en': 'Toggle Dark Mode', 'de': 'Dark Mode umschalten', 'fr': 'Activer le mode sombre', 'es': 'Alternar Modo Obscuro', 'hu': 'Sötét mód be/ki', 'it': 'Attiva/Disattiva modalità scura', 'nl': 'Toggle Dark Mode', 'pl': 'Toggle Dark Mode', 'pt': 'Alternar Modo Escuro', 'ru': 'Смена оформления', 'he': 'מצב לילה', 'hi': 'डार्क मोड' }[defaultUserLanguage()] || 'Toggle Dark Mode'; const toggleButton = ``; function isDarkModeSet() { return localStorage.getItem(DARK_MODE_STORAGE) === 'true'; } function getDarkModeIcon() { return ``; } function toggleDarkMode() { document.body.classList.toggle(DARK_MODE_CSS); const setting = (!isDarkModeSet()).toString(); localStorage.setItem(DARK_MODE_STORAGE, setting); } function addDarkModeToggle() { const sidebarToolbar = $('.rcx-sidebar-topbar .rcx-button-group').first(); // wait for the sidebar toolbar to be visible // this will also be false if the toolbar doesn't exist yet if(!sidebarToolbar.is(':visible')) { setTimeout(addDarkModeToggle, 250); return; } var darkModeButton = $(`#${DARK_MODE_BUTTON}`); // do nothing if button is already on the screen if (darkModeButton.is(':visible')) { return; } darkModeButton = $(toggleButton).prependTo(sidebarToolbar); darkModeButton.html(getDarkModeIcon()); darkModeButton.on('click', function() { toggleDarkMode(); darkModeButton.html(getDarkModeIcon()); $(this).blur(); }); } if (darkModeDefault) { if (localStorage.getItem(DARK_MODE_STORAGE) === null) { localStorage.setItem(DARK_MODE_STORAGE, 'true'); } } $(addDarkModeToggle); // Apply dark mode immediately if it's been set previously if(localStorage.getItem(DARK_MODE_STORAGE) === 'true') { document.body.classList.add(DARK_MODE_CSS); }