Update 1.js

This commit is contained in:
FURK4NGG
2025-02-24 21:00:24 +03:00
committed by GitHub
parent 13a07a7317
commit a068a08aae
+23 -5
View File
@@ -1,19 +1,37 @@
/*CHANGE THEME*/ /*CHANGE THEME*/
// Darkmode instance'ını oluştur // Darkmode instance'ını oluştur
const darkmode = new Darkmode(); const darkmode = new Darkmode();
const metaTheme = document.getElementById("themeMeta");
// Dark mode değiştiğinde çalışacak fonksiyon
function updateThemeColor(isDark) {
metaTheme.setAttribute("content", isDark ? "#100f2c" : "#F8F6E3");
}
// Toggle butonu dinleyicisi
document.getElementById("darkmode-toggle").addEventListener("click", function () { document.getElementById("darkmode-toggle").addEventListener("click", function () {
darkmode.toggle(); // Dark mode'u aç/kapat darkmode.toggle(); // Dark mode'u aç/kapat
let metaTheme = document.getElementById("themeMeta"); // Kendi dark mode'umuzu tarayıcıdaki dark mode gibi algılat
// Karanlık modun aktif olup olmadığını localStorage'dan al
const isDarkMode = darkmode.isActivated(); const isDarkMode = darkmode.isActivated();
updateThemeColor(isDarkMode);
// Doğrudan theme color'ı değiştir // Tarayıcıya "sistem teması değişti" gibi davranması için event gönder
metaTheme.setAttribute("content", isDarkMode ? "#100f2c" : "#F8F6E3"); window.matchMedia('(prefers-color-scheme: dark)').dispatchEvent(new Event('change'));
}); });
// Tarayıcının sistem teması değişirse güncelle
if (window.matchMedia) {
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
mediaQuery.addEventListener('change', function (e) {
updateThemeColor(e.matches);
});
// Sayfa ilk yüklendiğinde de kontrol et
updateThemeColor(mediaQuery.matches);
}
/*SERVICES VISIBILITY*/ /*SERVICES VISIBILITY*/
const boxes = document.querySelectorAll('.services_id'); const boxes = document.querySelectorAll('.services_id');