const darkModeDefault = false;
const darkModeSymbol = ``; // moon icon
const lightModeSymbol = ``; // sun icon
const darkModeToggleText = {
'en': 'Toggle Dark Mode',
'de': 'Dark Mode umschalten',
'fr': 'Toggle Dark Mode',
'es': 'Toggle Dark Mode',
'it': 'Toggle Dark Mode',
'nl': 'Toggle Dark Mode',
'pl': 'Toggle Dark Mode',
'pt': 'Toggle Dark Mode',
'ru': 'Смена оформления'
}[defaultUserLanguage()] || 'Toggle Dark Mode';
const toggleButton = ``;
function isDarkModeSet() {
return localStorage.getItem('dark-mode') === 'true';
}
function getDarkModeIcon() {
return ``;
}
function toggleDarkMode() {
document.body.classList.toggle('dark-mode');
const setting = (!isDarkModeSet()).toString();
localStorage.setItem('dark-mode', setting);
}
function addDarkModeToggle() {
const sidebarToolbar = $('.sidebar__toolbar');
// 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 = $(`.js-button[aria-label="${darkModeToggleText}"]`);
// 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") === null) {
localStorage.setItem('dark-mode', 'true');
}
}
$(addDarkModeToggle);
// Apply dark mode immediately if it's been set previously
if(localStorage.getItem('dark-mode') === 'true') {
document.body.classList.add('dark-mode');
}