-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGH.html
More file actions
291 lines (291 loc) Β· 10 KB
/
Copy pathGH.html
File metadata and controls
291 lines (291 loc) Β· 10 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>GitHub Dashboard</title>
<link rel="icon" type="image/png" href="/assets/images/favicon.png">
<link rel="stylesheet" href="/assets/style.css">
<style>
.container {
max-width: 1100px;
margin: auto;
padding: 20px;
}
.repo-grid {
display: grid;
grid-template-columns: repeat(auto-fit,minmax(260px,1fr));
gap: 20px;
margin-top: 15px;
}
.card {
padding: 15px;
transition: .2s;
}
.card:hover {
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.card a {
text-decoration: none !important;
color: inherit !important;
display: block;
}
.meta {
font-size: .8em;
color: #666;
margin-top: 8px;
}
.meta.release {
display: inline-flex;
}
.meta.release a {
text-decoration: underline !important;
}
.topics {
margin-top: 8px;
}
.topic-badge {
display: inline-block;
background: #e1ecf4;
color: #0366d6;
padding: 2px 6px;
margin: 2px;
border-radius: 3px;
font-size: 0.75em;
font-weight: 500;
}
.stats {
display: grid;
grid-template-columns: repeat(auto-fit,minmax(150px,1fr));
gap: 15px;
margin-bottom: 30px;
}
.stat {
background: var(--card-bg);
padding: 15px;
border-radius: 8px;
text-align: center;
}
.stat strong {
font-size: 1.4em;
display: block;
}
.section {
margin-top: 40px;
}
.lang-chart {
margin-top: 20px;
}
.lang-bar {
height: 20px;
margin-bottom: 5px;
border-radius: 5px;
color: white;
font-size: 0.75em;
padding-left: 5px;
line-height: 20px;
}
</style>
</head>
<body>
<div id="navbar"></div>
<div class="container">
<h1>GitHub Dashboard</h1>
<div id="stats" class="stats"></div>
<h3>Language Usage</h3>
<div id="langChart" class="lang-chart"></div>
<div class="section">
<h2>π€ User Repositories</h2>
<div id="userRepos" class="repo-grid"></div>
</div>
<div class="section">
<h2>π’ Organization Repositories</h2>
<div id="orgRepos" class="repo-grid"></div>
</div>
<div class="section">
<h2>π¦ Archived</h2>
<div id="archivedRepos" class="repo-grid"></div>
</div>
</div>
<div id="footer"></div>
<script src="/assets/script.js"></script>
<script>
const CACHE_KEY = "github_dashboard_cache";
const CACHE_TIME = 60 * 60 * 1000; // 1 hour in milliseconds
const API_REQUEST_TIMESTAMP_KEY = "api_request_timestamps"; // Store timestamps for rate-limiting
// Function to get the current timestamp
function getCurrentTimestamp() {
return Date.now();
}
// Check if the request is allowed based on the last 5 API request timestamps
function canMakeApiRequest() {
const requestTimestamps = JSON.parse(localStorage.getItem(API_REQUEST_TIMESTAMP_KEY)) || [];
// Remove timestamps older than 1 hour
const oneHourAgo = getCurrentTimestamp() - CACHE_TIME;
const recentRequests = requestTimestamps.filter(timestamp => timestamp > oneHourAgo);
// If there are fewer than 40 recent requests, allow the new request
if (recentRequests.length < 40) {
return true;
}
// If there are 40 or more requests in the last hour, deny the request
return false;
}
// Store the timestamp of the API request
function storeApiRequestTimestamp() {
const requestTimestamps = JSON.parse(localStorage.getItem(API_REQUEST_TIMESTAMP_KEY)) || [];
requestTimestamps.push(getCurrentTimestamp());
// Keep only the last 5 timestamps
if (requestTimestamps.length > 5) {
requestTimestamps.shift(); // Remove the oldest timestamp
}
localStorage.setItem(API_REQUEST_TIMESTAMP_KEY, JSON.stringify(requestTimestamps));
}
// Repo card rendering logic
function repoCard(repo, latestRelease) {
let date = new Date(repo.pushed_at).toLocaleDateString();
let topicsHtml = "";
if (repo.topics && repo.topics.length) {
topicsHtml =
'<div class="topics">' +
repo.topics
.map((t) => `<span class="topic-badge">${t}</span>`)
.join("") +
"</div>";
}
// Latest release HTML section
let releaseHtml = "";
if (latestRelease) {
releaseHtml = `
<div class="meta release">
<span style="white-space: pre;">π Latest Release: </span>
<a target="_blank" rel="noopener noreferrer" href="${latestRelease.html_url}">${latestRelease.name}</a>
<span style="white-space: pre;"> - ${new Date(latestRelease.published_at).toLocaleDateString()}</span>
</div>
`;
}
return `
<div class="card">
<a href="${repo.html_url}" target="_blank" rel="noopener noreferrer">
<h3>${repo.full_name}</h3>
</a>
<p>${repo.description ?? "No description available"}</p>
<div class="meta">
β ${repo.stargazers_count} | π΄ ${repo.forks_count} | π» ${repo.language ?? "Unknown"} | π ${date}
</div>
${topicsHtml}
${releaseHtml}
</div>
`;
}
// Function to fetch the latest release data
async function getLatestRelease(repo) {
if (!canMakeApiRequest()) {
console.log("You have exceeded the 5 requests per hour limit. Skipping API call.");
return null;
}
// Store the timestamp of the current request to prevent future requests within the same hour
storeApiRequestTimestamp();
try {
const response = await fetch(`${repo.url}/releases/latest`, {
headers: {
Accept: "application/vnd.github.v3+json",
},
});
if (response.ok) {
const release = await response.json();
return release;
}
} catch (error) {
console.error(`Failed to fetch latest release for ${repo.full_name}`, error);
}
return null; // Return null if no release or error occurs
}
// Rendering function for repositories and stats
async function render(allRepos) {
let userContainer = document.getElementById("userRepos");
let orgContainer = document.getElementById("orgRepos");
let archContainer = document.getElementById("archivedRepos");
let totalStars = 0;
let totalForks = 0;
let languages = {};
// Fetch the latest release for each repo
const releasePromises = allRepos.map(async (repo) => {
const latestRelease = await getLatestRelease(repo);
return { repo, latestRelease };
});
const reposWithReleases = await Promise.all(releasePromises);
reposWithReleases.forEach(({ repo, latestRelease }) => {
totalStars += repo.stargazers_count;
totalForks += repo.forks_count;
if (repo.language) languages[repo.language] = (languages[repo.language] || 0) + 1;
let html = repoCard(repo, latestRelease);
if (repo.archived) {
archContainer.innerHTML += html;
} else if (repo.owner.login === "Ignotum77") {
userContainer.innerHTML += html;
} else {
orgContainer.innerHTML += html;
}
});
renderStats(allRepos, totalStars, totalForks, Object.keys(languages).length);
renderLangChart(languages);
}
// Rendering statistics
function renderStats(repos, stars, forks, langCount) {
document.getElementById("stats").innerHTML = `
<div class="stat"><strong>${repos.length}</strong> Repositories</div>
<div class="stat"><strong>${stars}</strong> Stars</div>
<div class="stat"><strong>${forks}</strong> Forks</div>
<div class="stat"><strong>${langCount}</strong> Languages</div>
`;
}
// Rendering language chart
function renderLangChart(languages) {
let container = document.getElementById("langChart");
container.innerHTML = "";
let total = Object.values(languages).reduce((a, b) => a + b, 0);
const colors = ["#c3b01e", "#3572A5", "#563d7c", "#c6538c", "#f34b7d", "#2b7489", "#701516", "#b07219"];
let i = 0;
for (let lang in languages) {
let perc = Math.round(languages[lang] / total * 100);
let color = colors[i % colors.length];
container.innerHTML += `<div class="lang-bar" style="width:${perc}%; background:${color}">${lang} ${perc}%</div>`;
i++;
}
}
// Load data from GitHub API and render the dashboard
async function loadRepos() {
let cached = localStorage.getItem(CACHE_KEY);
if (cached) {
let obj = JSON.parse(cached);
if (Date.now() - obj.time < CACHE_TIME) {
// If cached data is still valid, use it
console.log("Using cached data");
render(obj.data);
return;
}
}
// If no cache or cache expired, attempt to fetch new data
let userReposFetch = fetch(
"https://api.github.com/users/Ignotum77/repos?per_page=100",
{ headers: { Accept: "application/vnd.github.mercy-preview+json" } }
).then((r) => r.json());
let orgsFetch = fetch("https://api.github.com/users/Ignotum77/orgs").then((r) => r.json());
let [userRepos, orgs] = await Promise.all([userReposFetch, orgsFetch]);
let orgRepoPromises = orgs.map((org) =>
fetch(`https://api.github.com/orgs/${org.login}/repos?per_page=100`, {
headers: { Accept: "application/vnd.github.mercy-preview+json" },
}).then((r) => r.json())
);
let orgRepos = (await Promise.all(orgRepoPromises)).flat();
let allRepos = [...userRepos, ...orgRepos];
allRepos.sort((a, b) => new Date(b.pushed_at) - new Date(a.pushed_at));
// Cache the fetched data for future use
localStorage.setItem(CACHE_KEY, JSON.stringify({ time: Date.now(), data: allRepos }));
render(allRepos);
}
loadRepos();
</script>
</body>
</html>