2024-10-03 05:16:49 +00:00
|
|
|
const root = document.querySelector(':root');
|
|
|
|
const themeToggle = document.getElementById('theme-toggle');
|
2024-11-03 13:51:18 +00:00
|
|
|
const mainNavbar = document.querySelector('#main-navbar');
|
2024-10-02 03:08:48 +00:00
|
|
|
let mouseX = 0;
|
|
|
|
let mouseY = 0;
|
2024-11-03 13:51:18 +00:00
|
|
|
let navX = mainNavbar.getBoundingClientRect().x;
|
|
|
|
let navY = mainNavbar.getBoundingClientRect().y;
|
|
|
|
let navW = mainNavbar.getBoundingClientRect().width;
|
|
|
|
let navH = mainNavbar.getBoundingClientRect().height;
|
|
|
|
root.style.setProperty("--nav-x", `${navX}`);
|
|
|
|
root.style.setProperty("--nav-y", `${navY}`);
|
2024-10-02 03:08:48 +00:00
|
|
|
|
2024-10-03 05:16:49 +00:00
|
|
|
const darkMode = {
|
|
|
|
mainBg: "linear-gradient(#28164B, 70%, #825ECA )",
|
|
|
|
contentBg: "#1A181B",
|
|
|
|
primaryText: "#DCCBFF",
|
|
|
|
secondaryText: "#B89AF5",
|
|
|
|
header: "#825ECA",
|
|
|
|
navLink: "#B89AF5",
|
|
|
|
primaryLink: "#B89AF5",
|
|
|
|
primaryLinkHover: "#E3D5FF",
|
|
|
|
secondaryLink: "#E3D5FF",
|
|
|
|
secondaryLinkHover: "#B89AF5",
|
|
|
|
ternaryLink: "var(--blue)",
|
|
|
|
ternaryLinkHover: "var(--brown)",
|
|
|
|
shadow: "#00000088"
|
|
|
|
}
|
|
|
|
|
|
|
|
const lightMode = {
|
2024-11-03 13:51:18 +00:00
|
|
|
// mainBg: "linear-gradient(#0045df, #00d4ff)",
|
|
|
|
mainBg: "linear-gradient(#2B5F8C, #3DADF2)",
|
|
|
|
contentBg: "white",
|
|
|
|
primaryText: "#132B40",
|
|
|
|
secondaryText: "#2B5F8C",
|
|
|
|
header: "#CFE8FF",
|
|
|
|
navLink: "#CFE8FF",
|
|
|
|
primaryLink: "#337AA6",
|
|
|
|
primaryLinkHover: "#3DADF2",
|
|
|
|
secondaryLink: "#2F4A62",
|
|
|
|
secondaryLinkHover: "#2B5F8C",
|
|
|
|
ternaryLink: "#2B5F8C",
|
|
|
|
ternaryLinkHover: "#3DADF2",
|
|
|
|
shadow: "#132B40AA"
|
2024-10-03 05:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const applyTheme = (theme) => {
|
|
|
|
root.style.setProperty("--main-bg", theme.mainBg);
|
|
|
|
root.style.setProperty("--content-bg", theme.contentBg);
|
|
|
|
root.style.setProperty("--primary-text", theme.primaryText);
|
|
|
|
root.style.setProperty("--secondary-text", theme.secondaryText);
|
|
|
|
root.style.setProperty("--header", theme.header);
|
|
|
|
root.style.setProperty("--nav-link", theme.navLink);
|
|
|
|
root.style.setProperty("--primary-link", theme.primaryLink);
|
|
|
|
root.style.setProperty("--primary-link-hover", theme.primaryLinkHover);
|
|
|
|
root.style.setProperty("--secondary-link", theme.secondaryLink);
|
|
|
|
root.style.setProperty("--secondary-link-hover", theme.secondaryLinkHover);
|
|
|
|
root.style.setProperty("--ternary-link", theme.ternaryLink);
|
|
|
|
root.style.setProperty("--ternary-link-hover", theme.ternaryLinkHover);
|
|
|
|
root.style.setProperty("--shadow", theme.shadow);
|
|
|
|
}
|
|
|
|
|
|
|
|
const enableDarkMode = () => {
|
|
|
|
applyTheme(darkMode);
|
|
|
|
localStorage.setItem('theme', 'dark');
|
|
|
|
themeToggle.innerText = 'Light Mode';
|
|
|
|
}
|
|
|
|
|
|
|
|
const disableDarkMode = () => {
|
|
|
|
applyTheme(lightMode);
|
|
|
|
localStorage.setItem('theme', 'light');
|
|
|
|
themeToggle.innerText = 'Dark Mode';
|
|
|
|
}
|
|
|
|
|
|
|
|
const detectTheme = () => {
|
|
|
|
let theme = 'light';
|
|
|
|
let themeObj = lightMode;
|
|
|
|
|
|
|
|
if (localStorage.getItem('theme')) {
|
|
|
|
theme = localStorage.getItem('theme');
|
|
|
|
}
|
|
|
|
else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
|
|
theme = 'dark';
|
|
|
|
}
|
|
|
|
|
|
|
|
theme === 'dark' ? enableDarkMode() : disableDarkMode();
|
|
|
|
}
|
|
|
|
|
2024-10-02 03:08:48 +00:00
|
|
|
document.addEventListener("mousemove", (evt) => {
|
|
|
|
mouseX = evt.clientX / innerWidth;
|
|
|
|
mouseY = evt.clientY / innerHeight;
|
|
|
|
|
2024-11-03 13:51:18 +00:00
|
|
|
root.style.setProperty("--mouse-x", `${evt.clientX}px`);
|
|
|
|
root.style.setProperty("--mouse-y", `${evt.clientY}px`);
|
2024-10-02 03:08:48 +00:00
|
|
|
});
|
|
|
|
|
2024-11-03 13:51:18 +00:00
|
|
|
const calcNavOffset = () => {
|
|
|
|
let rect = mainNavbar.getBoundingClientRect()
|
|
|
|
navX = rect.x;
|
|
|
|
navY = rect.y;
|
|
|
|
navW = rect.width;
|
|
|
|
navH = rect.height;
|
|
|
|
root.style.setProperty("--nav-x-offset", `${navX - (navW / 2)}px`);
|
|
|
|
root.style.setProperty("--nav-y-offset", `${navY - (navH / 2)}px`);
|
|
|
|
}
|
|
|
|
|
|
|
|
calcNavOffset();
|
|
|
|
|
2024-10-03 05:16:49 +00:00
|
|
|
themeToggle.className = "";
|
|
|
|
detectTheme();
|
|
|
|
|
|
|
|
themeToggle.addEventListener('click', () => {
|
|
|
|
localStorage.getItem('theme') === 'light' ? enableDarkMode() : disableDarkMode();
|
|
|
|
});
|