From 3ae15e9ed853418a811a6c36a78c5a3afd79d71f Mon Sep 17 00:00:00 2001 From: Speyll Date: Thu, 5 Oct 2023 23:02:23 +0100 Subject: [PATCH] moved js to its own static file --- static/js/script.js | 21 +++++++++++++++++++++ templates/head.html | 3 ++- templates/header.html | 24 ------------------------ 3 files changed, 23 insertions(+), 25 deletions(-) create mode 100644 static/js/script.js diff --git a/static/js/script.js b/static/js/script.js new file mode 100644 index 0000000..205d215 --- /dev/null +++ b/static/js/script.js @@ -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(); \ No newline at end of file diff --git a/templates/head.html b/templates/head.html index 4055b7f..179c11c 100644 --- a/templates/head.html +++ b/templates/head.html @@ -91,4 +91,5 @@ {% endif %} {% block css %} -{% endblock css %} \ No newline at end of file +{% endblock css %} + \ No newline at end of file diff --git a/templates/header.html b/templates/header.html index 0bda1b0..a65b254 100644 --- a/templates/header.html +++ b/templates/header.html @@ -24,27 +24,3 @@ {% endif %} - -