From ba55906dbeec13f7a724cbb832c7a3c8a0bbabc8 Mon Sep 17 00:00:00 2001 From: Ali Eren Date: Mon, 24 Feb 2025 01:02:16 +0300 Subject: [PATCH] Fix: theme switcher initialization logic --- src/main.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main.ts b/src/main.ts index 0fa8334..bbf4ac4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -141,21 +141,23 @@ function setSwitcherIcon() { } function initializeSwitcher() { + const container = document.getElementById("themeContainer"); // Target div + if (!container) return; + const switcher = document.createElement('div') console.log(window.innerWidth) switcher.id = 'nightowl-switcher-default' - switcher.style.position = 'fixed' - switcher.style.left = 'calc(100vw - 100px)' - switcher.style.top = 'calc(10px)' - switcher.style.width = '50px' - switcher.style.height = '50px' - switcher.style.borderRadius = '50%' - switcher.style.backgroundColor = - toggleButtonMode === 'newState' ? 'black' : 'white' - switcher.style.display = 'flex' - switcher.style.justifyContent = 'center' - switcher.style.alignItems = 'center' - switcher.style.cursor = 'pointer' + switcher.style.width = "50px" + switcher.style.height = "50px" + switcher.style.borderRadius = "50%" + switcher.style.backgroundColor = toggleButtonMode === "newState" ? "black" : "white" + switcher.style.display = "flex" + switcher.style.justifyContent = "center" + switcher.style.alignItems = "center" + switcher.style.cursor = "pointer" + switcher.style.boxShadow = "0 0 10px rgba(0,0,0,0.2)" + switcher.style.transition = "all 0.3s ease-in-out" + switcher.style.overflow = "hidden"; switcher.style.zIndex = '9999' switcher.style.boxShadow = '0 0 10px rgba(0,0,0,0.2)' switcher.style.transition = 'all 0.3s ease-in-out' @@ -167,7 +169,7 @@ function initializeSwitcher() { storeModeInLocalStorage() }) - document.body.appendChild(switcher) + container.appendChild(switcher) setSwitcherIcon() }