-
Notifications
You must be signed in to change notification settings - Fork 0
/
textExpander.htm
286 lines (261 loc) · 12.1 KB
/
textExpander.htm
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>textExpander</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div style="background: #f0f1f2;">
<nav class="navbar navbar-inverse" style="border-radius:0; background:#222;">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">textExpander</a>
</div>
<div class="nav navbar-nav navbar-right" style="margin-right: 0px;">
<button type="button" class="btn btn-primary navbar-btn" data-toggle="modal" data-target="#configModal" onclick="saveConfig();"><span class="glyphicon glyphicon-pencil"></span> Edit config</button>
<button type="button" class="btn btn-danger navbar-btn" data-toggle="modal" data-target="#clearFieldsModal"><span class="glyphicon glyphicon-remove"></span> Clear all</button>
</div>
</div> <!-- container -->
</nav> <!-- navbar -->
<ul class="nav nav-tabs" style="padding-left:16px;">
<li class="active"><a data-toggle="tab" href="#tabHome">Home</a></li>
<li><a data-toggle="tab" href="#tabOptions">Options</a></li>
<li><a data-toggle="tab" href="#tabHelp">Help</a></li>
</ul>
</div>
<div class="container-fluid">
<div class="tab-content">
<div id="tabHome" class="tab-pane fade in active">
<div class="row">
<div class="col-sm-6">
<h3>Input</h3>
<div class="form-group">
<textarea class="form-control" rows="10" id="inputText"></textarea>
</div> <!-- form-group -->
<div class="form-group">
<div class="row">
<div class="col-sm-8">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-filter"></i> Filter</span>
<input id="inputFilter" type="text" class="form-control" name="email" placeholder="Input filter (regEx)" value=".*">
</div> <!-- input-group -->
</div> <!-- col -->
<div class="col-sm-4">
<button class="btn btn-block" onclick="document.getElementById('inputFilter').value='.*'">.*</button>
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- form-group -->
<div class="checkbox active pull-right">
<label><input type="checkbox" class="" value="" checked disabled>Skip empty lines</label>
</div> <!-- checkbox -->
</div> <!-- col -->
<div class="col-sm-6">
<h3>Template</h3>
<div class="form-group">
<textarea class="form-control" rows="10" id="replaceText"></textarea>
</div> <!-- form-group -->
<div class="form-group">
<div class="row">
<div class="col-sm-8">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-flash"></i> Token</span>
<input id="replaceMagic" type="text" class="form-control" name="email" placeholder="replacePattern" value="\$\$\$">
</div> <!-- input-group -->
</div> <!-- col -->
<div class="col-sm-4">
<button class="btn btn-block" onclick="document.getElementById('replaceMagic').value='\\\$\\\$\\\$'">$$$</button>
</div> <!-- col -->
</div> <!-- row -->
<div class="row">
<div class="col-sm-12">
<br/>
<button class="btn btn-success btn-block" onclick="splitAndReplace()">Split and Replace</button>
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- form-group -->
</div> <!-- col -->
</div> <!-- row -->
<hr>
<div class="row">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-6">
<h3>Output</h3>
</div> <!-- col -->
<div class="col-sm-6">
<div class="pull-right">
<button class="btn btn-primary" onclick="copy_to_clipboard('outputText');"><span class="glyphicon glyphicon-copy"></span> Clipboard</button>
<button class="btn btn-primary" onclick="downloadOutput('outputText');"><span class="glyphicon glyphicon-save-file"></span> Download</button>
<button class="btn btn-danger" onclick="document.getElementById('outputText').value='';"><span class="glyphicon glyphicon-remove"></span> Clear</button>
</div> <!-- pull-right -->
</div> <!-- col -->
</div> <!-- row -->
<div class="row">
<div class="col-sm-12">
<textarea class="form-control" rows="20" id="outputText" readonly></textarea>
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- col-12 -->
</div> <!-- row -->
</div> <!-- tab-pane -->
<div id="tabOptions" class="tab-pane fade">
<h3>Options</h3>
<div class="well">
<div class="form-group">
<label for="headerText">Header:</label>
<textarea class="form-control" rows="3" id="headerText"></textarea>
</div>
<div class="form-group">
<label for="separatorText">Separator:</label>
<textarea class="form-control" rows="3" id="separatorText"></textarea>
</div>
<div class="form-group">
<label for="footerText">Footer:</label>
<textarea class="form-control" rows="3" id="footerText"></textarea>
</div>
</div> <!-- well -->
</div> <!-- tab-pane -->
<div id="tabHelp" class="tab-pane fade">
<h3>Project info</h3>
<p>Visit the <a href="https://github.com/realaxl/textExpander">GitHub home page</a> of this project for more infos and example configurations.</p>
<h3>Input</h3>
<ul>
<li>The content of the <code>input</code> field will be separated into lines, splitting by <code>\n</code> character.</li>
<li>Each line from <code>input</code> field will be processed individually with the rules below.</li>
</ul>
<h3>Filters</h3>
<ul>
<li>Blank lines in the <code>input</code> field will be skipped and will not appear in <code>output</code> field.</li>
<li>Lines in the <code>input</code> field can be filtered against the regEx <code>filter</code> field.</li>
</ul>
<h3>Template and Token</h3>
<ul>
<li>The <code>template</code> field defines the format of the output text.</li>
<li>Each occurenace ot the magic <code>token</code> field in the <code>template</code> will be replaced.</li>
<li>The magic <code>token</code>, e.g. <code>$$$</code> will be replaced with lines from the input field.</li>
<li>Please note the <code>token</code> must match using Javascript regEx.</li>
</ul>
<h3>Options</h3>
<ul>
<li><code>Header</code>, <code>Separator</code> and <code>Footer</code> will be added to the output before, inbetween and after the templates.</li>
<ul>
<li><code>Header</code></li>
<li>Template</li>
<li><code>Separator</code></li>
<li>Template</li>
<li><code>Separator</code></li>
<li>[...]</li>
<li><code>Footer</code></li>
</ul>
</ul>
</div> <!-- tab-pane -->
</div> <!-- tab-content -->
</div> <!-- container -->
<!-- Modal -->
<div id="clearFieldsModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Confirm clearing all fields</h4>
</div>
<div class="modal-body">
<button class="btn btn-danger btn-lg btn-block" onclick="clearFields()">Clear all fields</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div> <!-- modal fade -->
<!-- Modal -->
<div id="configModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit Config</h4>
</div>
<div class="modal-body">
<div class="form-group">
<textarea class="form-control" rows="10" id="configEditorText"></textarea>
</div>
<button class="btn btn-primary" onclick="copy_to_clipboard('configEditorText');"><span class="glyphicon glyphicon-copy"></span> Copy to Clipboard</button>
<button class="btn btn-warning pull-right" onclick="loadConfig(JSON.parse(document.getElementById('configEditorText').value))"><span class="glyphicon glyphicon-save"></span> Apply config</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div> <!-- modal fade -->
</body>
<script type='text/javascript'>
function clearFields() {
// clear textareas
let textareas = ['inputText', 'inputFilter', 'replaceText', 'replaceMagic', 'outputText', 'headerText', 'separatorText', 'footerText'];
for (let i = 0; i < textareas.length; i++) {
document.getElementById(textareas[i]).value = '';
}
}
function splitAndReplace() {
var arrayOfLines = $('#inputText').val().split('\n');
var outputText = '';
var replaceText = document.getElementById('replaceText').value;
var replaceMagic = document.getElementById('replaceMagic').value;
var re = new RegExp(replaceMagic, 'g');
var inputFilter = document.getElementById('inputFilter').value;
var inputRe = new RegExp(inputFilter, 'g');
for (let i = 0; i < arrayOfLines.length; i++) {
let replace = arrayOfLines[i];
if ((replace != "") && replace.match(inputRe)) {
if (outputText !== '') {
outputText += document.getElementById('separatorText').value;
}
outputText += replaceText.replace(re, replace);
}
}
outputText = document.getElementById('headerText').value + outputText + document.getElementById('footerText').value;
document.getElementById('outputText').value = outputText;
}
// try to copy the content of an input field to browser clipboard
function copy_to_clipboard(id) {
document.getElementById(id).select();
document.execCommand('copy');
}
// try to download the content of an input field with the browser
function downloadOutput(id) {
var s = document.getElementById(id).value;
function dataUrl(data) {return "data:x-application/text," + escape(data);}
window.open(dataUrl(s));
}
// generate a JSON representation of the current form input fields
function saveConfig() {
let textareas = ['inputText', 'inputFilter', 'replaceText', 'replaceMagic', 'headerText', 'separatorText', 'footerText']; // 'outputText',
var config = {};
for (let i = 0; i < textareas.length; i++) {
config[textareas[i]] = document.getElementById(textareas[i]).value;
}
document.getElementById('configEditorText').value = JSON.stringify(config, null, "\t");
}
// load a JSON representation from config input field for the form input fields
function loadConfig(config) {
let textareas = ['inputText', 'inputFilter', 'replaceText', 'replaceMagic', 'headerText', 'separatorText', 'footerText']; // 'outputText',
var config = JSON.parse(document.getElementById('configEditorText').value);
for (let i = 0; i < textareas.length; i++) {
let textarea = textareas[i];
if (config[textarea]) {
document.getElementById(textarea).value = config[textarea];
}
}
document.getElementById('configEditorText').value = JSON.stringify(config, null, "\t"); // reload config to reformat JSON
document.getElementById('outputText').value=''; // clear ouput to reduce confusion
}
</script>
</html>