-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-button-generator.html
More file actions
470 lines (424 loc) · 18.3 KB
/
github-button-generator.html
File metadata and controls
470 lines (424 loc) · 18.3 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
<!DOCTYPE html>
<html lang="en" class="neo-landing-root">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>GitHub Button Generator</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="./github-tools-common.css" />
<link rel="stylesheet" href="./github-tools-neo.css" />
</head>
<body class="neo-landing page-button-generator">
<div class="wrap">
<section class="tool-hero">
<div class="tool-kicker">GitHub Tools Suite</div>
<h1>GitHub Button Generator</h1>
<p>Create clickable Shields.io badge buttons for README files, issue-template links, resource pages, and repo navigation.</p>
</section>
<div class="tool-grid">
<section class="card">
<div class="card-header">
<div class="title-row">
<div>
<h2>Button settings</h2>
<p class="sub">Configure badge text, colors, logo options, and output format.</p>
</div>
<button class="btn" id="resetBtn" type="button">Reset</button>
</div>
</div>
<div class="card-content layout-stack">
<div class="form-grid">
<div class="stack">
<div class="toggle-row">
<div>
<label for="singleSegment">Single text badge</label>
<p class="hint">Turn this on for one continuous label like “Submit Template”.</p>
</div>
<label class="toggle">
<input id="singleSegment" type="checkbox" checked />
<span class="slider"></span>
</label>
</div>
<div class="field">
<label for="leftText">Badge text</label>
<input id="leftText" type="text" value="📁 Suggest Category" />
</div>
<div class="field hidden" id="rightTextWrap">
<label for="rightText">Right segment text</label>
<input id="rightText" type="text" value="Template" />
</div>
<div class="field">
<label for="altText">Alt text</label>
<input id="altText" type="text" value="📁 Suggest Category" />
</div>
<div class="field">
<label for="targetUrl">Target URL</label>
<input id="targetUrl" type="text" value="https://github.com/monapdx/90s-collage-maker/issues/new?template=suggest-category.yml" />
</div>
<div class="field">
<label>Emoji picker</label>
<div class="chip-row" id="emojiPicker"></div>
<p class="hint">Click an emoji to add it to the badge text field.</p>
</div>
</div>
<div class="stack">
<div class="mini-grid">
<div class="field">
<label for="style">Style</label>
<select id="style">
<option value="for-the-badge" selected>for-the-badge</option>
<option value="flat">flat</option>
<option value="flat-square">flat-square</option>
<option value="plastic">plastic</option>
<option value="social">social</option>
</select>
</div>
<div class="field">
<label for="color">Color</label>
<input id="color" class="input-hex" type="text" value="8a2be2" placeholder="8a2be2 or pink" />
</div>
</div>
<div class="field">
<label>Quick colors</label>
<div class="chip-row" id="colorChips"></div>
</div>
<div class="field">
<label for="logo">Logo slug</label>
<input id="logo" type="text" value="" placeholder="github, markdown, discord" />
</div>
<div class="mini-grid">
<div class="field">
<label for="logoColor">Logo color</label>
<input id="logoColor" class="input-hex" type="text" value="" placeholder="ffffff" />
</div>
<div class="field">
<label for="labelColor">Label color</label>
<input id="labelColor" class="input-hex" type="text" value="" placeholder="222222" />
</div>
</div>
</div>
</div>
<div class="field">
<label>Preview</label>
<div class="preview-box">
<a id="previewLink" href="#" target="_blank" rel="noreferrer">
<img id="previewImg" alt="Badge preview" src="" />
</a>
</div>
</div>
<div>
<div class="tabs">
<button class="tab active" data-tab="markdown" type="button">Markdown</button>
<button class="tab" data-tab="html" type="button">HTML</button>
<button class="tab" data-tab="url" type="button">Badge URL</button>
<button class="tab" data-tab="plain-link" type="button">Plain Link</button>
</div>
<div class="tab-panel active" id="panel-markdown">
<div class="code-box">
<div class="field">
<label for="markdownOutput">Markdown output</label>
<textarea id="markdownOutput" readonly></textarea>
</div>
<div class="copy-row">
<button class="btn accent" type="button" data-copy="markdownOutput">Copy Markdown</button>
</div>
</div>
</div>
<div class="tab-panel" id="panel-html">
<div class="code-box">
<div class="field">
<label for="htmlOutput">HTML output</label>
<textarea id="htmlOutput" readonly></textarea>
</div>
<div class="copy-row">
<button class="btn accent" type="button" data-copy="htmlOutput">Copy HTML</button>
</div>
</div>
</div>
<div class="tab-panel" id="panel-url">
<div class="code-box">
<div class="field">
<label for="urlOutput">Badge image URL</label>
<textarea id="urlOutput" readonly></textarea>
</div>
<div class="copy-row">
<button class="btn accent" type="button" data-copy="urlOutput">Copy URL</button>
</div>
</div>
</div>
<div class="tab-panel" id="panel-plain-link">
<div class="code-box layout-stack">
<div class="mini-grid">
<div class="field">
<label for="plainLinkText">Link text</label>
<input id="plainLinkText" type="text" value="Suggest Category" />
</div>
<div class="field">
<label for="plainLinkUrl">Link URL</label>
<input id="plainLinkUrl" type="text" value="https://github.com/monapdx/90s-collage-maker/issues/new?template=suggest-category.yml" />
</div>
</div>
<div class="field">
<label for="plainLinkOutput">Plain Markdown link</label>
<textarea id="plainLinkOutput" readonly></textarea>
</div>
<div class="copy-row">
<button class="btn accent" type="button" data-copy="plainLinkOutput">Copy Plain Link</button>
</div>
</div>
</div>
</div>
</div>
</section>
<aside class="layout-stack">
<section class="card">
<div class="card-header">
<h2>Example buttons</h2>
<p class="sub">These match the sort of clickable GitHub badges you showed.</p>
</div>
<div class="card-content example-stack">
<div class="example">
<img alt="Suggest Category" src="https://img.shields.io/badge/%F0%9F%93%81%20Suggest%20Category-8a2be2?style=for-the-badge" />
</div>
<div class="example">
<img alt="Submit Template" src="https://img.shields.io/badge/Submit%20Template-pink?style=for-the-badge" />
</div>
</div>
</section>
<section class="card">
<div class="card-header">
<h2>Tips</h2>
</div>
<div class="card-content tip-stack">
<ul class="tips">
<li>Use a single text badge for one continuous label like “Submit Template”.</li>
<li>Turn single text off if you want a two-part badge with separate left and right segments.</li>
<li>Logo slugs usually come from Simple Icons, like <code>github</code>, <code>discord</code>, or <code>markdown</code>.</li>
<li>The Markdown output is ready to paste straight into a README.</li>
</ul>
<p class="footer-note">This is a standalone HTML file with no frameworks or build tools required.</p>
</div>
</section>
</aside>
</div>
</div>
<script>
const COLORS = [
{ name: "Pink", value: "ff69b4" },
{ name: "Purple", value: "8a2be2" },
{ name: "Hot Pink", value: "ed0d92" },
{ name: "Blue", value: "1f6feb" },
{ name: "Green", value: "2ea44f" },
{ name: "Red", value: "d73a49" },
{ name: "Orange", value: "f59e0b" },
{ name: "Black", value: "111111" },
{ name: "Gray", value: "6b7280" }
];
const EMOJIS = [
"📁","✨","📝","📌","💖","🔥","🎀","🧩","🛠️","📚","🎨","🚀","💡","⭐","🔗","🗂️","📎","💬","✅","🎉",
"❓", /* question mark / help */
"👉", /* finger pointing right */
"📖", /* open book */
"🔍", /* search */
"🛒", /* shopping cart */
"⬇️", /* download */
"📋", /* forms */
"🔔", /* notification */
"📧", /* email */
"⚠️", /* alert / warning */
"💊", /* pill */
"💰","💸","🪙", /* money */
"🩺","🏥","⚕️","💉", /* healthcare */
"✈️","🌍","🧳", /* travel */
"📣","✊","🗳️","⚖️", /* activism/politics */
"📱","☎️", /* phone */
"⚖️","📜","🏛️", /* legal/law */
"📊","📈","📉","🧮", /* data/stats */
"🔒","🛡️","🕶️", /* privacy/safety */
"🎙️","🎧", /* podcasts */
"🎬","🍿" /* films */
];
const els = {
singleSegment: document.getElementById("singleSegment"),
leftText: document.getElementById("leftText"),
rightText: document.getElementById("rightText"),
rightTextWrap: document.getElementById("rightTextWrap"),
altText: document.getElementById("altText"),
targetUrl: document.getElementById("targetUrl"),
style: document.getElementById("style"),
color: document.getElementById("color"),
logo: document.getElementById("logo"),
logoColor: document.getElementById("logoColor"),
labelColor: document.getElementById("labelColor"),
previewLink: document.getElementById("previewLink"),
previewImg: document.getElementById("previewImg"),
markdownOutput: document.getElementById("markdownOutput"),
htmlOutput: document.getElementById("htmlOutput"),
urlOutput: document.getElementById("urlOutput"),
colorChips: document.getElementById("colorChips"),
emojiPicker: document.getElementById("emojiPicker"),
plainLinkText: document.getElementById("plainLinkText"),
plainLinkUrl: document.getElementById("plainLinkUrl"),
plainLinkOutput: document.getElementById("plainLinkOutput"),
resetBtn: document.getElementById("resetBtn")
};
const defaults = {
singleSegment: true,
leftText: "📁 Suggest Category",
rightText: "Template",
altText: "📁 Suggest Category",
targetUrl: "https://github.com/monapdx/90s-collage-maker/issues/new?template=suggest-category.yml",
style: "for-the-badge",
color: "8a2be2",
logo: "",
logoColor: "",
labelColor: "",
plainLinkText: "Suggest Category",
plainLinkUrl: "https://github.com/monapdx/90s-collage-maker/issues/new?template=suggest-category.yml"
};
function encodeSegment(text) {
return encodeURIComponent(text || "").replace(/%20/g, "%20");
}
function cleanColor(value) {
const trimmed = (value || "").trim();
if (!trimmed) return "8a2be2";
return trimmed.replace(/^#/, "");
}
function buildBadgeUrl() {
const single = els.singleSegment.checked;
const left = els.leftText.value.trim() || "Button";
const right = els.rightText.value.trim() || "Label";
const color = cleanColor(els.color.value);
const params = new URLSearchParams();
if (els.style.value) params.set("style", els.style.value);
if (els.logo.value.trim()) params.set("logo", els.logo.value.trim());
if (els.logoColor.value.trim()) params.set("logoColor", cleanColor(els.logoColor.value));
if (els.labelColor.value.trim()) params.set("labelColor", cleanColor(els.labelColor.value));
const query = params.toString();
if (single) {
const segment = encodeSegment(left);
return `https://img.shields.io/badge/${segment}-${color}${query ? `?${query}` : ""}`;
}
return `https://img.shields.io/badge/${encodeSegment(left)}-${encodeSegment(right)}-${color}${query ? `?${query}` : ""}`;
}
function buildMarkdown(badgeUrl) {
const alt = els.altText.value.trim() || els.leftText.value.trim() || "Badge";
const target = els.targetUrl.value.trim() || "https://github.com/";
return `[](${target})`;
}
function buildHtml(badgeUrl) {
const alt = escapeHtml(els.altText.value.trim() || els.leftText.value.trim() || "Badge");
const target = escapeHtml(els.targetUrl.value.trim() || "https://github.com/");
return `<a href="${target}"><img alt="${alt}" src="${badgeUrl}" /></a>`;
}
function buildPlainMarkdownLink() {
const text = (els.plainLinkText.value || "Link").trim();
const url = (els.plainLinkUrl.value || "https://github.com/").trim();
return `[${text}](${url})`;
}
function escapeHtml(str) {
return str
.replaceAll("&", "&")
.replaceAll("\"", """)
.replaceAll("<", "<")
.replaceAll(">", ">");
}
function updateRightField() {
els.rightTextWrap.classList.toggle("hidden", els.singleSegment.checked);
}
function updateOutputs() {
updateRightField();
const badgeUrl = buildBadgeUrl();
const markdown = buildMarkdown(badgeUrl);
const html = buildHtml(badgeUrl);
const target = els.targetUrl.value.trim() || "https://github.com/";
const alt = els.altText.value.trim() || els.leftText.value.trim() || "Badge preview";
els.previewLink.href = target;
els.previewImg.src = badgeUrl;
els.previewImg.alt = alt;
els.markdownOutput.value = markdown;
els.htmlOutput.value = html;
els.urlOutput.value = badgeUrl;
els.plainLinkOutput.value = buildPlainMarkdownLink();
}
function renderColorChips() {
els.colorChips.innerHTML = "";
COLORS.forEach((color) => {
const button = document.createElement("button");
button.type = "button";
button.className = "chip";
button.textContent = color.name;
button.addEventListener("click", () => {
els.color.value = color.value;
updateOutputs();
});
els.colorChips.appendChild(button);
});
}
function renderEmojiPicker() {
els.emojiPicker.innerHTML = "";
EMOJIS.forEach((emoji) => {
const button = document.createElement("button");
button.type = "button";
button.className = "chip";
button.textContent = emoji;
button.addEventListener("click", () => {
const current = els.leftText.value.trim();
els.leftText.value = current ? `${current} ${emoji}` : emoji;
updateOutputs();
});
els.emojiPicker.appendChild(button);
});
}
function resetForm() {
els.singleSegment.checked = defaults.singleSegment;
els.leftText.value = defaults.leftText;
els.rightText.value = defaults.rightText;
els.altText.value = defaults.altText;
els.targetUrl.value = defaults.targetUrl;
els.style.value = defaults.style;
els.color.value = defaults.color;
els.logo.value = defaults.logo;
els.logoColor.value = defaults.logoColor;
els.labelColor.value = defaults.labelColor;
els.plainLinkText.value = defaults.plainLinkText;
els.plainLinkUrl.value = defaults.plainLinkUrl;
updateOutputs();
}
document.querySelectorAll("input, select").forEach((el) => {
el.addEventListener("input", updateOutputs);
el.addEventListener("change", updateOutputs);
});
document.querySelectorAll(".tab").forEach((tab) => {
tab.addEventListener("click", () => {
const target = tab.dataset.tab;
document.querySelectorAll(".tab").forEach((t) => t.classList.remove("active"));
document.querySelectorAll(".tab-panel").forEach((panel) => panel.classList.remove("active"));
tab.classList.add("active");
document.getElementById(`panel-${target}`).classList.add("active");
});
});
document.querySelectorAll("[data-copy]").forEach((btn) => {
btn.addEventListener("click", async () => {
const id = btn.getAttribute("data-copy");
const value = document.getElementById(id).value;
const original = btn.textContent;
try {
await navigator.clipboard.writeText(value);
btn.textContent = "Copied";
setTimeout(() => { btn.textContent = original; }, 1400);
} catch {
btn.textContent = "Copy failed";
setTimeout(() => { btn.textContent = original; }, 1400);
}
});
});
els.resetBtn.addEventListener("click", resetForm);
renderColorChips();
renderEmojiPicker();
updateOutputs();
</script>
</body>
</html>