Repository navigation
Expand file tree
/
Copy path404.html
More file actions
141 lines (123 loc) · 5.01 KB
/
Copy path404.html
File metadata and controls
141 lines (123 loc) · 5.01 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>OpenTentacle Labels</title>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
background: #0d1117; color: #e6edf3;
min-height: 100vh; display: flex; flex-direction: column;
align-items: center; justify-content: center; padding: 2rem 1rem;
}
a { color: #58a6ff; text-decoration: none; }
a:hover { text-decoration: underline; }
.back { display: block; font-size: .85rem; color: #8b949e; margin-bottom: 1.5rem; text-align: center; }
.card {
background: #161b22; border: 1px solid #30363d; border-radius: 10px;
padding: 2rem; width: 100%; max-width: 440px;
}
.preview {
display: flex; justify-content: center; align-items: center;
background: #0d1117; border: 1px solid #30363d; border-radius: 8px;
padding: 2rem; margin-bottom: 1.25rem; min-height: 80px;
}
.preview svg { display: block; }
.label-row {
display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap;
}
code {
font-family: "SFMono-Regular", Consolas, monospace;
font-size: .88rem; color: #79c0ff; flex: 1; word-break: break-all;
}
.actions { display: flex; gap: .6rem; flex-wrap: wrap; }
button, .btn {
background: #21262d; border: 1px solid #30363d; border-radius: 6px;
color: #c9d1d9; cursor: pointer; font-size: .85rem; padding: .4rem .9rem;
transition: background .12s, border-color .12s; text-decoration: none;
display: inline-flex; align-items: center;
}
button:hover, .btn:hover { background: #30363d; border-color: #8b949e; }
button.flash { color: #56d364; border-color: #56d364; }
/* 404 state */
.not-found { text-align: center; }
.not-found h1 { font-size: 3rem; font-weight: 700; color: #30363d; margin-bottom: .5rem; }
.not-found p { color: #8b949e; margin-bottom: 1.5rem; }
</style>
</head>
<body>
<div id="badge-page" hidden>
<a class="back" href="/validate/">← Badge Configurator</a>
<div class="card">
<div class="preview" id="preview"></div>
<div class="label-row">
<code id="label-text"></code>
<button id="copy-label-btn" onclick="copyLabel()">Copy label</button>
</div>
<div class="actions">
<button id="copy-svg-btn" onclick="copySVG()">Copy SVG</button>
<button onclick="download()">Download .svg</button>
<a class="btn" id="configurator-link" href="/validate/">Open in Configurator</a>
</div>
</div>
</div>
<div id="not-found" hidden class="not-found">
<h1>404</h1>
<p>Page not found.</p>
<a class="btn" href="/validate/">Open Badge Configurator</a>
</div>
<script type="module">
import { makeBadge, setLogoContent, extractLogoContent, parseLabelString } from '/lib/badges.js'
// Register SW so future <img src="…"> requests work with the right content-type
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js', { type: 'module' })
}
const BADGE_RE = /^\/(badge|seal|strip|compound)\/(.+)$/
const m = window.location.pathname.match(BADGE_RE)
if (!m) {
document.getElementById('not-found').hidden = false
} else {
const [, style, raw] = m
const label = decodeURIComponent(raw)
const normalized = /^otl:/i.test(label) ? label : 'OTL:' + label
// Validate before showing the page
const result = parseLabelString(normalized)
document.getElementById('badge-page').hidden = false
document.getElementById('label-text').textContent = normalized.toUpperCase()
// Link back to configurator with label pre-filled
document.getElementById('configurator-link').href =
`/validate/#${encodeURIComponent(normalized)}`
document.title = `${normalized.toUpperCase()} — OpenTentacle Labels`
let currentSVG = ''
function render() {
currentSVG = makeBadge(style, label)
document.getElementById('preview').innerHTML = currentSVG
}
// Render immediately (without logo watermark), then re-render with logo
render()
fetch('/badges/svg/logo.svg')
.then(r => r.text())
.then(text => { setLogoContent(extractLogoContent(text)); render() })
.catch(() => {})
// Actions
window.copySVG = () =>
navigator.clipboard.writeText(currentSVG).then(() => flash('copy-svg-btn'))
window.copyLabel = () =>
navigator.clipboard.writeText(normalized.toUpperCase()).then(() => flash('copy-label-btn'))
window.download = () => {
const name = normalized.toUpperCase().replace('OTL:', 'OTL-').replace(/\+/g, '_')
const url = URL.createObjectURL(new Blob([currentSVG], { type: 'image/svg+xml' }))
Object.assign(document.createElement('a'), { href: url, download: `${name}.svg` }).click()
URL.revokeObjectURL(url)
}
function flash(id) {
const el = document.getElementById(id)
el.classList.add('flash')
setTimeout(() => el.classList.remove('flash'), 1500)
}
}
</script>
</body>
</html>