-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
95 lines (82 loc) · 2.64 KB
/
scripts.js
File metadata and controls
95 lines (82 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
document.addEventListener("DOMContentLoaded", () => {
// --- Theme Toggle Logic ---
const themeToggleBtn = document.getElementById('themeToggleBtn');
const themeIcon = themeToggleBtn ? themeToggleBtn.querySelector('i') : null;
function setTheme(themeName) {
document.documentElement.setAttribute('data-theme', themeName);
localStorage.setItem('theme', themeName);
if (themeIcon) {
if (themeName === 'dark') {
themeIcon.classList.remove('fa-moon');
themeIcon.classList.add('fa-sun');
} else {
themeIcon.classList.remove('fa-sun');
themeIcon.classList.add('fa-moon');
}
}
}
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
setTheme(savedTheme);
} else {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
setTheme('dark');
} else {
setTheme('light');
}
}
if (themeToggleBtn) {
themeToggleBtn.addEventListener('click', () => {
if (document.documentElement.getAttribute('data-theme') === 'dark') {
setTheme('light');
} else {
setTheme('dark');
}
});
}
const heading = document.querySelector(".heading-txt h1");
const originalText = "UI Clones";
if (heading && document.body.classList.contains("site-loading")) {
heading.textContent = "";
let i = 0;
const typeInterval = setInterval(() => {
heading.textContent += originalText.charAt(i);
i++;
if (i >= originalText.length) {
clearInterval(typeInterval);
setTimeout(() => {
heading.style.borderRight = "none";
document.body.classList.remove("site-loading");
}, 400);
}
}, 150);
}
const goUpBtn = document.getElementById("goUpBtn");
if (goUpBtn) {
window.addEventListener("scroll", () => {
if (window.scrollY > 300) {
goUpBtn.classList.add("visible");
} else {
goUpBtn.classList.remove("visible");
}
});
goUpBtn.addEventListener("click", (e) => {
e.preventDefault();
window.scrollTo({ top: 0, behavior: "smooth" });
});
}
const cloneLinks = document.querySelectorAll('.x-go-btn, .instagram-go-btn');
const loadingOverlay = document.getElementById('loading-overlay');
if (cloneLinks.length > 0 && loadingOverlay) {
cloneLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const targetUrl = link.getAttribute('href');
loadingOverlay.classList.add('active');
setTimeout(() => {
window.location.href = targetUrl;
}, 2000);
});
});
}
});