-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
166 lines (136 loc) · 5.57 KB
/
script.js
File metadata and controls
166 lines (136 loc) · 5.57 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
document.addEventListener('DOMContentLoaded', () => {
const modalElement = document.getElementById('download-modal');
if (modalElement && modalElement.parentElement !== document.body) {
document.body.appendChild(modalElement);
}
const revealElements = document.querySelectorAll('.scroll-reveal');
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.1,
rootMargin: "0px 0px -50px 0px"
});
revealElements.forEach((element) => {
observer.observe(element);
});
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const target = document.querySelector(targetId);
if (target) {
e.preventDefault();
const headerOffset = 90;
const elementPosition = target.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: "smooth"
});
}
});
});
const repoOwner = "LeafClientMC";
const repoName = "LeafClient";
const downloadBtn = document.getElementById('download-btn');
const versionText = document.getElementById('version-text');
const modal = document.getElementById('download-modal');
const closeModalBtn = document.getElementById('close-modal');
const countdownSpan = document.getElementById('countdown');
const forceLink = document.getElementById('force-download-link');
let downloadUrl = "https://github.com/LeafClientMC/LeafClient/raw/refs/heads/main/latestexe/LeafClient.zip";
if (downloadBtn) {
downloadBtn.addEventListener('click', (e) => {
e.preventDefault();
console.log("Download clicked. Modal exists?", !!modal);
if (modal) {
openDownloadModal();
} else {
console.warn("Modal not found, falling back to direct download.");
window.location.href = downloadUrl;
}
});
if (versionText) {
fetch(`https://api.github.com/repos/${repoOwner}/${repoName}/releases`)
.then(response => {
if (!response.ok) throw new Error('Network response was not ok');
return response.json();
})
.then(data => {
const latestRelease = data[0];
if (latestRelease) {
versionText.textContent = `Version: ${latestRelease.tag_name}`;
const zipAsset = latestRelease.assets.find(asset => asset.name.endsWith('.zip'));
if (zipAsset) {
downloadUrl = zipAsset.browser_download_url;
console.log("Updated download URL to:", downloadUrl);
} else {
console.error('No .zip asset found in the latest release.');
versionText.textContent = "Version found, but no Zip file.";
}
}
})
.catch(error => {
console.error('Error fetching release data:', error);
versionText.textContent = "Version: Manual Download";
});
}
}
if (closeModalBtn) {
closeModalBtn.addEventListener('click', () => {
closeDownloadModal();
});
}
window.addEventListener('click', (e) => {
if (e.target === modal) {
closeDownloadModal();
}
});
function openDownloadModal() {
const modalEl = document.getElementById('download-modal');
if (modalEl) {
modalEl.style.display = 'flex';
modalEl.classList.add('active');
document.body.classList.add('modal-open');
const adFrame = document.getElementById('modal-ad-frame');
if (adFrame && !adFrame.src && adFrame.dataset.src) {
adFrame.src = adFrame.dataset.src;
}
startDownloadCountdown();
}
}
function closeDownloadModal() {
const modalEl = document.getElementById('download-modal');
if (modalEl) {
modalEl.classList.remove('active');
modalEl.style.display = 'none';
document.body.classList.remove('modal-open');
}
}
function startDownloadCountdown() {
let seconds = 5;
if (countdownSpan) countdownSpan.innerText = seconds;
if (forceLink) {
forceLink.classList.add('hidden');
forceLink.href = downloadUrl;
}
const timer = setInterval(() => {
seconds--;
if (countdownSpan) countdownSpan.innerText = seconds;
if (seconds <= 0) {
clearInterval(timer);
console.log("Countdown finished. Triggering download: " + downloadUrl);
window.location.href = downloadUrl;
if (forceLink) {
forceLink.classList.remove('hidden');
}
if (countdownSpan) countdownSpan.innerText = "0";
}
}, 1000);
}
});