-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
63 lines (57 loc) · 1.97 KB
/
main.js
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
function pausecomp(millis) {
var date = new Date();
var curDate = null;
do {
curDate = new Date();
} while (curDate - date < millis);
}
function getDaysSinceLaunch() {
var baseDate = new Date("03/22/22"), baseValue = 1;
var presentDate = new Date();
presentDate.setHours(00,00,00);
var timeDiff = Math.abs(presentDate.getTime() - baseDate.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
baseValue = baseValue + diffDays;
return baseValue;
}
async function getLinesOfCode() {
const response = await fetch("https://api.codetabs.com/v1/loc/?github=EDM115/unzip-bot");
if (!response.ok) {
console.log("getLinesOfCode() : Not reachable");
return 0;
}
const data = await response.json();
const linesOfCode = data[data.length - 1].lines;
return linesOfCode;
};
// function that returns the number of stars and forks of the project
async function getStarsAndForks() {
const response = await fetch("https://api.github.com/repos/EDM115/unzip-bot");
if (!response.ok) {
console.log("getStarsAndForks() : Not reachable");
return 0;
}
const data = await response.json();
const stars = data.stargazers_count;
const forks = data.forks_count;
return [stars, forks];
};
function setElements([linesOfCode, stars, forks]) {
const linesElement = document.getElementById("lines-of-code");
linesElement.setAttribute("data-purecounter-end", linesOfCode);
const starsElement = document.getElementById("stars");
starsElement.setAttribute("data-purecounter-end", stars);
const forksElement = document.getElementById("forks");
forksElement.setAttribute("data-purecounter-end", forks);
}
function setDays(days) {
const daysElement = document.getElementById("days-since-launch");
daysElement.setAttribute("data-purecounter-end", days);
}
window.addEventListener('load', async () => {
const days = getDaysSinceLaunch();
setDays(days);
const linesOfCode = await getLinesOfCode();
const [stars, forks] = await getStarsAndForks();
setElements([linesOfCode, stars, forks]);
});