-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
228 lines (205 loc) · 7.61 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GitHub Repository Search</title>
<style>
body {
font-family: 'Roboto', sans-serif;
background-color: #202327;
color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
background-color: #2d3339;
padding: 20px;
border-radius: 15px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
width: 800px;
text-align: center;
position: relative;
border: 5.5px solid #4f5964;
max-height: 560px;
overflow-y: auto;
}
h1, h3 {
color: #f0f0f0;
}
input[type="text"] {
width: 80%;
padding: 10px;
border: 4px solid #4f5963;
border-radius: 10px;
background-color: #394047;
color: #fff;
font-size: 16px;
margin-bottom: 20px;
margin-top: 10px;
}
button {
padding: 13px 21px;
border: none;
border-radius: 10px;
background-color: #3b8ea5;
color: #f0f0f0;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
margin-left: 5px;
}
button:hover {
background-color: #41a3be;
}
.results {
margin-top: 20px;
text-align: left;
margin-left: 10px;
margin-right: 10px;
}
::placeholder {
color: #9fb2b7;
}
.repo {
margin-bottom: 10px;
padding: 10px;
border: 4px solid #4f5963;
border-radius: 10px;
background-color: #333;
}
.repo a {
color: #21d498;
text-decoration: none;
}
.repo a:hover {
text-decoration: underline;
}
.file {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
padding: 10px;
border: 4px solid #4f5963;
border-radius: 10px;
background-color: #2d3339;
}
.file-name {
flex: 1;
color: #f0f0f0;
}
.file-icons {
display: flex;
gap: 10px;
}
.file-icons a {
color: white;
text-decoration: none;
font-size: 18px;
}
.file-icons a.download {
font-size: 17px;
cursor: pointer;
}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
</head>
<body>
<div class="container">
<h1>GitHub Repository Search</h1>
<h3>𝙼𝚊𝚍𝚎 𝚋𝚢 𝚍𝚒𝚗𝚐𝚞𝚜𝚌𝚑𝚊𝚗!</h3>
<input type="text" id="repoSearch" placeholder="Search GitHub repositories...">
<button onclick="searchRepos()">Search</button> 
<br>━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
<div class="results" id="results"></div>
</div>
<script>
function searchRepos() {
const query = document.getElementById('repoSearch').value;
const resultsDiv = document.getElementById('results');
resultsDiv.innerHTML = '';
if (query) {
fetch(`https://api.github.com/search/repositories?q=${encodeURIComponent(query)}`)
.then(response => response.json())
.then(data => {
if (data.items && data.items.length) {
data.items.forEach(repo => {
const repoDiv = document.createElement('div');
repoDiv.className = 'repo';
repoDiv.innerHTML = `
<a href="#" onclick="fetchRepoFiles('${repo.full_name}', this)">${repo.name} by ${repo.owner.login}</a>
<p>${parseDescription(repo.description)}</p>
<div class="files" style="display:none;"></div>
`;
resultsDiv.appendChild(repoDiv);
});
} else {
resultsDiv.innerHTML = '<p>No repositories found.</p>';
}
})
.catch(error => {
resultsDiv.innerHTML = '<p>Error fetching repositories.</p>';
console.error('Error:', error);
});
} else {
resultsDiv.innerHTML = '<p>Please enter a search query.</p>';
}
}
function parseDescription(description) {
if (!description) return 'No description available';
// Convert URLs in description to clickable links
return description.replace(/(https?:\/\/[^\s]+)/g, url => `<a href="${url}" target="_blank">${url}</a>`);
}
function fetchRepoFiles(fullName, element) {
const filesDiv = element.parentElement.querySelector('.files');
const isVisible = filesDiv.style.display !== 'none';
if (isVisible) {
filesDiv.style.display = 'none';
return;
}
if (filesDiv.innerHTML) {
filesDiv.style.display = 'block';
return;
}
fetch(`https://api.github.com/repos/${fullName}/contents`)
.then(response => response.json())
.then(files => {
files.forEach(file => {
const fileDiv = document.createElement('div');
fileDiv.className = 'file';
fileDiv.innerHTML = `
<span class="file-name">${file.name}</span>
<div class="file-icons">
<a href="${file.html_url}" target="_blank" class="github"><i class="fab fa-github"></i></a>
<a class="download" onclick="downloadFile('${file.download_url}', '${file.name}')"><i class="fas fa-download"></i></a>
</div>
`;
filesDiv.appendChild(fileDiv);
});
filesDiv.style.display = 'block';
})
.catch(error => {
console.error('Error fetching files:', error);
});
}
function downloadFile(url, filename) {
fetch(url)
.then(response => response.text())
.then(data => {
const blob = new Blob([data], { type: 'text/plain' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
})
.catch(error => console.error('Error downloading file:', error));
}
</script>
</body>
</html>