|
| 1 | +<!doctype html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 6 | + <title>Contributors — commitra/react-verse</title> |
| 7 | + <style> |
| 8 | + body { font-family: Inter, Arial, sans-serif; margin: 32px; color: #111827; } |
| 9 | + h1 { font-size: 1.6rem; margin-bottom: 8px; } |
| 10 | + .controls { margin-bottom: 16px; } |
| 11 | + .grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(220px,1fr)); gap: 12px; } |
| 12 | + .card { border: 1px solid #e5e7eb; border-radius: 8px; padding: 12px; display:flex; gap:12px; align-items:center; } |
| 13 | + img { width:56px; height:56px; border-radius:50%; } |
| 14 | + .meta { display:flex; flex-direction:column; } |
| 15 | + .login { font-weight:600; } |
| 16 | + .small { color:#6b7280; font-size:0.9rem } |
| 17 | + .error { color: #b91c1c; } |
| 18 | + footer { margin-top: 24px; color:#6b7280; font-size:0.85rem } |
| 19 | + .spinner { animation:spin 1s linear infinite; border:2px solid #e5e7eb; border-top-color:#374151; border-radius:50%; width:18px; height:18px; } |
| 20 | + @keyframes spin { to { transform: rotate(360deg); } } |
| 21 | + </style> |
| 22 | +</head> |
| 23 | +<body> |
| 24 | + <h1>Contributors to commitra/react-verse</h1> |
| 25 | + <div class="controls"> |
| 26 | + <label for="token">Personal access token (optional, increases rate limits): </label> |
| 27 | + <input id="token" placeholder="ghp_... (optional)" style="width:360px;" /> |
| 28 | + <button id="load">Load contributors</button> |
| 29 | + <span id="status"></span> |
| 30 | + </div> |
| 31 | + |
| 32 | + <div id="results"></div> |
| 33 | + |
| 34 | + <footer> |
| 35 | + 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. |
| 36 | + </footer> |
| 37 | + |
| 38 | + <script> |
| 39 | + const owner = 'commitra'; |
| 40 | + const repo = 'react-verse'; |
| 41 | + const perPage = 100; |
| 42 | + |
| 43 | + const statusEl = document.getElementById('status'); |
| 44 | + const resultsEl = document.getElementById('results'); |
| 45 | + const tokenEl = document.getElementById('token'); |
| 46 | + const loadBtn = document.getElementById('load'); |
| 47 | + |
| 48 | + function setStatus(text, isError) { |
| 49 | + statusEl.textContent = text || ''; |
| 50 | + statusEl.className = isError ? 'error' : ''; |
| 51 | + } |
| 52 | + |
| 53 | + async function fetchContributors(token) { |
| 54 | + setStatus('Loading contributors...', false); |
| 55 | + resultsEl.innerHTML = '<div class="spinner" style="display:inline-block;margin-left:8px;"></div>'; |
| 56 | + |
| 57 | + const headers = { 'Accept': 'application/vnd.github+json' }; |
| 58 | + if (token) headers['Authorization'] = `token ${token}`; |
| 59 | + |
| 60 | + const url = `https://api.github.com/repos/${owner}/${repo}/contributors?per_page=${perPage}&anon=1`; |
| 61 | + |
| 62 | + try { |
| 63 | + const res = await fetch(url, { headers }); |
| 64 | + if (res.status === 403) { |
| 65 | + const rate = res.headers.get('x-ratelimit-remaining'); |
| 66 | + const reset = res.headers.get('x-ratelimit-reset'); |
| 67 | + setStatus(`Rate limited by GitHub API. Remaining: ${rate}. Reset: ${reset ? new Date(reset*1000).toLocaleString() : 'unknown'}`, true); |
| 68 | + resultsEl.innerHTML = ''; |
| 69 | + return []; |
| 70 | + } |
| 71 | + if (!res.ok) { |
| 72 | + const txt = await res.text(); |
| 73 | + setStatus(`GitHub API error: ${res.status} ${res.statusText}` , true); |
| 74 | + resultsEl.innerHTML = `<pre class="error">${escapeHtml(txt)}</pre>`; |
| 75 | + return []; |
| 76 | + } |
| 77 | + const data = await res.json(); |
| 78 | + setStatus('Loaded contributors (' + data.length + ').', false); |
| 79 | + return data; |
| 80 | + } catch (err) { |
| 81 | + setStatus('Network or CORS error: ' + err.message, true); |
| 82 | + resultsEl.innerHTML = ''; |
| 83 | + return []; |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + function escapeHtml(s) { |
| 88 | + return s.replace(/[&<>'"]/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":"'"}[c])); |
| 89 | + } |
| 90 | + |
| 91 | + function render(contributors) { |
| 92 | + if (!contributors || contributors.length === 0) { |
| 93 | + resultsEl.innerHTML = '<p>No contributors found.</p>'; |
| 94 | + return; |
| 95 | + } |
| 96 | + |
| 97 | + const grid = document.createElement('div'); |
| 98 | + grid.className = 'grid'; |
| 99 | + |
| 100 | + contributors.forEach(c => { |
| 101 | + const card = document.createElement('div'); |
| 102 | + card.className = 'card'; |
| 103 | + |
| 104 | + const avatar = document.createElement('img'); |
| 105 | + avatar.src = c.avatar_url || ''; |
| 106 | + avatar.alt = c.login || c.name || 'contributor'; |
| 107 | + |
| 108 | + const meta = document.createElement('div'); |
| 109 | + meta.className = 'meta'; |
| 110 | + |
| 111 | + const login = document.createElement('a'); |
| 112 | + login.className = 'login'; |
| 113 | + login.href = c.html_url || '#'; |
| 114 | + login.textContent = c.login || (c.name || 'unknown'); |
| 115 | + login.target = '_blank'; |
| 116 | + |
| 117 | + const details = document.createElement('div'); |
| 118 | + details.className = 'small'; |
| 119 | + details.innerHTML = `Contributions: ${c.contributions || 0}${c.type ? ' • type: ' + c.type : ''}`; |
| 120 | + |
| 121 | + meta.appendChild(login); |
| 122 | + meta.appendChild(details); |
| 123 | + |
| 124 | + card.appendChild(avatar); |
| 125 | + card.appendChild(meta); |
| 126 | + |
| 127 | + grid.appendChild(card); |
| 128 | + }); |
| 129 | + |
| 130 | + resultsEl.innerHTML = ''; |
| 131 | + resultsEl.appendChild(grid); |
| 132 | + } |
| 133 | + |
| 134 | + loadBtn.addEventListener('click', async () => { |
| 135 | + const token = tokenEl.value.trim() || null; |
| 136 | + const data = await fetchContributors(token); |
| 137 | + render(data); |
| 138 | + }); |
| 139 | + |
| 140 | + // Auto-load on open if no token and quick fetch allowed |
| 141 | + (async function autoLoad(){ |
| 142 | + // try to read token from URL query param ?token= or from localStorage |
| 143 | + const params = new URLSearchParams(location.search); |
| 144 | + const urlToken = params.get('token'); |
| 145 | + const stored = localStorage.getItem('GITHUB_TOKEN'); |
| 146 | + if (urlToken) tokenEl.value = urlToken; |
| 147 | + else if (stored) tokenEl.value = stored; |
| 148 | + |
| 149 | + // auto-fetch small list but only if not explicitly skipped |
| 150 | + try { |
| 151 | + const data = await fetchContributors(tokenEl.value.trim() || null); |
| 152 | + render(data); |
| 153 | + } catch(e) { /* ignore */ } |
| 154 | + })(); |
| 155 | + |
| 156 | + // store token if user enters one |
| 157 | + tokenEl.addEventListener('change', () => { |
| 158 | + const v = tokenEl.value.trim(); |
| 159 | + if (v) localStorage.setItem('GITHUB_TOKEN', v); |
| 160 | + else localStorage.removeItem('GITHUB_TOKEN'); |
| 161 | + }); |
| 162 | + </script> |
| 163 | +</body> |
| 164 | +</html> |
0 commit comments