-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
255 lines (230 loc) · 8.49 KB
/
index.html
File metadata and controls
255 lines (230 loc) · 8.49 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Signature Assets Manager</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 1000px;
margin: 40px auto;
padding: 0 20px;
background: #f9fafb;
}
.section {
margin: 40px 0;
}
.assets-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 20px;
margin: 20px 0;
}
.asset {
background: white;
border: 1px solid #e5e7eb;
padding: 20px;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.private-asset {
background: #f8fafc;
border: 1px solid #e5e7eb;
padding: 15px;
border-radius: 8px;
margin-bottom: 10px;
}
.asset img {
max-width: 100%;
height: auto;
margin-bottom: 15px;
border: 1px solid #e5e7eb;
border-radius: 4px;
}
.url {
background: #f5f5f5;
padding: 10px;
border-radius: 4px;
word-break: break-all;
font-size: 14px;
margin: 10px 0;
}
.url code {
color: #4a5568;
}
.copy-btn {
background: #4f46e5;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
transition: background 0.2s;
}
.copy-btn:hover {
background: #4338ca;
}
.copy-btn:active {
transform: translateY(1px);
}
.copy-btn.copied {
background: #059669;
}
.meta {
font-size: 14px;
color: #6b7280;
margin-top: 10px;
}
.loading {
text-align: center;
padding: 40px;
color: #6b7280;
}
.private-section {
background: #f8fafc;
padding: 20px;
border-radius: 8px;
border: 1px solid #e5e7eb;
}
</style>
</head>
<body>
<h1>Signature Assets Manager</h1>
<!-- Public Assets Section -->
<div class="section">
<h2>Public Assets</h2>
<div id="public-assets" class="assets-grid">
<div class="loading">Loading assets...</div>
</div>
</div>
<!-- Private Assets Section -->
<div class="section">
<h2>Private Assets</h2>
<div id="private-assets" class="private-section">
<div class="loading">Loading assets...</div>
</div>
</div>
<script>
async function fetchRepoContents() {
const username = window.location.hostname.split('.')[0];
const repoName = window.location.pathname.split('/')[1];
const assetsPath = 'assets';
const apiUrl = `https://api.github.com/repos/${username}/${repoName}/contents/${assetsPath}`;
try {
const response = await fetch(apiUrl);
const data = await response.json();
return data.filter(file =>
file.type === 'file' &&
/\.(jpg|jpeg|png|gif|svg)$/i.test(file.name)
);
} catch (error) {
console.error('Error fetching repo contents:', error);
return [];
}
}
function formatBytes(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
function isBase64Name(filename) {
// Check if the filename (without extension) is base64 encoded
const nameWithoutExt = filename.split('.').slice(0, -1).join('.');
try {
return /^[A-Za-z0-9+/]+=*$/.test(nameWithoutExt) &&
nameWithoutExt.length % 4 === 0;
} catch {
return false;
}
}
function createPublicAssetElement(file) {
const assetDiv = document.createElement('div');
assetDiv.className = 'asset';
const fileName = document.createElement('h3');
fileName.textContent = file.name;
const img = document.createElement('img');
img.src = file.download_url;
img.alt = file.name;
const url = document.createElement('div');
url.className = 'url';
url.innerHTML = `<code>${file.download_url}</code>`;
const copyBtn = document.createElement('button');
copyBtn.className = 'copy-btn';
copyBtn.textContent = 'Copy URL';
copyBtn.onclick = async () => {
await navigator.clipboard.writeText(file.download_url);
copyBtn.textContent = 'Copied!';
copyBtn.classList.add('copied');
setTimeout(() => {
copyBtn.textContent = 'Copy URL';
copyBtn.classList.remove('copied');
}, 2000);
};
const meta = document.createElement('div');
meta.className = 'meta';
meta.textContent = `Size: ${formatBytes(file.size)}`;
assetDiv.append(fileName, img, url, copyBtn, meta);
return assetDiv;
}
function createPrivateAssetElement(file) {
const assetDiv = document.createElement('div');
assetDiv.className = 'private-asset';
const url = document.createElement('div');
url.className = 'url';
url.innerHTML = `<code>${file.download_url}</code>`;
const copyBtn = document.createElement('button');
copyBtn.className = 'copy-btn';
copyBtn.textContent = 'Copy URL';
copyBtn.onclick = async () => {
await navigator.clipboard.writeText(file.download_url);
copyBtn.textContent = 'Copied!';
copyBtn.classList.add('copied');
setTimeout(() => {
copyBtn.textContent = 'Copy URL';
copyBtn.classList.remove('copied');
}, 2000);
};
const meta = document.createElement('div');
meta.className = 'meta';
meta.textContent = `Size: ${formatBytes(file.size)}`;
assetDiv.append(url, copyBtn, meta);
return assetDiv;
}
async function initializeAssetManager() {
const publicContainer = document.getElementById('public-assets');
const privateContainer = document.getElementById('private-assets');
const files = await fetchRepoContents();
if (files.length === 0) {
publicContainer.innerHTML = '<div class="loading">No assets found. Add images to the assets folder.</div>';
privateContainer.innerHTML = '<div class="loading">No private assets found.</div>';
return;
}
publicContainer.innerHTML = '';
privateContainer.innerHTML = '';
let hasPublic = false;
let hasPrivate = false;
files.forEach(file => {
if (isBase64Name(file.name)) {
hasPrivate = true;
privateContainer.appendChild(createPrivateAssetElement(file));
} else {
hasPublic = true;
publicContainer.appendChild(createPublicAssetElement(file));
}
});
if (!hasPublic) {
publicContainer.innerHTML = '<div class="loading">No public assets found.</div>';
}
if (!hasPrivate) {
privateContainer.innerHTML = '<div class="loading">No private assets found.</div>';
}
}
// Initialize when page loads
initializeAssetManager();
</script>
</body>
</html>