-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathCONTRIBUTORS.html
More file actions
164 lines (139 loc) · 6 KB
/
CONTRIBUTORS.html
File metadata and controls
164 lines (139 loc) · 6 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Contributors — commitra/react-verse</title>
<style>
body { font-family: Inter, Arial, sans-serif; margin: 32px; color: #111827; }
h1 { font-size: 1.6rem; margin-bottom: 8px; }
.controls { margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(220px,1fr)); gap: 12px; }
.card { border: 1px solid #e5e7eb; border-radius: 8px; padding: 12px; display:flex; gap:12px; align-items:center; }
img { width:56px; height:56px; border-radius:50%; }
.meta { display:flex; flex-direction:column; }
.login { font-weight:600; }
.small { color:#6b7280; font-size:0.9rem }
.error { color: #b91c1c; }
footer { margin-top: 24px; color:#6b7280; font-size:0.85rem }
.spinner { animation:spin 1s linear infinite; border:2px solid #e5e7eb; border-top-color:#374151; border-radius:50%; width:18px; height:18px; }
@keyframes spin { to { transform: rotate(360deg); } }
</style>
</head>
<body>
<h1>Contributors to commitra/react-verse</h1>
<div class="controls">
<label for="token">Personal access token (optional, increases rate limits): </label>
<input id="token" placeholder="ghp_... (optional)" style="width:360px;" />
<button id="load">Load contributors</button>
<span id="status"></span>
</div>
<div id="results"></div>
<footer>
This page fetches contributor data from the GitHub REST API: /repos/commitra/react-verse/contributors. If you see incomplete results, the repository may have many contributors — open issues or try providing a personal access token.
</footer>
<script>
const owner = 'commitra';
const repo = 'react-verse';
const perPage = 100;
const statusEl = document.getElementById('status');
const resultsEl = document.getElementById('results');
const tokenEl = document.getElementById('token');
const loadBtn = document.getElementById('load');
function setStatus(text, isError) {
statusEl.textContent = text || '';
statusEl.className = isError ? 'error' : '';
}
async function fetchContributors(token) {
setStatus('Loading contributors...', false);
resultsEl.innerHTML = '<div class="spinner" style="display:inline-block;margin-left:8px;"></div>';
const headers = { 'Accept': 'application/vnd.github+json' };
if (token) headers['Authorization'] = `token ${token}`;
const url = `https://api.github.com/repos/${owner}/${repo}/contributors?per_page=${perPage}&anon=1`;
try {
const res = await fetch(url, { headers });
if (res.status === 403) {
const rate = res.headers.get('x-ratelimit-remaining');
const reset = res.headers.get('x-ratelimit-reset');
setStatus(`Rate limited by GitHub API. Remaining: ${rate}. Reset: ${reset ? new Date(reset*1000).toLocaleString() : 'unknown'}`, true);
resultsEl.innerHTML = '';
return [];
}
if (!res.ok) {
const txt = await res.text();
setStatus(`GitHub API error: ${res.status} ${res.statusText}` , true);
resultsEl.innerHTML = `<pre class="error">${escapeHtml(txt)}</pre>`;
return [];
}
const data = await res.json();
setStatus('Loaded contributors (' + data.length + ').', false);
return data;
} catch (err) {
setStatus('Network or CORS error: ' + err.message, true);
resultsEl.innerHTML = '';
return [];
}
}
function escapeHtml(s) {
return s.replace(/[&<>'"]/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":"'"}[c]));
}
function render(contributors) {
if (!contributors || contributors.length === 0) {
resultsEl.innerHTML = '<p>No contributors found.</p>';
return;
}
const grid = document.createElement('div');
grid.className = 'grid';
contributors.forEach(c => {
const card = document.createElement('div');
card.className = 'card';
const avatar = document.createElement('img');
avatar.src = c.avatar_url || '';
avatar.alt = c.login || c.name || 'contributor';
const meta = document.createElement('div');
meta.className = 'meta';
const login = document.createElement('a');
login.className = 'login';
login.href = c.html_url || '#';
login.textContent = c.login || (c.name || 'unknown');
login.target = '_blank';
const details = document.createElement('div');
details.className = 'small';
details.innerHTML = `Contributions: ${c.contributions || 0}${c.type ? ' • type: ' + c.type : ''}`;
meta.appendChild(login);
meta.appendChild(details);
card.appendChild(avatar);
card.appendChild(meta);
grid.appendChild(card);
});
resultsEl.innerHTML = '';
resultsEl.appendChild(grid);
}
loadBtn.addEventListener('click', async () => {
const token = tokenEl.value.trim() || null;
const data = await fetchContributors(token);
render(data);
});
// Auto-load on open if no token and quick fetch allowed
(async function autoLoad(){
// try to read token from URL query param ?token= or from localStorage
const params = new URLSearchParams(location.search);
const urlToken = params.get('token');
const stored = localStorage.getItem('GITHUB_TOKEN');
if (urlToken) tokenEl.value = urlToken;
else if (stored) tokenEl.value = stored;
// auto-fetch small list but only if not explicitly skipped
try {
const data = await fetchContributors(tokenEl.value.trim() || null);
render(data);
} catch(e) { /* ignore */ }
})();
// store token if user enters one
tokenEl.addEventListener('change', () => {
const v = tokenEl.value.trim();
if (v) localStorage.setItem('GITHUB_TOKEN', v);
else localStorage.removeItem('GITHUB_TOKEN');
});
</script>
</body>
</html>