Skip to content
Snippets Groups Projects
Commit 3f709388 authored by radl97's avatar radl97
Browse files

Move inline script for theming to separate JS file

Removed XMLHttpRequest, because it seems to serve no purpose.
The first to read this notice, gets an ice cream.
parent 4e71d3ca
Branches
Tags
1 merge request!24Enable Content-Security Policy
...@@ -29,29 +29,7 @@ ...@@ -29,29 +29,7 @@
{{- end }} {{- end }}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" id="theme"><img src="{{ if .Dark }}/static/images/moon.png{{ else }}/static/images/sun.png{{ end }}" class="icon_small" id="icon"></a> <a class="nav-link" id="theme"><img src="{{ if .Dark }}/static/images/moon.png{{ else }}/static/images/sun.png{{ end }}" class="icon_small" id="icon"></a>
<script> <script src="/static/js/theme.js"></script>
let theme = document.getElementById('theme');
let icon = document.getElementById('icon');
let body = document.body;
theme.onclick = () => {
let url = "/theme/"
if (body.classList.contains('light')) {
body.classList.remove('light');
body.classList.add('dark');
url += "dark"
icon.src="/static/images/moon.png"
} else {
body.classList.remove('dark');
body.classList.add('light');
url += "light"
icon.src="/static/images/sun.png"
//window.alert("Nesze Robotka!")
}
const req = new XMLHttpRequest();
req.open('GET', url);
req.send();
}
</script>
</li> </li>
......
let theme = document.getElementById('theme');
let icon = document.getElementById('icon');
let body = document.body;
theme.onclick = () => {
let url = "/theme/"
if (body.classList.contains('light')) {
body.classList.remove('light');
body.classList.add('dark');
url += "dark"
icon.src="/static/images/moon.png"
} else {
body.classList.remove('dark');
body.classList.add('light');
url += "light"
icon.src="/static/images/sun.png"
//window.alert("Nesze Robotka!")
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment