pub / newsplanet

Planet-Style Newsfeed generated with perlanet
git clone https://https://src.jayvii.de/pub/newsplanet.git
Home | Log | Files | Exports | Refs | README | RSS

commit 4664ef7d280b8b929d48577d52773bd79eeb5f9d
parent b85558d008814e85f1b67419053367a971c4aec3
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Sun,  2 Jun 2024 18:29:40 +0200

Prompt user for cookie permissions

Diffstat:
Mtemplate.html | 15+++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/template.html b/template.html @@ -37,16 +37,23 @@ } else { document.querySelector("body").classList = ["list dark"]; } - sessionStorage.setItem("dark-mode", set_mode); - document.cookie="dark-mode=" + set_mode + ";SameSite=Strict"; + if (document.cookie == "") { + var set_cookie = confirm( + "Do you want to save this decision with a cookie?"" + ); + + } + if (set_cookie) { + document.cookie="dark-mode=" + set_mode + ";SameSite=Strict"; + } } // On Load: set dark mode if necessary function initialTheme() { if ( - // Case 1: Dark Mode is preferred and has not been toggled before + // Case 1: Dark Mode is preferred and no cookie is set (window.matchMedia('(prefers-color-scheme: dark)').matches && document.cookie == "") || - // Case 2: Dark Mode has been choosen before + // Case 2: Dark Mode is set via cookie document.cookie == "dark-mode=1" ) { toggleTheme(set_mode = 1);