-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtxt.html
More file actions
120 lines (110 loc) · 3.83 KB
/
txt.html
File metadata and controls
120 lines (110 loc) · 3.83 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
---
layout: generator
title: "Text File Generator"
subtitle: "Generate TXT with custom configuration"
tab_id: "TXT"
generator_script: "/js/generators/text.js"
redirect_from:
- /txt.html
---
<h2 class="text-2xl font-bold mb-4">Text File Generator</h2>
<form id="form-txt" class="space-y-4">
<div class="form-control">
<label class="label">
<span class="label-text">Number of Rows</span>
</label>
<input
type="number"
name="rows"
value="10"
min="1"
class="input input-bordered w-full"
/>
<label class="label">
<span class="label-text-alt">Disabled if size is specified</span>
</label>
</div>
<div class="divider">OR</div>
<div class="form-control">
<label class="label">
<span class="label-text">Target Size (Optional)</span>
</label>
<div class="flex flex-col sm:flex-row gap-2">
<input
type="number"
name="size"
min="0"
step="0.01"
class="input input-bordered"
placeholder="Size"
/>
<select name="sizeUnit" class="select select-bordered">
<option value="KB">KB</option>
<option value="MB">MB</option>
</select>
</div>
</div>
<button type="submit" class="btn btn-primary w-full">
Generate & Download
</button>
</form>
<script>
document
.getElementById("form-txt")
.addEventListener("submit", async (e) => {
e.preventDefault();
const formData = new FormData(e.target);
const config = {
rows: parseInt(formData.get("rows")) || null,
size: formData.get("size")
? parseFloat(formData.get("size"))
: null,
sizeUnit: formData.get("sizeUnit"),
};
try {
const blob = await generateText(config);
logToUI("Preparing file...");
const shareTitle = config.size
? `Text file ${config.size} ${config.sizeUnit}`
: `Text file ${config.rows} rows`;
const filename = config.size
? `Text_file_${config.size}_${config.sizeUnit}.txt`
: `Text_file_${config.rows}_rows.txt`;
const result = await downloadOrShareFile(blob, filename, "text", shareTitle);
if (result.method === 'download') {
logToUI("✓ Download complete!");
}
// Track in Google Analytics
gtag("event", "generate_txt", {
event_category: "file_generation",
event_label: "text",
rows: config.rows || "size_based",
has_size: config.size ? "yes" : "no",
});
} catch (error) {
logToUI(`❌ Error: ${error.message}`);
showError("Text generation failed: " + error.message);
hideProgress();
}
});
// Mutual exclusion logic
const txtSizeInput = document.querySelector('input[name="size"]');
const txtRowsInput = document.querySelector('input[name="rows"]');
txtSizeInput.addEventListener("input", (e) => {
if (e.target.value) {
txtRowsInput.disabled = true;
txtRowsInput.value = "";
} else {
txtRowsInput.disabled = false;
txtRowsInput.value = 10;
}
});
txtRowsInput.addEventListener("input", (e) => {
if (e.target.value) {
txtSizeInput.disabled = true;
txtSizeInput.value = "";
} else {
txtSizeInput.disabled = false;
}
});
</script>