function set_theme(name) { var themes = { default: { bootstrap: '/static/css/bootstrap.flatly.min.css', pygments: '/highlight_stylesheet', pastepy: '/static/css/paste.css', }, dark: { bootstrap: '/static/css/bootstrap.darkly.min.css', pygments: '/highlight_stylesheet/paraiso-dark', pastepy: '/static/css/paste.dark.css', } }; var bootstrap_css = document.getElementById('bootstrap-css'); var pygments_css = document.getElementById('pygments-css'); var pastepy_css = document.getElementById('pastepy-css'); var theme = themes[name]; bootstrap_css.href = theme.bootstrap; if (pygments_css) { pygments_css.href = theme.pygments; } if (pastepy_css) { pastepy_css.href = theme.pastepy; } var theme = localStorage.setItem('theme', name); } function switch_theme(event) { if (event && event.type !== 'load') { event.preventDefault(); } var bootstrap_css = document.getElementById('bootstrap-css'); var pygments_css = document.getElementById('pygments-css'); var theme = localStorage.getItem('theme'); set_theme(theme === 'dark' ? 'default' : 'dark'); } window.addEventListener('load', function() { var theme = localStorage.getItem('theme'); if (theme) { set_theme(theme); } });