-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeta.html
More file actions
337 lines (286 loc) · 8.63 KB
/
beta.html
File metadata and controls
337 lines (286 loc) · 8.63 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="images/favicon.png" type="image/x-icon">
<title>beta/replacetext/tool</title>
<!-- load roboto and roboto mono fonts -->
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&family=Roboto+Mono:wght@400&display=swap" rel="stylesheet">
<style>
:root {
/* primary colors (shared) */
--primary-blue: #007bff;
--primary-blue-hover: #0056b3;
/* light theme */
--bg: #f5f5f5;
--surface: #ffffff;
--text: #111827;
--muted: #6b7280;
--border: #d1d5db;
}
/* dark theme overrides */
.dark {
--bg: #0b1020;
--surface: #0f1724;
--text: #e6eef8;
--muted: #93a4c3;
--border: #1f2937;
}
/* UI base */
html, body {
height: 100%;
}
body {
font-family: 'Roboto', Arial, sans-serif;
background: var(--bg);
color: var(--text);
padding: 20px;
transition: background 160ms linear, color 160ms linear;
box-sizing: border-box;
}
.top-row {
display: flex;
gap: 10px 16px;
align-items: center;
justify-content: space-between;
}
h2 {
margin: 0;
font-weight: 700;
}
.controls {
display: flex;
gap: 8px;
align-items: center;
width: 100%;
}
/* Dark mode */
@media (prefers-color-scheme: dark) {
.top-row {
background-image: url('-dark.png');
color: #fff; /* text color for dark mode */
}
}
/* shared control styles */
textarea, .editable, button {
width: 100%;
margin-top: 10px;
padding: 10px;
font-size: 16px;
box-sizing: border-box;
border-radius: 12px;
font-family: inherit; /* ensure all controls use Roboto */
}
.editable {
min-height: 36px;
background: var(--surface);
border: 1px solid var(--border);
color: var(--text);
overflow-y: auto;
transition: background 160ms linear, border-color 160ms linear, color 160ms linear;
}
textarea {
background: var(--surface);
border: 1px solid var(--border);
color: var(--text);
transition: background 160ms linear, border-color 160ms linear, color 160ms linear;
resize: vertical;
}
textarea::placeholder {
color: var(--muted);
}
label {
display: block;
margin-top: 12px;
color: var(--muted);
font-size: 14px;
}
button.primary {
cursor: pointer;
background: var(--primary-blue);
color: white;
border: none;
transition: background 0.3s;
}
button.primary:hover {
background: var(--primary-blue-hover);
}
.logo {
width: 200px;
height: 100px;
background-image: url("images/betalogo-light.png");
background-size: contain;
background-repeat: no-repeat;
background-position: left;
}
/* when dark mode is active */
.dark .logo {
background-image: url("images/betalogo-dark.png");
}
/* small secondary buttons (theme toggle etc) */
.small-btn {
padding: 8px 12px;
border-radius: 10px;
background: var(--surface);
color: var(--text);
border: 1px solid var(--border);
cursor: pointer;
transition: background 160ms linear, border-color 160ms linear, color 160ms linear;
font-size: 14px;
}
.small-btn:hover {
filter: brightness(0.95);
}
.blueData {
color: var(--primary-blue);
font-weight: normal;
font-family: 'Roboto Mono', monospace; /* Roboto family monospace */
}
/* layout niceties */
.actions {
display: grid;
gap: 8px;
grid-auto-flow: column;
align-items: center;
width: 220px;
}
.footer-note {
margin-top: 12px;
color: var(--muted);
font-size: 13px;
}
.transform-actions {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.transform-actions .small-btn {
width: 100%;
padding: 8px 0; /* tighter horizontally */
text-align: center;
}
</style>
</head>
<body>
<div class="top-row">
<div id="logo" class="logo"></div>
<div class="actions">
<button id="themeToggle" class="small-btn" aria-pressed="false" title="toggle dark mode">toggle theme</button>
<button id="replaceBtn" class="primary">replace!</button>
</div>
</div>
<label for="text">text:</label>
<textarea id="text" rows="6" placeholder="enter text here!"></textarea>
<label>find:</label>
<div id="find" class="editable" contenteditable="true" aria-label="Find pattern"></div>
<label>replace with:</label>
<div id="replace" class="editable" contenteditable="true" aria-label="Replace pattern"></div>
<div style="display:none" id="sr">screenreader helper</div>
<label>extra actions</label>
<div class="transform-actions">
<button class="small-btn" onclick="removeNumbers()">remove numbers</button>
<button class="small-btn" onclick="toLowercase()">lowercase</button>
<button class="small-btn" onclick="toUppercase()">UPPERCASE</button>
</div>
<div class="footer-note">
! use <span class="blueData">$data</span> inside find and replace with if you want to keep data on another type of brackets! (or get rid of it)
<br><br>
<a href="index" class="small-btn">exit beta</a>
</div>
</div>
<script>
// Theme toggle + persistence
(function() {
const html = document.documentElement;
const toggle = document.getElementById('themeToggle');
const saved = localStorage.getItem('theme');
function applyTheme(mode) {
if (mode === 'dark') {
html.classList.add('dark');
toggle.textContent = 'toggle theme';
toggle.setAttribute('aria-pressed', 'true');
} else {
html.classList.remove('dark');
toggle.textContent = 'toggle theme';
toggle.setAttribute('aria-pressed', 'false');
}
}
if (saved === 'dark' || (!saved && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
applyTheme('dark');
} else {
applyTheme('light');
}
toggle.addEventListener('click', () => {
const isDark = html.classList.contains('dark');
const next = isDark ? 'light' : 'dark';
applyTheme(next);
localStorage.setItem('theme', next);
});
})();
// Replace button
document.getElementById('replaceBtn').addEventListener('click', replaceText);
// Highlight $data inside contenteditable
function colorData(div) {
const sel = window.getSelection();
const range = sel.rangeCount ? sel.getRangeAt(0) : null;
const caretOffset = range ? range.startOffset : null;
let text = div.textContent;
const html = text.replace(/\$data/g, '<span class="blueData">$data</span>');
div.innerHTML = html;
if (range && div.firstChild) {
const newRange = document.createRange();
const childNode = div.firstChild;
const offset = Math.min(caretOffset, childNode.length || 0);
newRange.setStart(childNode, offset);
newRange.collapse(true);
sel.removeAllRanges();
sel.addRange(newRange);
}
}
document.getElementById("find").addEventListener("input", function() {
colorData(this);
});
document.getElementById("replace").addEventListener("input", function() {
colorData(this);
});
function escapeForRegExp(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
// Replace function supporting multiple $data, bracket replacement, and global matches
function replaceText() {
const textArea = document.getElementById("text");
let findValue = document.getElementById("find").textContent;
let replaceValue = document.getElementById("replace").textContent;
if (!findValue) return;
if (findValue.includes("$data") && replaceValue.includes("$data")) {
const parts = findValue.split(/\$data/g).map(part => escapeForRegExp(part));
const regex = new RegExp(parts.join("([\\s\\S]+?)"), "g");
textArea.value = textArea.value.replace(regex, (...args) => {
const captured = args.slice(1, args.length - 2 + 1);
let result = replaceValue;
let index = 0;
result = result.replace(/\$data/g, () => captured[index++] ?? '');
return result;
});
} else {
const regex = new RegExp(escapeForRegExp(findValue), "g");
textArea.value = textArea.value.replace(regex, replaceValue);
}
}
function removeNumbers() {
const textArea = document.getElementById("text");
textArea.value = textArea.value.replace(/\d+/g, '');
}
function toLowercase() {
const textArea = document.getElementById("text");
textArea.value = textArea.value.toLowerCase();
}
function toUppercase() {
const textArea = document.getElementById("text");
textArea.value = textArea.value.toUpperCase();
}
// Initialize $data highlighting for prefilled content
document.querySelectorAll('.editable').forEach(div => colorData(div));
</script>
</body>
</html>