From eb8ca8212c7aa563f37f737ea8af91a565a34104 Mon Sep 17 00:00:00 2001 From: garronej Date: Fri, 11 Nov 2022 23:17:00 +0100 Subject: [PATCH] Scope the cookie to the domain --- src/lib/darkMode.ts | 12 +----------- src/lib/start.ts | 2 -- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/lib/darkMode.ts b/src/lib/darkMode.ts index 1e340f371..b8328e39d 100644 --- a/src/lib/darkMode.ts +++ b/src/lib/darkMode.ts @@ -72,23 +72,13 @@ export function startObservingColorSchemeHtmlAttribute() { { const setColorSchemeCookie = (colorScheme: ColorScheme) => { - console.log("DEBUG: setColorSchemeCookie"); - let newCookie = `${data_fr_theme}=${colorScheme};path=/;max-age=31536000`; //We do not set the domain if we are on localhost or an ip if (window.location.hostname.match(/\.[a-zA-Z]{2,}$/)) { - console.log("DEBUG: Append to newCookie"); - - newCookie += `;domain=${ - window.location.hostname.split(".").length >= 3 - ? window.location.hostname.replace(/^[^.]+\./, "") - : window.location.hostname - }`; + newCookie += `;domain=${window.location.hostname}`; } - console.log(`DEBUG: set newCookie: ${newCookie}`); - document.cookie = newCookie; }; diff --git a/src/lib/start.ts b/src/lib/start.ts index 00519b4ca..015f0837d 100644 --- a/src/lib/start.ts +++ b/src/lib/start.ts @@ -67,8 +67,6 @@ export async function startDsfrReact(params: Params) { ); } - console.log("DEBUG: startObservingColorSchemeHtmlAttribute"); - startObservingColorSchemeHtmlAttribute(); (window as any).dsfr = { verbose, "mode": "manual" };