-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
473 lines (435 loc) · 23.1 KB
/
Copy pathadmin.html
File metadata and controls
473 lines (435 loc) · 23.1 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
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin - Ziploot Link Manager</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Syne:wght@700;800&family=Space+Mono&display=swap" rel="stylesheet">
<style>
:root {
--bg: #070913;
--card-bg: rgba(13, 17, 39, 0.4);
--border: rgba(255, 255, 255, 0.05);
--border-focus: #818cf8;
--primary: #818cf8;
--primary-hover: #6366f1;
--success: #10b981;
--success-hover: #059669;
--danger: #ef4444;
--danger-bg: rgba(239, 68, 68, 0.1);
--text: #cbd5e1;
--text-muted: #64748b;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
background: var(--bg);
color: var(--text);
font-family: 'Inter', sans-serif;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: flex-start;
padding: 40px 20px;
}
.container { width: 100%; max-width: 760px; margin: 0 auto; }
header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
border-bottom: 1px solid var(--border);
padding-bottom: 20px;
}
h1 { font-family: 'Syne', sans-serif; color: #fff; font-size: 22px; font-weight: 800; letter-spacing: -0.5px; }
.card {
background: var(--card-bg);
border: 1px solid var(--border);
border-radius: 20px;
padding: 30px;
margin-bottom: 24px;
backdrop-filter: blur(20px);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
h2 { font-family: 'Syne', sans-serif; font-size: 16px; margin-bottom: 18px; color: #fff; display: flex; align-items: center; gap: 8px; }
.wizard-card {
text-align: center;
padding: 40px 30px;
border: 1px solid rgba(129, 140, 248, 0.15);
}
.wizard-logo { font-size: 40px; margin-bottom: 15px; }
.wizard-desc { font-size: 14px; color: var(--text-muted); line-height: 1.6; margin-bottom: 25px; max-width: 500px; margin-left: auto; margin-right: auto; }
label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 8px; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.5px; }
input {
width: 100%;
padding: 14px 16px;
background: rgba(0, 0, 0, 0.3);
border: 1px solid var(--border);
border-radius: 10px;
color: #fff;
font-family: 'Inter', sans-serif;
font-size: 14px;
margin-bottom: 20px;
transition: all 0.2s ease;
}
input:focus { border-color: var(--border-focus); outline: none; box-shadow: 0 0 10px rgba(129, 140, 248, 0.15); }
input::placeholder { color: #475569; }
.btn {
padding: 14px 28px;
border-radius: 10px;
border: none;
font-family: 'Syne', sans-serif;
font-weight: 700;
font-size: 14px;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
transition: all 0.2s ease;
width: 100%;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-hover); transform: translateY(-1px); }
.btn-danger { background: var(--danger-bg); color: var(--danger); padding: 8px 16px; font-size: 12px; border-radius: 8px; font-family: 'Inter', sans-serif; font-weight: 600; width: auto; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.2); }
.link-row { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid var(--border); gap: 15px; min-width: 0; }
.link-row:last-child { border-bottom: none; }
.link-details { min-width: 0; flex: 1; }
.link-slug { font-family: 'Space Mono', monospace; font-weight: 700; color: #fff; font-size: 15px; margin-bottom: 4px; }
.link-dest { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-dest a { color: var(--primary); text-decoration: none; }
.link-dest a:hover { text-decoration: underline; }
.settings-header { cursor: pointer; display: flex; justify-content: space-between; align-items: center; padding: 10px 0; }
.settings-body { display: none; margin-top: 20px; border-top: 1px solid var(--border); padding-top: 20px; }
.settings-body.active { display: block; }
.live-link-tip { font-size: 12px; color: var(--success); margin-top: -12px; margin-bottom: 20px; font-family: 'Space Mono', monospace; }
.warning-msg { background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.2); border-radius: 10px; padding: 12px 16px; font-size: 13px; color: var(--danger); margin-bottom: 20px; display: none; }
.loading-spinner { border: 2px solid rgba(255,255,255,0.2); border-radius: 50%; border-top: 2px solid #fff; width: 16px; height: 16px; animation: spin 0.8s linear infinite; display: none; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
</style>
</head>
<body>
<!-- ZipLoot Official Brand Header -->
<div id="ziploot-official-bar" style="position: fixed !important; top: 0 !important; left: 0 !important; right: 0 !important; width: 100% !important; min-height: 38px !important; z-index: 9999999 !important; background: linear-gradient(90deg, #0f172a 0%, #1e1b4b 100%) !important; border-bottom: 1px solid rgba(99, 102, 241, 0.4) !important; padding: 8px 16px !important; text-align: center !important; font-family: system-ui, -apple-system, sans-serif !important; font-size: 13.5px !important; font-weight: 600 !important; color: #f8fafc !important; display: flex !important; align-items: center !important; justify-content: center !important; gap: 12px !important; flex-wrap: wrap !important; box-shadow: 0 4px 14px rgba(0,0,0,0.5) !important; box-sizing: border-box !important;">
<span>🚀 Official Portal: <a href="https://ziploot.app" target="_blank" rel="noopener" style="color: #818cf8 !important; text-decoration: none !important; font-weight: 700 !important; border-bottom: 1px solid #818cf8 !important;">ziploot.app</a></span>
<span style="color: #64748b !important;">•</span>
<span>Ecosystem Mirror: <a href="https://ziploot.vercel.app" target="_blank" rel="noopener" style="color: #38bdf8 !important; text-decoration: none !important; font-weight: 600 !important;">ziploot.vercel.app</a></span>
</div>
<div class="container">
<header>
<h1>⚡ ZIPLOOT LINK MANAGER</h1>
<button class="btn btn-danger" id="logoutBtn" style="padding: 8px 16px; display: none;" onclick="deactivateManager()">Lock Admin</button>
</header>
<div class="card wizard-card" id="wizardSection">
<div class="wizard-logo">🔑</div>
<h2>Activate Your Link Manager</h2>
<p class="wizard-desc">Enter your GitHub Personal Access Token (PAT) to start creating and managing short links.</p>
<label style="text-align: left;">GitHub Personal Access Token (PAT)</label>
<input type="password" id="wizardPat" placeholder="Paste your ghp_... token here" />
<button class="btn btn-primary" onclick="activateManager()">Activate Manager</button>
<p style="font-size: 12px; margin-top: 15px; color: var(--text-muted); line-height: 1.6;">
Don't have a token? <a href="https://github.com/settings/tokens/new?description=Ziploot%20Link%20Manager&scopes=public_repo" target="_blank" style="color: var(--primary);">Create a Classic Token</a> (check <strong>"public_repo"</strong>).<br>
If using a <strong>Fine-grained Token</strong>, select "All Repositories" and grant <strong>"Contents: Read & Write"</strong> permission.
</p>
</div>
<div id="dashboardSection" style="display: none;">
<div class="card">
<h2>🔗 Create New Short Link</h2>
<div style="display: grid; grid-template-columns: 1fr 2fr; gap: 15px;">
<div>
<label>Short Path (Slug)</label>
<input type="text" id="newSlug" placeholder="e.g. fb" oninput="updateLiveLinkTip()" />
</div>
<div>
<label>Destination URL</label>
<input type="text" id="newUrl" placeholder="https://facebook.com/..." />
</div>
</div>
<div class="live-link-tip" id="liveLinkTip">Short Link: https://your-username.github.io/slug</div>
<button class="btn btn-success" id="createBtn" onclick="addLink()">
<span class="loading-spinner" id="createSpinner"></span>
<span>Shorten & Save Link</span>
</button>
</div>
<div class="card">
<h2>📂 Active Redirects</h2>
<div id="linksContainer">
<div style="text-align:center; padding:20px; color:var(--text-muted); font-size:14px;">Loading...</div>
</div>
</div>
<div class="card">
<div class="settings-header" onclick="toggleSettings()">
<h2>⚙️ Click Analytics Settings (Optional)</h2>
<span id="settingsArrow" style="font-size: 18px; color: var(--text-muted);">▼</span>
</div>
<div class="settings-body" id="settingsBody">
<p style="font-size: 13px; color: var(--text-muted); margin-bottom: 20px; line-height: 1.5;">
To log click events (IP, country, browser) in a Google Sheet for free, paste your Google Form Pre-filled Link below.
</p>
<div class="warning-msg" id="linkWarning">
⚠️ This looks like a Google Sheet URL. Please paste a <strong>Google Form pre-filled link</strong> instead.
</div>
<label style="color: var(--success); font-weight: 700;">🚀 Google Form Pre-filled Link</label>
<input type="text" id="prefilledLink" placeholder="Paste your entry-populated Google Form link..." oninput="autoParseLink()" />
<div style="opacity: 0.6; pointer-events: none;">
<label>Google Form ID</label>
<input type="text" id="formId" placeholder="Parsed Form ID" tabindex="-1" />
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px;">
<div><label>Slug Entry ID</label><input type="text" id="entrySlug" placeholder="Parsed Slug ID" tabindex="-1" /></div>
<div><label>IP Entry ID</label><input type="text" id="entryIp" placeholder="Parsed IP ID" tabindex="-1" /></div>
</div>
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px;">
<div><label>Country Entry ID</label><input type="text" id="entryCountry" placeholder="Parsed Country ID" tabindex="-1" /></div>
<div><label>UserAgent Entry ID</label><input type="text" id="entryUa" placeholder="Parsed UA ID" tabindex="-1" /></div>
</div>
</div>
<button class="btn btn-primary" id="saveConfigBtn" onclick="saveAnalyticsConfig()">Save Analytics Configuration</button>
</div>
</div>
</div>
</div>
<script>
let redirects = {};
let repoSha = "";
// Auto-configured owner and repository (hardcoded by installer)
let owner = "Ziploot";
let repo = "Ziploot.github.io";
const savedPat = localStorage.getItem("GITHUB_PAT");
if (savedPat) showDashboard();
function activateManager() {
const pat = document.getElementById("wizardPat").value.trim();
if (!pat) { alert("Please enter your GitHub PAT."); return; }
localStorage.setItem("GITHUB_PAT", pat);
showDashboard();
}
function deactivateManager() {
localStorage.removeItem("GITHUB_PAT");
document.getElementById("wizardPat").value = "";
document.getElementById("wizardSection").style.display = "block";
document.getElementById("dashboardSection").style.display = "none";
document.getElementById("logoutBtn").style.display = "none";
}
function showDashboard() {
document.getElementById("wizardSection").style.display = "none";
document.getElementById("dashboardSection").style.display = "block";
document.getElementById("logoutBtn").style.display = "block";
// Fallback pre-population from localStorage
document.getElementById("prefilledLink").value = localStorage.getItem("PREFILLED_LINK") || "";
document.getElementById("formId").value = localStorage.getItem("GOOGLE_FORM_ID") || "";
document.getElementById("entrySlug").value = localStorage.getItem("ENTRY_SLUG") || "";
document.getElementById("entryIp").value = localStorage.getItem("ENTRY_IP") || "";
document.getElementById("entryCountry").value = localStorage.getItem("ENTRY_COUNTRY") || "";
document.getElementById("entryUa").value = localStorage.getItem("ENTRY_UA") || "";
updateLiveLinkTip();
loadRedirects();
}
function updateLiveLinkTip() {
const slug = document.getElementById("newSlug").value.trim().toLowerCase() || "slug";
document.getElementById("liveLinkTip").textContent = "Short Link: https://" + owner + ".github.io/" + slug;
}
function toggleSettings() {
const body = document.getElementById("settingsBody");
const arrow = document.getElementById("settingsArrow");
body.classList.toggle("active");
arrow.innerHTML = body.classList.contains("active") ? "▲" : "▼";
}
function autoParseLink() {
const urlString = document.getElementById("prefilledLink").value.trim();
const warning = document.getElementById("linkWarning");
warning.style.display = "none";
if (!urlString) return;
if (urlString.includes("spreadsheets/d/")) { warning.style.display = "block"; return; }
try {
const url = new URL(urlString);
const pathParts = url.pathname.split('/');
const eIndex = pathParts.indexOf('e');
if (eIndex !== -1 && pathParts[eIndex + 1]) {
document.getElementById("formId").value = pathParts[eIndex + 1];
}
const params = new URLSearchParams(url.search);
for (const [key, value] of params.entries()) {
if (key.startsWith("entry.")) {
const entryId = key.substring(6);
const val = value.toLowerCase().trim();
if (val === "slug") document.getElementById("entrySlug").value = entryId;
else if (val === "ip") document.getElementById("entryIp").value = entryId;
else if (val === "country") document.getElementById("entryCountry").value = entryId;
else if (val === "ua" || val === "useragent") document.getElementById("entryUa").value = entryId;
}
}
} catch (e) {}
}
async function saveAnalyticsConfig() {
const formId = document.getElementById("formId").value.trim();
const entrySlug = document.getElementById("entrySlug").value.trim();
const entryIp = document.getElementById("entryIp").value.trim();
const entryCountry = document.getElementById("entryCountry").value.trim();
const entryUa = document.getElementById("entryUa").value.trim();
const prefilled = document.getElementById("prefilledLink").value.trim();
if (!formId || !entrySlug || !entryIp || !entryCountry || !entryUa) {
alert("Please paste a valid Google Form Pre-filled link so it can parse entry IDs.");
return;
}
// Store in redirects map under the special key '_config'
redirects["_config"] = {
formId: formId,
entrySlug: entrySlug,
entryIp: entryIp,
entryCountry: entryCountry,
entryUa: entryUa,
prefilledLink: prefilled
};
// Backup locally
localStorage.setItem("PREFILLED_LINK", prefilled);
localStorage.setItem("GOOGLE_FORM_ID", formId);
localStorage.setItem("ENTRY_SLUG", entrySlug);
localStorage.setItem("ENTRY_IP", entryIp);
localStorage.setItem("ENTRY_COUNTRY", entryCountry);
localStorage.setItem("ENTRY_UA", entryUa);
const btn = document.getElementById("saveConfigBtn");
const originalText = btn.textContent;
btn.textContent = "Saving to GitHub...";
btn.disabled = true;
await commitToGitHub("Update Analytics Configuration");
btn.textContent = originalText;
btn.disabled = false;
alert("Analytics configuration saved and synced to GitHub! It works for all visitors now.");
}
async function loadRedirects() {
// 1. Fetch local redirects first to show the table instantly (even without token or when logged out)
try {
const res = await fetch('redirects.json?v=' + Date.now());
if (res.ok) {
redirects = await res.json();
renderTable();
}
} catch (e) {
console.warn("Could not fetch local redirects.json", e);
}
// 2. Fetch from GitHub API if token exists to get the latest version (bypassing caching) and SHA
const pat = localStorage.getItem("GITHUB_PAT");
if (pat) {
try {
const metaRes = await fetch("https://api.github.com/repos/" + owner + "/" + repo + "/contents/redirects.json", {
headers: { "Authorization": "token " + pat, "Cache-Control": "no-cache" }
});
if (metaRes.ok) {
const meta = await metaRes.json();
repoSha = meta.sha;
const content = atob(meta.content.replace(/\r?\n/g, ""));
redirects = JSON.parse(content);
// If GitHub has a config, update the UI input fields
if (redirects._config) {
const conf = redirects._config;
document.getElementById("prefilledLink").value = conf.prefilledLink || "";
document.getElementById("formId").value = conf.formId || "";
document.getElementById("entrySlug").value = conf.entrySlug || "";
document.getElementById("entryIp").value = conf.entryIp || "";
document.getElementById("entryCountry").value = conf.entryCountry || "";
document.getElementById("entryUa").value = conf.entryUa || "";
// Backup in localStorage
localStorage.setItem("PREFILLED_LINK", conf.prefilledLink || "");
localStorage.setItem("GOOGLE_FORM_ID", conf.formId || "");
localStorage.setItem("ENTRY_SLUG", conf.entrySlug || "");
localStorage.setItem("ENTRY_IP", conf.entryIp || "");
localStorage.setItem("ENTRY_COUNTRY", conf.entryCountry || "");
localStorage.setItem("ENTRY_UA", conf.entryUa || "");
}
renderTable();
} else if (metaRes.status === 401 || metaRes.status === 403 || metaRes.status === 404) {
document.getElementById("linksContainer").innerHTML = '<div style="text-align:center;padding:20px;color:var(--danger)">Access Denied. Check your GitHub PAT permissions.</div>';
}
} catch (e) {
console.error("Could not fetch redirects.json from GitHub API", e);
}
}
}
function renderTable() {
const container = document.getElementById("linksContainer");
container.innerHTML = "";
// Filter out _config key so it doesn't show in the user's redirects list
const keys = Object.keys(redirects).filter(k => k !== "_config");
if (keys.length === 0) {
container.innerHTML = '<div style="text-align:center;padding:20px;color:var(--text-muted);font-size:14px;">No short links yet. Create one above!</div>';
return;
}
keys.forEach(slug => {
const row = document.createElement("div");
row.className = "link-row";
const shortUrl = "https://" + owner + ".github.io/" + slug;
row.innerHTML = `
<div class="link-details">
<div class="link-slug">/${slug}</div>
<div class="link-dest">Redirects to: <a href="${redirects[slug]}" target="_blank">${redirects[slug]}</a></div>
<div style="font-size:11px;color:var(--text-muted);margin-top:2px;">
Short link: <a href="${shortUrl}" target="_blank" style="color:var(--success);">${shortUrl}</a>
</div>
</div>
<button class="btn btn-danger" onclick="deleteLink('${slug}')">Delete</button>
`;
container.appendChild(row);
});
}
async function addLink() {
const slug = document.getElementById("newSlug").value.trim().toLowerCase();
const url = document.getElementById("newUrl").value.trim();
const pat = localStorage.getItem("GITHUB_PAT");
if (!slug || !url || !pat) { alert("Please fill in both the Short Path and Destination URL."); return; }
if (slug === "_config") { alert("The slug name '_config' is reserved for system settings."); return; }
if (!url.startsWith("http://") && !url.startsWith("https://")) { alert("URL must start with http:// or https://"); return; }
document.getElementById("createSpinner").style.display = "inline-block";
document.getElementById("createBtn").disabled = true;
redirects[slug] = url;
await commitToGitHub("Add short link /" + slug);
document.getElementById("createSpinner").style.display = "none";
document.getElementById("createBtn").disabled = false;
document.getElementById("newSlug").value = "";
document.getElementById("newUrl").value = "";
updateLiveLinkTip();
}
async function deleteLink(slug) {
if (confirm("Delete redirect /" + slug + "?")) {
delete redirects[slug];
await commitToGitHub("Delete short link /" + slug);
}
}
async function commitToGitHub(message, attempt) {
if (attempt === undefined) attempt = 0;
const pat = localStorage.getItem("GITHUB_PAT");
const contentBase64 = btoa(unescape(encodeURIComponent(JSON.stringify(redirects, null, 2))));
const res = await fetch("https://api.github.com/repos/" + owner + "/" + repo + "/contents/redirects.json", {
method: "PUT",
headers: { "Authorization": "token " + pat, "Content-Type": "application/json" },
body: JSON.stringify({ message: message, content: contentBase64, sha: repoSha })
});
if (res.ok) {
const responseData = await res.json();
repoSha = responseData.content.sha; // store fresh SHA from response
renderTable();
} else if (attempt < 2) {
// SHA mismatch or stale — silently fetch fresh SHA and retry
try {
const shaRes = await fetch(
"https://api.github.com/repos/" + owner + "/" + repo + "/contents/redirects.json?_=" + Date.now(),
{ headers: { "Authorization": "token " + pat } }
);
if (shaRes.ok) {
const shaData = await shaRes.json();
repoSha = shaData.sha;
// Merge: keep all remote entries + config + add our new ones
const remoteContent = JSON.parse(atob(shaData.content.replace(/\r?\n/g, "")));
redirects = Object.assign({}, remoteContent, redirects);
}
} catch (e) {}
return commitToGitHub(message, attempt + 1); // retry silently
} else {
const err = await res.json().catch(() => ({ message: "Unknown error" }));
alert("Error saving: " + err.message + "\nPlease refresh the page and try again.");
await loadRedirects();
}
}
</script>
</body>
</html>