enhance: DOMContentLoaded instead of line

This commit is contained in:
minoplhy 2024-05-02 21:21:29 +07:00
parent 4d591adbb5
commit 2f7c70e846
Signed by: minoplhy
GPG Key ID: 41D406044E2434BF
3 changed files with 5 additions and 12 deletions

View File

@ -21,4 +21,8 @@ function darkmode_disable() {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches && localStorage.getItem('dark-mode') === null) {
localStorage.setItem('dark-mode', 'true');
}
}
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("dark-mode-button").addEventListener("click", darkmode);
});

View File

@ -1,2 +0,0 @@
/* initialize onclick here because the main point is to avoid inline scripts and stylesheets */
document.getElementById("dark-mode-button").addEventListener("click", darkmode);

View File

@ -63,15 +63,6 @@
Simply place a custom_body.html into
your local /layouts/partials-directory -->
{{- partial "custom_body.html" . -}}
{{- /* Onclick Javascript */}}
{{- $darkmode_onclick := (resources.Get "js/darkmode_click.js") | resources.Minify }}
{{- if not site.Params.assets.disableFingerprinting }}
{{- $darkmode_onclick := $darkmode_onclick | fingerprint }}
<script crossorigin="anonymous" src="{{ $darkmode_onclick.RelPermalink }}" integrity="{{ $darkmode_onclick.Data.Integrity }}"></script>
{{ else }}
<script crossorigin="anonymous" src="{{ $darkmode_onclick.RelPermalink }}"></script>
{{ end }}
</body>
</html>