gobyexample/templates/footer.tmpl
2022-12-24 20:01:48 +01:00

55 lines
2.2 KiB
Cheetah

{{define "footer"}}
<p class="footer">
<script>
window.onload = function() {
function styleAllTags(tag, style, value){
document.querySelectorAll(tag).forEach((tag) => {
tag.style[style] = value
})
}
var themeButton = document.getElementById('theme-button');
var body = document.getElementsByTagName('body')[0];
var lightText = "#ffffffeb";
var darkText = "#252519";
var lightBackground = "white";
var darkBackground = "#1a202c";
var lightCodeBackground = "#f0f0f0";
var darkCodeBackground = "#333333";
function activateTheme(theme) {
if (theme === 'dark') {
body.style.color = lightText;
body.style.backgroundColor = darkBackground;
styleAllTags('a', 'color', lightText)
styleAllTags('td.code', 'background', darkCodeBackground);
styleAllTags('td.code.empty', 'background', darkBackground)
} else {
body.style.color = darkText;
body.style.backgroundColor = lightBackground;
styleAllTags('a', 'color', darkText)
styleAllTags('td.code', 'background', lightCodeBackground)
styleAllTags('td.code.empty', 'background', lightBackground)
}
localStorage.setItem('theme', theme);
}
var currentTheme = localStorage.getItem('theme');
if (currentTheme === 'light' || currentTheme === 'dark') {
activateTheme(currentTheme);
} else {
activateTheme('light');
}
themeButton.onclick = function() {
var newTheme = localStorage.getItem('theme') === 'dark' ? 'light' : 'dark';
activateTheme(newTheme);
}
}
</script>
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> and <a href="https://eli.thegreenplace.net">Eli Bendersky</a> | <a href="https://github.com/mmcgrana/gobyexample">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a> | <button id="theme-button">Toggle theme</button>
</p>
{{end}}