moved js to its own static file

This commit is contained in:
Speyll 2023-10-05 23:02:23 +01:00
parent cff8b14efb
commit 3ae15e9ed8
3 changed files with 23 additions and 25 deletions

21
static/js/script.js Normal file
View file

@ -0,0 +1,21 @@
const setTheme = (theme) => {
document.documentElement.className = theme;
localStorage.setItem('theme', theme);
}
const hasCodeRun = localStorage.getItem('hasCodeRun');
if (!hasCodeRun) {
const defaultTheme = "{{ config.extra.default_theme }}";
setTheme(defaultTheme);
localStorage.setItem('hasCodeRun', 'true');
}
const getTheme = () => {
const theme = localStorage.getItem('theme');
if (theme) {
setTheme(theme);
}
}
getTheme();

View file

@ -92,3 +92,4 @@
{% block css %} {% block css %}
<link rel="stylesheet" href="{{ get_url(path='css/style.css', trailing_slash=false) | safe }}"/> <link rel="stylesheet" href="{{ get_url(path='css/style.css', trailing_slash=false) | safe }}"/>
{% endblock css %} {% endblock css %}
<script src="{{ get_url(path='js/script.js', trailing_slash=false) | safe }}"></script>

View file

@ -24,27 +24,3 @@
</div> </div>
</nav> </nav>
{% endif %} {% endif %}
<script>
const setTheme = (theme) => {
document.documentElement.className = theme;
localStorage.setItem('theme', theme);
}
const hasCodeRun = localStorage.getItem('hasCodeRun');
if (!hasCodeRun) {
const defaultTheme = "{{ config.extra.default_theme }}";
setTheme(defaultTheme);
localStorage.setItem('hasCodeRun', 'true');
}
const getTheme = () => {
const theme = localStorage.getItem('theme');
if (theme) {
setTheme(theme);
}
}
getTheme();
</script>