From 44448e350c9a5996b8043509c1ab67d641cfdc10 Mon Sep 17 00:00:00 2001 From: Thom Vaughan Date: Thu, 4 Jul 2024 01:00:34 +0100 Subject: [PATCH] feat: consolidate scripts into app.js --- docs/app.js | 17 +++++++++++++++++ docs/index.html | 18 ------------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/docs/app.js b/docs/app.js index 9db1984..ad3629d 100644 --- a/docs/app.js +++ b/docs/app.js @@ -165,4 +165,21 @@ function loadPage() { fetchLatestCommit(); } +const toggleButton = document.getElementById('dark-mode-toggle'); +const darkModeText = `Dark mode`; +const lightModeText = `Light mode`; +toggleButton.innerHTML = darkModeText; + +if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { + document.body.classList.add('dark-mode'); + toggleButton.innerHTML = lightModeText; +} else { + toggleButton.innerHTML = darkModeText; +} + +toggleButton.addEventListener('click', () => { + document.body.classList.toggle('dark-mode'); + toggleButton.innerHTML = document.body.classList.contains('dark-mode') ? lightModeText : darkModeText; +}); + window.onload = loadPage; diff --git a/docs/index.html b/docs/index.html index 2a68052..ab3ef3e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -68,24 +68,6 @@ Dark mode -