-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrangExtr.html
More file actions
360 lines (318 loc) · 19 KB
/
rangExtr.html
File metadata and controls
360 lines (318 loc) · 19 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
<!-- v2.3 -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RangExtr</title>
<link href="https://minisoft.it/icons/fix.png" rel="shortcut icon" type="image/x-icon" />
<link href="https://minisoft.it/icons/fix.png" rel="apple-touch-icon" />
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: '#006E81',
'primary-dark': '#006E81',
secondary: '#814000',
}
}
}
}
</script>
</head>
<body class="bg-gray-100 flex flex-col min-h-screen">
<header class="bg-white border-b border-gray-200">
<div class="container mx-auto px-4 py-6 max-w-4xl">
<h1 class="text-3xl font-bold text-center text-gray-800">Rang_Extr</h1>
<p class="text-gray-600 text-center mt-1">Text Range Extractor</p>
</div>
</header>
<main class="container mx-auto px-4 py-8 max-w-4xl flex-grow">
<!-- Instructions Section -->
<div class="bg-white rounded-lg shadow-md p-6 mb-8">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Instructions</h2>
<div class="bg-slate-50 border-l-4 border-primary p-4 rounded-r">
<ol class="list-decimal pl-5 space-y-1">
<li>Paste your text in the input area below.</li>
<li>Choose extraction type: <strong>By position</strong> (character range) or <strong>By delimiter</strong> (before/after a character).</li>
<li><strong>By position:</strong> Set start/end positions and choose Extract or Remove mode.</li>
<li><strong>By delimiter:</strong> Enter the delimiter and choose to extract before or after it (first or last occurrence).</li>
<li>Click "Process" to apply the operation and view the result.</li>
<li>Click on the result to copy it to your clipboard.</li>
</ol>
</div>
</div>
<div class="bg-white rounded-lg shadow-md p-6">
<form id="extract-form">
<div class="space-y-4">
<div>
<label for="inTxt" class="block text-sm font-medium text-gray-700 mb-2">Input text</label>
<textarea id="inTxt" class="w-full h-40 p-3 border border-gray-300 rounded-lg resize-y"
placeholder="Paste your text here..." oninput="validatePositions()"></textarea>
</div>
<div class="flex flex-col gap-4">
<div class="flex items-center gap-2 text-sm text-gray-600">
<label for="previewRows">Preview rows:</label>
<select id="previewRows" class="p-1 border border-gray-300 rounded text-sm" onchange="updatePreview()">
<option value="3" selected>3</option>
<option value="5">5</option>
<option value="10">10</option>
<option value="0">All</option>
</select>
</div>
<div id="preview" class="max-w-full overflow-x-auto font-mono whitespace-pre text-left text-gray-600 leading-relaxed flex-1"></div>
</div>
<!-- Extraction Type Toggle -->
<div class="flex flex-wrap gap-6 py-2 border-b border-gray-200 pb-4">
<div class="flex gap-4">
<label class="inline-flex items-center">
<input type="radio" name="extractType" value="position" checked class="h-4 w-4 text-primary border-gray-300" onchange="toggleExtractionType()">
<span class="ml-2 text-sm text-gray-700">By position</span>
</label>
<label class="inline-flex items-center">
<input type="radio" name="extractType" value="delimiter" class="h-4 w-4 text-primary border-gray-300" onchange="toggleExtractionType()">
<span class="ml-2 text-sm text-gray-700">By delimiter</span>
</label>
</div>
</div>
<!-- Position-based options -->
<div id="positionOptions">
<div class="flex flex-wrap gap-6 py-2">
<div class="flex gap-4">
<label class="inline-flex items-center">
<input type="radio" name="mode" value="extract" checked class="h-4 w-4 text-primary border-gray-300">
<span class="ml-2 text-sm text-gray-700">Extract range</span>
</label>
<label class="inline-flex items-center">
<input type="radio" name="mode" value="remove" class="h-4 w-4 text-primary border-gray-300">
<span class="ml-2 text-sm text-gray-700">Remove range</span>
</label>
</div>
<div class="flex gap-4">
<label class="inline-flex items-center">
<input type="radio" name="direction" value="left" checked class="h-4 w-4 text-primary border-gray-300">
<span class="ml-2 text-sm text-gray-700">Start from left</span>
</label>
<label class="inline-flex items-center">
<input type="radio" name="direction" value="right" class="h-4 w-4 text-primary border-gray-300">
<span class="ml-2 text-sm text-gray-700">Start from right</span>
</label>
</div>
</div>
<div class="flex flex-col sm:flex-row gap-4">
<div class="flex-1">
<label for="startPos" class="block text-sm font-medium text-gray-700 mb-2">Start position</label>
<input type="number" class="w-full p-3 border border-gray-300 rounded-lg"
min="0" value="0" id="startPos" oninput="validatePositions()" />
</div>
<div class="flex-1">
<label for="endPos" class="block text-sm font-medium text-gray-700 mb-2">End position</label>
<input type="number" class="w-full p-3 border border-gray-300 rounded-lg"
min="0" value="0" id="endPos" oninput="validatePositions()" />
</div>
</div>
</div>
<!-- Delimiter-based options -->
<div id="delimiterOptions" class="hidden">
<div class="flex flex-wrap gap-6 py-2">
<div class="flex gap-4">
<label class="inline-flex items-center">
<input type="radio" name="delimiterMode" value="before" checked class="h-4 w-4 text-primary border-gray-300" onchange="updatePreview()">
<span class="ml-2 text-sm text-gray-700">Extract before</span>
</label>
<label class="inline-flex items-center">
<input type="radio" name="delimiterMode" value="after" class="h-4 w-4 text-primary border-gray-300" onchange="updatePreview()">
<span class="ml-2 text-sm text-gray-700">Extract after</span>
</label>
</div>
<div class="flex gap-4">
<label class="inline-flex items-center">
<input type="radio" name="occurrence" value="first" checked class="h-4 w-4 text-primary border-gray-300" onchange="updatePreview()">
<span class="ml-2 text-sm text-gray-700">First occurrence</span>
</label>
<label class="inline-flex items-center">
<input type="radio" name="occurrence" value="last" class="h-4 w-4 text-primary border-gray-300" onchange="updatePreview()">
<span class="ml-2 text-sm text-gray-700">Last occurrence</span>
</label>
</div>
</div>
<div class="flex flex-col sm:flex-row gap-4">
<div class="flex-1">
<label for="delimiter" class="block text-sm font-medium text-gray-700 mb-2">Delimiter character(s)</label>
<input type="text" class="w-full p-3 border border-gray-300 rounded-lg"
placeholder="e.g. @ or , or //" id="delimiter" oninput="updatePreview()" />
</div>
</div>
</div>
<button type="button" class="bg-primary text-white px-4 py-2 rounded-lg hover:bg-primary-dark transition duration-200"
onclick="processText(); return false;">Process</button>
</div>
</form>
<div id="result" class="bg-gray-50 p-5 mt-6 border border-gray-200 rounded-lg font-mono whitespace-pre cursor-pointer hover:bg-gray-100 transition duration-200 hidden"
onclick="copyToClipboard(this)"></div>
<div id="copyFeedback" class="fixed bottom-5 right-5 bg-primary text-white py-2 px-4 rounded-lg shadow-md hidden">
Copied to clipboard!
</div>
</div>
</main>
<footer class="bg-white border-t border-gray-200 mt-auto">
<div class="container mx-auto px-4 py-6 max-w-4xl">
<p class="text-gray-600 text-center">© <a href="https://minisoft.it/" class="text-primary hover:text-primary-dark">Minisoft</a> — All rights reserved</p>
</div>
</footer>
<script>
function toggleExtractionType() {
const extractType = document.querySelector('input[name="extractType"]:checked').value;
const positionOptions = document.getElementById("positionOptions");
const delimiterOptions = document.getElementById("delimiterOptions");
if (extractType === 'position') {
positionOptions.classList.remove('hidden');
delimiterOptions.classList.add('hidden');
} else {
positionOptions.classList.add('hidden');
delimiterOptions.classList.remove('hidden');
}
updatePreview();
}
function validatePositions() {
const startPos = document.getElementById("startPos");
const endPos = document.getElementById("endPos");
if (parseInt(startPos.value) > parseInt(endPos.value)) {
endPos.value = startPos.value;
}
updatePreview();
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
function updatePreview() {
const input = document.getElementById("inTxt").value;
const extractType = document.querySelector('input[name="extractType"]:checked').value;
const previewRowsValue = parseInt(document.getElementById("previewRows").value);
const maxRows = previewRowsValue === 0 ? Infinity : previewRowsValue;
const lines = input.split('\n').filter(line => line.trim());
if (lines.length === 0) {
document.getElementById("preview").innerHTML = '';
return;
}
let preview = '';
if (extractType === 'position') {
const startPos = parseInt(document.getElementById("startPos").value) || 0;
const endPos = parseInt(document.getElementById("endPos").value) || 0;
const direction = document.querySelector('input[name="direction"]:checked').value;
for (let i = 0; i < Math.min(maxRows, lines.length); i++) {
const line = lines[i];
if (direction === 'left') {
preview += escapeHtml(line.substring(0, startPos)) +
'<span class="bg-primary text-white">' +
escapeHtml(line.substring(startPos, endPos)) +
'</span>' +
escapeHtml(line.substring(endPos)) + '\n';
} else {
let len = line.length;
preview += escapeHtml(line.substring(0, len - endPos)) +
'<span class="bg-primary text-white">' +
escapeHtml(line.substring(len - endPos, len - startPos)) +
'</span>' +
escapeHtml(line.substring(len - startPos)) + '\n';
}
}
} else {
const delimiter = document.getElementById("delimiter").value;
const delimiterMode = document.querySelector('input[name="delimiterMode"]:checked').value;
const occurrence = document.querySelector('input[name="occurrence"]:checked').value;
if (!delimiter) {
document.getElementById("preview").innerHTML = '<span class="text-gray-400">Enter a delimiter to see preview</span>';
return;
}
for (let i = 0; i < Math.min(maxRows, lines.length); i++) {
const line = lines[i];
const idx = occurrence === 'first' ? line.indexOf(delimiter) : line.lastIndexOf(delimiter);
if (idx === -1) {
preview += escapeHtml(line) + ' <span class="text-red-500">(no match)</span>\n';
} else {
if (delimiterMode === 'before') {
preview += '<span class="bg-primary text-white">' +
escapeHtml(line.substring(0, idx)) +
'</span>' +
escapeHtml(line.substring(idx)) + '\n';
} else {
const afterIdx = idx + delimiter.length;
preview += escapeHtml(line.substring(0, afterIdx)) +
'<span class="bg-primary text-white">' +
escapeHtml(line.substring(afterIdx)) +
'</span>\n';
}
}
}
}
document.getElementById("preview").innerHTML = preview;
}
function processText() {
const input = document.getElementById("inTxt").value;
const extractType = document.querySelector('input[name="extractType"]:checked').value;
const lines = input.split('\n').filter(line => line.trim());
let result = '';
if (extractType === 'position') {
const startPos = parseInt(document.getElementById("startPos").value);
const endPos = parseInt(document.getElementById("endPos").value);
const direction = document.querySelector('input[name="direction"]:checked').value;
const mode = document.querySelector('input[name="mode"]:checked').value;
for (let line of lines) {
if (direction === 'left') {
if (mode === 'extract') {
result += line.substring(startPos, endPos) + '\n';
} else {
result += line.substring(0, startPos) + line.substring(endPos) + '\n';
}
} else {
let len = line.length;
if (mode === 'extract') {
result += line.substring(len - endPos, len - startPos) + '\n';
} else {
result += line.substring(0, len - endPos) + line.substring(len - startPos) + '\n';
}
}
}
} else {
const delimiter = document.getElementById("delimiter").value;
const delimiterMode = document.querySelector('input[name="delimiterMode"]:checked').value;
const occurrence = document.querySelector('input[name="occurrence"]:checked').value;
if (!delimiter) {
alert('Please enter a delimiter character');
return;
}
for (let line of lines) {
const idx = occurrence === 'first' ? line.indexOf(delimiter) : line.lastIndexOf(delimiter);
if (idx === -1) {
result += line + '\n';
} else {
if (delimiterMode === 'before') {
result += line.substring(0, idx) + '\n';
} else {
result += line.substring(idx + delimiter.length) + '\n';
}
}
}
}
const resultArea = document.getElementById("result");
resultArea.textContent = result;
resultArea.classList.remove('hidden');
}
function copyToClipboard(element) {
const text = element.textContent;
navigator.clipboard.writeText(text).then(() => {
const feedback = document.getElementById("copyFeedback");
feedback.classList.remove('hidden');
setTimeout(() => {
feedback.classList.add('hidden');
}, 2000);
});
}
</script>
</body>
</html>