-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheraser-lab.html
More file actions
305 lines (266 loc) · 11.9 KB
/
Copy patheraser-lab.html
File metadata and controls
305 lines (266 loc) · 11.9 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Eraser Lab - Text-Kitchen</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<nav class="main-nav">
<a href="index.html">Home</a>
<a href="text-reverse-lab.html">Text Reversal</a>
<a href="line-break-lab.html">Line Break Lab</a>
<a href="eraser-lab.html">Eraser Lab</a>
<a href="alphabetizer-lab.html">Alphabetizer Lab</a>
<a href="markov-mashup-lab.html">Markov Mashup Lab</a>
<a href="lipogram-lab.html">Lipogram Lab</a>
<a href="long-tail-lab.html">Long Tail Lab</a>
<a href="grid-it-lab.html">Grid-It Lab</a>
<a href="letter-replacement-lab.html">Letter Swap</a>
<a href="chromacode-lab.html">Chromacode</a>
<a href="about.html">About</a>
</nav>
<!-- Tool content here -->
<div class="container">
<div class="header">
<h1>Eraser Lab</h1>
<p>Transform text through selective erasure • Create found poetry from any text</p>
</div>
<p style="margin-bottom: 30px; line-height: 1.8; color: #4a4a4a;">
[Add your description here about how the Eraser Lab enables permutational erasure and its applications for found poetry and textual reduction.]
</p>
<div class="controls">
<div class="file-upload">
<label class="file-input-wrapper">
Choose Text File (.txt only)
<input type="file" id="fileInput" accept=".txt">
</label>
<div id="errorMessage" class="error-message"></div>
</div>
<div class="mode-selector">
<h3>Erasure Mode</h3>
<div class="mode-buttons">
<button class="mode-btn active" data-mode="word">By Word</button>
<button class="mode-btn" data-mode="character">By Character</button>
</div>
</div>
<div class="erasure-controls">
<div class="control-group">
<h3>Pattern Controls</h3>
<div class="slider-container">
<div class="slider-label">
<span>Every Nth Element</span>
<span id="nthValue">2</span>
</div>
<input type="range" class="slider" id="nthSlider" min="2" max="10" value="2">
</div>
<div class="checkbox-container">
<input type="checkbox" id="enableErasure" checked>
<label for="enableErasure">Enable Erasure</label>
</div>
</div>
<div class="control-group">
<h3>Advanced Patterns</h3>
<div class="checkbox-container">
<input type="checkbox" id="eraseEvery2nd">
<label for="eraseEvery2nd">Every 2nd</label>
</div>
<div class="checkbox-container">
<input type="checkbox" id="eraseEvery3rd">
<label for="eraseEvery3rd">Every 3rd</label>
</div>
<div class="checkbox-container">
<input type="checkbox" id="eraseEvery5th">
<label for="eraseEvery5th">Every 5th</label>
</div>
<div class="checkbox-container">
<input type="checkbox" id="eraseEvery7th">
<label for="eraseEvery7th">Every 7th</label>
</div>
</div>
<div class="control-group">
<h3>Display Options</h3>
<div class="slider-container">
<div class="slider-label">
<span>Font Size</span>
<span id="fontSizeValue">16px</span>
</div>
<input type="range" class="slider" id="fontSizeSlider" min="12" max="24" value="16">
</div>
<div class="checkbox-container">
<input type="checkbox" id="preserveSpacing" checked>
<label for="preserveSpacing">Preserve Original Spacing</label>
</div>
<div class="checkbox-container">
<input type="checkbox" id="preserveLineBreaks" checked>
<label for="preserveLineBreaks">Preserve Line Breaks</label>
</div>
</div>
</div>
</div>
<div class="output">
<div id="outputText" class="output-text">
<div class="placeholder-text">
Upload a .txt file to begin creating your erasure poetry
</div>
</div>
<div id="stats" class="stats" style="display: none;">
<span>Original: <span id="originalCount">0</span> elements</span>
<span>Remaining: <span id="remainingCount">0</span> elements</span>
<span>Erased: <span id="erasedCount">0</span> elements</span>
</div>
<button class="apply-btn" id="exportBtn" style="display: none; margin-top: 15px;">Export TXT</button>
</div>
<script>
// JavaScript for this specific tool
let originalText = '';
let currentMode = 'word';
// DOM elements
const fileInput = document.getElementById('fileInput');
const errorMessage = document.getElementById('errorMessage');
const outputText = document.getElementById('outputText');
const stats = document.getElementById('stats');
const modeButtons = document.querySelectorAll('.mode-btn');
// Controls
const nthSlider = document.getElementById('nthSlider');
const nthValue = document.getElementById('nthValue');
const enableErasure = document.getElementById('enableErasure');
const fontSizeSlider = document.getElementById('fontSizeSlider');
const fontSizeValue = document.getElementById('fontSizeValue');
const preserveSpacing = document.getElementById('preserveSpacing');
const preserveLineBreaks = document.getElementById('preserveLineBreaks');
// Advanced pattern checkboxes
const patternCheckboxes = {
2: document.getElementById('eraseEvery2nd'),
3: document.getElementById('eraseEvery3rd'),
5: document.getElementById('eraseEvery5th'),
7: document.getElementById('eraseEvery7th')
};
// File upload handler
fileInput.addEventListener('change', handleFileUpload);
function handleFileUpload(event) {
const file = event.target.files[0];
errorMessage.textContent = '';
if (!file) return;
if (!file.name.toLowerCase().endsWith('.txt')) {
errorMessage.textContent = 'Please select a .txt file only.';
return;
}
const reader = new FileReader();
reader.onload = function(e) {
originalText = e.target.result;
processText();
};
reader.readAsText(file);
}
// Mode switching
modeButtons.forEach(button => {
button.addEventListener('click', () => {
modeButtons.forEach(btn => btn.classList.remove('active'));
button.classList.add('active');
currentMode = button.dataset.mode;
if (originalText) processText();
});
});
// Control listeners
nthSlider.addEventListener('input', () => {
nthValue.textContent = nthSlider.value;
if (originalText) processText();
});
enableErasure.addEventListener('change', () => {
if (originalText) processText();
});
fontSizeSlider.addEventListener('input', () => {
const size = fontSizeSlider.value + 'px';
fontSizeValue.textContent = size;
outputText.style.fontSize = size;
});
preserveSpacing.addEventListener('change', () => {
if (originalText) processText();
});
preserveLineBreaks.addEventListener('change', () => {
if (originalText) processText();
});
// Advanced pattern listeners
Object.values(patternCheckboxes).forEach(checkbox => {
checkbox.addEventListener('change', () => {
if (originalText) processText();
});
});
function processText() {
if (!originalText) return;
// Handle line breaks if not preserving them
let textToProcess = originalText;
if (!preserveLineBreaks.checked) {
textToProcess = originalText.replace(/[\r\n]+/g, ' ');
}
let elements;
if (currentMode === 'word') {
elements = textToProcess.split(' ');
} else {
elements = textToProcess.split('');
}
const processedElements = elements.map((element, index) => {
if (!enableErasure.checked) return element;
let shouldErase = false;
const position = index + 1;
// Check main nth pattern
if (position % parseInt(nthSlider.value) === 0) {
shouldErase = true;
}
// Check advanced patterns
for (const [nth, checkbox] of Object.entries(patternCheckboxes)) {
if (checkbox.checked && position % parseInt(nth) === 0) {
shouldErase = true;
break;
}
}
if (shouldErase) {
if (currentMode === 'word') {
return preserveSpacing.checked ? ' '.repeat(element.length) : '';
} else {
return preserveSpacing.checked ? ' ' : '';
}
}
return element;
});
let result;
if (currentMode === 'word') {
result = processedElements.join(' ');
} else {
result = processedElements.join('');
}
outputText.textContent = result;
updateStats(elements, processedElements);
}
const exportBtn = document.getElementById('exportBtn');
exportBtn.addEventListener('click', function() {
const text = outputText.textContent;
if (!text) return;
const blob = new Blob([text], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'eraser-lab-output.txt';
a.click();
URL.revokeObjectURL(url);
});
function updateStats(originalElements, processedElements) {
const originalCount = originalElements.length;
const erasedCount = processedElements.filter((element, index) => {
if (currentMode === 'word') {
return element.trim() === '' || element === ' '.repeat(originalElements[index].length);
} else {
return element === ' ' || element === '';
}
}).length;
const remainingCount = originalCount - erasedCount;
document.getElementById('originalCount').textContent = originalCount;
document.getElementById('remainingCount').textContent = remainingCount;
document.getElementById('erasedCount').textContent = erasedCount;
stats.style.display = 'flex';
exportBtn.style.display = 'block';
}
</script>
</body>
</html>