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 64e167c4eb3fa078bfbb80a28f468214630c045b
parent ad4420f01a7f389cb1276becd50970a3c4e8b803
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Sun,  2 Jun 2024 20:24:42 +0200

undo cookie-setting for theme: use sessionstore instead

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

diff --git a/template.html b/template.html @@ -30,33 +30,22 @@ </style> <script> // Toggle Theme function - function toggleTheme(set_mode = null, set_cookie = false) { + function toggleTheme(set_mode = null) { // Set Mode and mark in session storage if (set_mode === 0) { document.querySelector("body").classList = ["list"]; } else { document.querySelector("body").classList = ["list dark"]; } - if (document.cookie == "" && set_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"; - } else { sessionStorage.setItem("dark-mode", set_mode); - } } // On Load: set dark mode if necessary function initialTheme() { if ( // Case 1: Dark Mode is preferred and no cookie is set (window.matchMedia('(prefers-color-scheme: dark)').matches && - document.cookie == "") || - // Case 2: Dark Mode is set via cookie - document.cookie == "dark-mode=1" || - // Case 3: Dark Mode is set via session Storage + sessionStorage.getItem("dark-mode") === null) || + // Case 2: Dark Mode is set via session Storage sessionStorage.getItem("dark-mode") == 1 ) { toggleTheme(set_mode = 1); @@ -81,7 +70,7 @@ <path d="M6.18,15.64A2.18,2.18 0 0,1 8.36,17.82C8.36,19 7.38,20 6.18,20C5,20 4,19 4,17.82A2.18,2.18 0 0,1 6.18,15.64M4,4.44A15.56,15.56 0 0,1 19.56,20H16.73A12.73,12.73 0 0,0 4,7.27V4.44M4,10.1A9.9,9.9 0 0,1 13.9,20H11.07A7.07,7.07 0 0,0 4,12.93V10.1Z" /> </svg> </a> - <a href="#" onclick="toggleTheme(set_mode = 1 - sessionStorage.getItem('dark-mode'), set_cookie = true);"> + <a href="#" onclick="toggleTheme(set_mode = 1 - sessionStorage.getItem('dark-mode'));"> <!-- Copyright: 2023, Pictogrammers License: Apache-2.0 <https://www.apache.org/licenses/LICENSE-2.0> Info: https://pictogrammers.com/docs/general/license/