-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
118 lines (108 loc) · 3.44 KB
/
Copy pathscript.js
File metadata and controls
118 lines (108 loc) · 3.44 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
const downloadLabel = document.querySelector(".version");
const navbar = document.querySelector(".navbar");
const starsCount = document.getElementById("stars-count");
const commitTime = document.getElementById("commit-time");
const versionsCount = document.getElementById("versions-count");
function timeAgo(date) {
const seconds = Math.floor((new Date() - new Date(date)) / 1000);
const intervals = [
{ label: "yr", seconds: 31536000 },
{ label: "mo", seconds: 2592000 },
{ label: "wk", seconds: 604800 },
{ label: "d", seconds: 86400 },
{ label: "hr", seconds: 3600 },
{ label: "min", seconds: 60 },
];
for (const interval of intervals) {
const count = Math.floor(seconds / interval.seconds);
if (count >= 1) {
return `${count} ${interval.label}${count > 1 ? "s" : ""} ago`;
}
}
return "just now";
}
fetch("https://github.com/ghapi/repos/JereIDE/JereIDE/releases/latest")
.then((res) => res.json())
.then((data) => {
const tag = data.tag_name;
const version = `v${tag.replace(/^v/i, "")}`;
downloadLabel.textContent = `${version} · macOS 12+ · Windows 10+`;
downloadLabel.href = data.html_url;
})
.catch(() => {
downloadLabel.textContent = "macOS 12+ · Windows 10+";
});
// Fetch repo data for stars and last commit
fetch("https://github.com/ghapi/repos/JereIDE/JereIDE")
.then((res) => res.json())
.then((repoData) => {
const stars = repoData.stargazers_count;
// Animate the star count from 0 to the actual number
let current = 0;
const target = stars;
const steps = target > 0 ? target : 1;
const increment = target > 100 ? Math.ceil(target / 50) : 1;
const duration = 1500;
const stepTime = Math.floor(
duration / (Math.min(target, steps) / increment),
);
const timer = setInterval(() => {
current += increment;
if (current >= target) {
current = target;
clearInterval(timer);
}
starsCount.textContent = current;
}, stepTime);
// Show time since last commit
commitTime.textContent = timeAgo(repoData.pushed_at);
})
.catch(() => {
starsCount.textContent = "0";
commitTime.textContent = "-";
versionsCount.textContent = "0";
});
function animateCount(el, target) {
let current = 0;
const steps = target > 0 ? target : 1;
const increment = target > 100 ? Math.ceil(target / 50) : 1;
const duration = 1500;
const stepTime = Math.floor(duration / (Math.min(target, steps) / increment));
const timer = setInterval(() => {
current += increment;
if (current >= target) {
current = target;
clearInterval(timer);
}
el.textContent = current;
}, stepTime);
}
// Fetch release count for "Versions Released"
fetch("https://github.com/ghapi/repos/JereIDE/JereIDE/releases")
.then((res) => res.json())
.then((releases) => {
if (Array.isArray(releases)) {
animateCount(versionsCount, releases.length);
}
})
.catch(() => {
versionsCount.textContent = "0";
});
window.addEventListener(
"scroll",
() => {
const threshold = 250;
if (window.scrollY > threshold) {
if (!navbar.classList.contains("navbar-fixed")) {
navbar.classList.add("navbar-fixed");
document.body.style.paddingTop = navbar.offsetHeight + "px";
}
} else {
if (navbar.classList.contains("navbar-fixed")) {
navbar.classList.remove("navbar-fixed");
document.body.style.paddingTop = "";
}
}
},
{ passive: true },
);