From 7eb1426e1f14b22985e7b1983ed6afc2506fa698 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 17 Oct 2021 18:31:40 +0200 Subject: [PATCH] Use onload handler to set giscus theme as soon as it's loaded --- blog/static/js/edition-2/main.js | 11 ++++++----- blog/templates/snippets.html | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/blog/static/js/edition-2/main.js b/blog/static/js/edition-2/main.js index 1ebee250..e1fb157f 100644 --- a/blog/static/js/edition-2/main.js +++ b/blog/static/js/edition-2/main.js @@ -1,9 +1,4 @@ window.onload = function () { - let theme = localStorage.getItem("theme"); - if (theme != null) { - set_theme(theme) - } - let container = document.querySelector('#toc-aside'); if (container != null) { resize_toc(container); @@ -96,3 +91,9 @@ function set_giscus_theme(theme) { } } +function giscus_loaded() { + let theme = localStorage.getItem("theme"); + if (theme != null) { + set_giscus_theme(theme) + } +} diff --git a/blog/templates/snippets.html b/blog/templates/snippets.html index 96dbcf57..fc596c8c 100644 --- a/blog/templates/snippets.html +++ b/blog/templates/snippets.html @@ -38,7 +38,8 @@ data-emit-metadata="1" data-theme="preferred_color_scheme" crossorigin="anonymous" - async> + async + onload="giscus_loaded()">