-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script> | ||
(function () { | ||
// 시스템 테마 변경 감지 객체 생성 | ||
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)"); | ||
|
||
// 시스템 테마와 저장된 테마를 비교하여 필요하면 localStorage에서 항목 제거 | ||
function checkAndRemoveStoredTheme() { | ||
const systemThemeIsDark = mediaQuery.matches; | ||
const storedTheme = localStorage.getItem("color-theme"); | ||
|
||
if ( | ||
(systemThemeIsDark && storedTheme === "dark") || | ||
(!systemThemeIsDark && storedTheme === "light") | ||
) { | ||
localStorage.removeItem("color-theme"); | ||
} | ||
} | ||
|
||
// 페이지 로드 시 초기 실행 | ||
checkAndRemoveStoredTheme(); | ||
|
||
// 시스템 테마 변경 시 이벤트 리스너 등록 | ||
mediaQuery.addEventListener("change", function () { | ||
checkAndRemoveStoredTheme(); | ||
}); | ||
})(); | ||
</script> |