-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
367 lines (317 loc) · 12.2 KB
/
index.html
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>GitPort</title>
<style>
/* General Styling */
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 20px;
background-color: #000;
color: #fff;
line-height: 1.6;
}
h1 {
text-align: center;
color: #ffffff;
margin-bottom: 20px;
}
form {
max-width: 800px;
margin: 0 auto 20px auto;
padding: 20px;
background-color: #1a1a1a;
border-radius: 10px;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
color: #ffffff;
}
input[type="text"] {
width: calc(100% - 50px);
padding: 12px;
margin-bottom: 15px;
box-sizing: border-box;
border: 1px solid #444;
border-radius: 5px;
background-color: #333;
color: #ffffff;
}
button {
padding: 15px 25px;
background: linear-gradient(90deg, red, yellow, green, cyan, blue, magenta, red);
background-size: 400% 400%;
color: #ffffff;
border: none;
border-radius: 5px;
cursor: pointer;
}
#user-info {
max-width: 400px;
margin: 20px auto;
padding: 20px;
background-color: #1a1a1a;
border-radius: 10px;
text-align: center;
}
#user-info img {
width: 100px;
height: 100px;
border-radius: 50%;
margin-bottom: 10px;
}
.repo-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
max-width: 1000px;
margin: 20px auto;
}
.repo-item {
background-color: #1a1a1a;
padding: 20px;
border: 1px solid #555;
border-radius: 5px;
color: #ffffff;
text-align: center;
}
a {
color: #61dafb;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
#file-list {
max-width: 800px;
margin: 20px auto;
}
.file-item {
background-color: #1a1a1a;
padding: 20px;
margin-bottom: 15px;
border: 1px solid #555;
border-radius: 5px;
color: #ffffff;
}
#show-more-button {
display: block;
margin: 20px auto;
padding: 10px 20px;
font-size: 18px;
font-weight: bold;
background: linear-gradient(90deg, red, yellow, green, cyan, blue, magenta, red);
background-size: 400% 400%;
color: #ffffff;
border: none;
border-radius: 5px;
cursor: pointer;
text-align: center;
}
/* Github Profile Button Styling */
.github-profile-button {
position: fixed;
bottom: 20px;
right: 20px;
padding: 10px 20px;
background-color: #333;
color: white;
font-size: 16px;
border: none;
border-radius: 5px;
text-decoration: none;
text-align: center;
cursor: pointer;
z-index: 1000;
}
.github-profile-button:hover {
background-color: #555;
}
</style>
</head>
<body>
<h1>GitPort App</h1>
<!-- Form to input GitHub repository URL -->
<form id="repo-form">
<label for="repo-url">Enter GitHub Repository URL:</label>
<input type="text" id="repo-url" name="repo-url" placeholder="https://github.com/username/repository" required>
<button type="submit">Access Files</button>
</form>
<!-- Form to input GitHub username -->
<form id="user-form">
<label for="username">Enter GitHub Username:</label>
<input type="text" id="username" name="username" placeholder="GitHub username" required>
<button type="submit">Load Repositories</button>
</form>
<!-- Section to display user information -->
<div id="user-info"></div>
<!-- Section to display file list -->
<div id="file-list"></div>
<!-- Section to display repository grid -->
<div id="repo-list" class="repo-grid"></div>
<!-- Show More Button -->
<button id="show-more-button" style="display: none;">Show More</button>
<!-- Github Profile Button -->
<a href="https://github.com/y8tireu" target="_blank" class="github-profile-button">Github Profile</a>
<script>
document.addEventListener('DOMContentLoaded', function () {
const repoForm = document.getElementById('repo-form');
const userForm = document.getElementById('user-form');
const userInfoDiv = document.getElementById('user-info');
const fileList = document.getElementById('file-list');
const repoList = document.getElementById('repo-list');
const showMoreButton = document.getElementById('show-more-button');
let currentUsername = '';
let allRepos = [];
let displayedRepos = 0;
const displayLimit = 1000;
// Handle repository URL submission
repoForm.addEventListener('submit', function (event) {
event.preventDefault();
const repoUrl = document.getElementById('repo-url').value.trim();
if (repoUrl) {
const repoInfo = parseGitHubUrl(repoUrl);
if (repoInfo) {
fetchRepoContents(repoInfo.owner, repoInfo.repo);
} else {
alert('Please enter a valid GitHub repository URL.');
}
}
});
// Parse GitHub repository URL
function parseGitHubUrl(url) {
const regex = /https?:\/\/github\.com\/([^\/]+)\/([^\/]+)(\/)?$/;
const match = url.match(regex);
return match ? { owner: match[1], repo: match[2] } : null;
}
// Fetch repository contents
function fetchRepoContents(owner, repo) {
const apiUrl = `https://api.github.com/repos/${owner}/${repo}/contents`;
fetch(apiUrl)
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error('Repository not found or access denied.');
}
})
.then(data => {
displayFiles(data);
})
.catch(error => {
alert(error.message);
});
}
// Display repository files
function displayFiles(files) {
fileList.innerHTML = ''; // Clear existing content
if (files.length === 0) {
fileList.innerHTML += '<p>No files found in this repository.</p>';
return;
}
files.forEach(file => {
const fileItem = document.createElement('div');
fileItem.classList.add('file-item');
const fileName = document.createElement('h3');
fileName.textContent = file.name;
const fileLink = document.createElement('a');
fileLink.href = file.download_url;
fileLink.textContent = 'Download File';
fileLink.download = file.name;
fileItem.appendChild(fileName);
fileItem.appendChild(fileLink);
fileList.appendChild(fileItem);
});
}
// Handle GitHub username submission
userForm.addEventListener('submit', function (event) {
event.preventDefault();
const username = document.getElementById('username').value.trim();
if (username) {
currentUsername = username;
userInfoDiv.innerHTML = '';
repoList.innerHTML = '<p>Loading repositories...</p>';
fileList.innerHTML = '';
fetchUserInfo(username);
fetchAllUserRepositories(username);
}
});
// Fetch user information
async function fetchUserInfo(username) {
const apiUrl = `https://api.github.com/users/${username}`;
try {
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error('User not found.');
}
const user = await response.json();
displayUserInfo(user);
} catch (error) {
userInfoDiv.innerHTML = `<p>Error: ${error.message}</p>`;
}
}
// Display user information
function displayUserInfo(user) {
userInfoDiv.innerHTML = `
<img src="${user.avatar_url}" alt="${user.login}'s avatar">
<h2>${user.login}</h2>
<p>${user.bio || 'No bio available.'}</p>
<p>Followers: ${user.followers} - Following: ${user.following}</p>
<p>Public Repos: ${user.public_repos}</p>
<a href="${user.html_url}" target="_blank">View GitHub Profile</a>
`;
}
// Fetch all user repositories
async function fetchAllUserRepositories(username) {
const perPage = 100; // Maximum repositories per page
let page = 1;
allRepos = [];
let repos = [];
try {
do {
const apiUrl = `https://api.github.com/users/${username}/repos?per_page=${perPage}&page=${page}`;
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error('Failed to load repositories.');
}
repos = await response.json();
allRepos = allRepos.concat(repos);
page++;
} while (repos.length === perPage);
displayRepositories();
} catch (error) {
repoList.innerHTML = `<p>Error: ${error.message}</p>`;
}
}
// Display repositories in grid
function displayRepositories() {
const reposToShow = allRepos.slice(displayedRepos, displayedRepos + displayLimit);
reposToShow.forEach(repo => {
const repoItem = document.createElement('div');
repoItem.classList.add('repo-item');
const repoName = document.createElement('h3');
repoName.textContent = repo.name;
const repoLink = document.createElement('a');
repoLink.href = repo.html_url;
repoLink.target = '_blank';
repoLink.textContent = 'View Repository';
repoItem.appendChild(repoName);
repoItem.appendChild(repoLink);
repoList.appendChild(repoItem);
});
displayedRepos += reposToShow.length;
if (displayedRepos < allRepos.length) {
showMoreButton.style.display = 'block';
} else {
showMoreButton.style.display = 'none';
}
}
// Handle "Show More" button click
showMoreButton.addEventListener('click', displayRepositories);
});
</script>
</body>
</html>