-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
101 lines (91 loc) · 3.43 KB
/
script.js
File metadata and controls
101 lines (91 loc) · 3.43 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
document.addEventListener("DOMContentLoaded", () => {
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute("href"));
if (target) {
target.scrollIntoView({
behavior: "smooth",
block: "start",
});
}
});
});
// --- Fetch Latest Release and Stars from GitHub ---
const macOSRepo = "floatpane/floatpane";
const windowsRepo = "floatpane/floatpane-windows";
const versionSpan = document.getElementById("latest-version");
const demoVersionSpan = document.getElementById("demo-version");
const downloadLink = document.getElementById("download-link");
const installLink = document.getElementById("install-link");
const windowsInstallLink = document.getElementById("windows-install-link");
const starsSpan = document.getElementById("github-stars");
async function fetchRepoInfo() {
try {
// Fetch macOS release info
const macOSReleaseResponse = await fetch(
`https://api.github.com/repos/floatpane/floatpane/releases/latest`,
);
if (macOSReleaseResponse.ok) {
const releaseData = await macOSReleaseResponse.json();
const latestVersion = releaseData.tag_name;
const releaseUrl = releaseData.html_url;
if (demoVersionSpan) demoVersionSpan.textContent = latestVersion;
if (versionSpan) versionSpan.textContent = latestVersion;
if (downloadLink) downloadLink.href = releaseUrl;
if (installLink) installLink.href = releaseUrl;
}
// Fetch Windows release info
try {
const windowsReleaseResponse = await fetch(
`https://api.github.com/repos/${windowsRepo}/releases/latest`,
);
if (windowsReleaseResponse.ok && windowsInstallLink) {
const windowsReleaseData = await windowsReleaseResponse.json();
windowsInstallLink.href = windowsReleaseData.html_url;
}
} catch (error) {
console.log("Windows repo not found or accessible:", error);
}
// Fetch repo info for stars (using macOS repo)
const repoResponse = await fetch(
`https://api.github.com/repos/${macOSRepo}`,
);
if (repoResponse.ok) {
const repoData = await repoResponse.json();
const starCount = repoData.stargazers_count;
if (starsSpan) starsSpan.textContent = starCount;
}
} catch (error) {
console.error("Could not fetch GitHub data:", error);
if (versionSpan) versionSpan.textContent = "N/A";
if (starsSpan) starsSpan.textContent = "N/A";
}
}
fetchRepoInfo();
});
// --- Initialize Clipboard.js ---
if (typeof ClipboardJS !== "undefined") {
const clipboard = new ClipboardJS(".copy-btn");
clipboard.on("success", function (e) {
const button = e.trigger;
const originalContent = button.innerHTML;
button.innerHTML = "Copied!";
setTimeout(() => {
button.innerHTML = originalContent;
}, 2000);
e.clearSelection();
});
clipboard.on("error", function (e) {
console.error("Clipboard Action:", e.action);
console.error("Clipboard Trigger:", e.trigger);
// Fallback for error
const button = e.trigger;
const originalContent = button.innerHTML;
button.innerHTML = "Error!";
setTimeout(() => {
button.innerHTML = originalContent;
}, 2000);
});
}