-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexttool.html
More file actions
901 lines (881 loc) · 46.5 KB
/
texttool.html
File metadata and controls
901 lines (881 loc) · 46.5 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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
<!DOCTYPE html>
<html lang="">
<!--Original source: https://github.com/Pinsplash/texttool-->
<!--Last time I remembered to update the build date: May 11, 2026-->
<head>
<style>
.intermediary {
display:none;
}
body {
background-color: #50505c;
font-family:arial,serif;
margin:0;
}
.form {
position:absolute;
border:1px solid black;
background-color:white;
user-select:none;
}
.draggableselectable {
float:right;
user-select:none;
padding:10px;
background-image: repeating-linear-gradient(135deg, #fff 0%, #fff 15%, #d8d8d8 15%, #d8d8d8 30%);
position:absolute;
right:0;
}
.anchortd {
height:0;
width:20px;
padding:0;
margin:0;
overflow:visible;
}
.anchorpoint {
height:10px;
width:10px;
background-color:#bbb;
border-radius:50%;
align-items:center;
position:relative;
}
.anchorpoint:hover {
height:20px;
width:20px;
background-color:#888;
}
.anchorleft {
right:37.5%;
}
.anchorleft:hover {
right:62.5%;
}
.anchorright {
left:87.5%;
}
.anchorright:hover {
left:62.5%;
}
.anchorconnectsuggest {
background-color:#000;
}
.copyabletable {
padding: 10px 0;
}
textarea[readonly] {
background-color: #ccc;
}
</style>
<title></title>
</head>
<body>
<form name="form" class="form">
<div class="draggableselectable">DRAG</div>
<table class="copyabletable">
<tbody>
<tr>
<td class="anchortd anchorleft"></td>
<td><label title="Select what text to target with the effect">Target:</label></td>
<td>
<label>
<select name="targetmodeselect" class="targetmodeselect">
<option value="alltext">All Text</option>
<option value="duplicatelines">Duplicate Lines</option>
<option value="emptylines">Empty Lines</option>
<option value="evenlines">Even Lines</option>
<option value="withtokens">Lines with Tokens</option>
<option value="without_tokens">Lines without Tokens</option>
<option value="oddlines">Odd Lines</option>
<option value="repeatlines">Repeat Lines</option>
<option value="uniquelines">Unique Lines</option>
</select>
</label>
</td>
<td class="anchortd"></td>
</tr>
<tr>
<td class="anchortd"></td>
<td><label title="Select effect to apply to targeted text">Effect:</label></td>
<td>
<label>
<select name="effectselect" class="effectselect">
<option value="copy">Copy (Debug)</option>
<option value="prefixsuffix">Add Prefix/Suffix</option>
<option value="allcombos">All Combinations</option>
<option value="camelseparate">Camel Case Separate</option>
<option value="clear">Clear</option>
<option value="colext">Column Extract</option>
<option value="delete">Delete</option>
<option value="insertnewline">Insert Newline</option>
<option value="makelowercase">Make Lowercase</option>
<option value="makeuppercase">Make Uppercase</option>
<option value="numberlines">Number Lines</option>
<option value="tabbrackets">Re-Tab By Brackets</option>
<option value="replacetable">Replace Table</option>
<option value="reverse">Reverse Lines</option>
<option value="sort">Sort Alphabetically</option>
<option value="sortnumstrings">Sort by # Instances of Substring</option>
<option value="tabtable">Tab Table</option>
</select>
</label>
</td>
<td class="anchortd"></td>
</tr>
<tr class="inputtr">
<td class="anchortd"><div class="anchorpoint anchorleft"></div></td>
<td><label title="Put original text here">Input:</label></td>
<td><label><textarea class="inputeventlisten input" rows="10" cols="50"></textarea></label></td>
<td class="anchortd"><div class="anchorpoint anchorright"></div></td>
</tr>
<tr class="replacetabletr intermediary">
<td class="anchortd"><div class="anchorpoint anchorleft"></div></td>
<td><label title="Batch find and replace. Instances of odd lines will be replaced with the next line down.">Table:</label></td>
<td><label><textarea class="inputeventlisten replacetable" rows="10" cols="50"></textarea></label></td>
<td class="anchortd"><div class="anchorpoint anchorright"></div></td>
</tr>
<tr class="desiredtabwidthtr intermediary">
<td class="anchortd"><div class="anchorpoint anchorleft"></div></td>
<td><label title="When working with tabs, the character width of the tabs. Commonly 2, 4, or 8.">Desired Tab Width:</label></td>
<td><label><textarea class="inputeventlisten desiredtabwidth" rows="1" cols="50">4</textarea></label></td>
<td class="anchortd"><div class="anchorpoint anchorright"></div></td>
</tr>
<tr class="colnotr intermediary">
<td class="anchortd"><div class="anchorpoint anchorleft"></div></td>
<td><label title="When interpreting text as a table, which column to extract">Column Number:</label></td>
<td><label><textarea class="inputeventlisten colno" rows="1" cols="50"></textarea></label></td>
<td class="anchortd"><div class="anchorpoint anchorright"></div></td>
</tr>
<tr class="openbracketstr intermediary">
<td class="anchortd"><div class="anchorpoint anchorleft"></div></td>
<td><label title="Characters that indicate an opening bracket.">Opening Bracket Chars:</label></td>
<td><label><textarea class="inputeventlisten openbrackets" rows="1" cols="50">([{</textarea></label></td>
<td class="anchortd"><div class="anchorpoint anchorright"></div></td>
</tr>
<tr class="closebracketstr intermediary">
<td class="anchortd"><div class="anchorpoint anchorleft"></div></td>
<td><label title="Characters that indicate a closing bracket.">Closing Bracket Chars:</label></td>
<td><label><textarea class="inputeventlisten closebrackets" rows="1" cols="50">)]}</textarea></label></td>
<td class="anchortd"><div class="anchorpoint anchorright"></div></td>
</tr>
<tr class="delimtr intermediary">
<td class="anchortd"><div class="anchorpoint anchorleft"></div></td>
<td><label title="A character or string that indicates where to separate text">Delimiter:</label></td>
<td><label><textarea class="inputeventlisten delim" rows="1" cols="50"></textarea></label></td>
<td class="anchortd"><div class="anchorpoint anchorright"></div></td>
</tr>
<tr class="tokenstr intermediary">
<td class="anchortd"><div class="anchorpoint anchorleft"></div></td>
<td><label>Tokens:</label></td>
<td><label><textarea class="inputeventlisten tokens" rows="10" cols="50"></textarea></label></td>
<td class="anchortd"><div class="anchorpoint anchorright"></div></td>
</tr>
<tr class="ignoreprefixestr intermediary">
<td class="anchortd"><div class="anchorpoint anchorleft"></div></td>
<td><label title="Prefixes to ignore when sorting. Line is sorted as if it starts after a prefix.">Prefixes:</label></td>
<td><label><textarea class="inputeventlisten ignoreprefixes" rows="10" cols="50"></textarea></label></td>
<td class="anchortd"><div class="anchorpoint anchorright"></div></td>
</tr>
<tr class="prefixtr intermediary">
<td class="anchortd"><div class="anchorpoint anchorleft"></div></td>
<td><label title="Prefix to add to text">Prefix:</label></td>
<td><label><textarea class="inputeventlisten prefix" rows="1" cols="50"></textarea></label></td>
<td class="anchortd"><div class="anchorpoint anchorright"></div></td>
</tr>
<tr class="suffixtr intermediary">
<td class="anchortd"><div class="anchorpoint anchorleft"></div></td>
<td><label title="Suffix to add to text">Suffix:</label></td>
<td><label><textarea class="inputeventlisten suffix" rows="1" cols="50"></textarea></label></td>
<td class="anchortd"><div class="anchorpoint anchorright"></div></td>
</tr>
<tr class="startattr intermediary">
<td class="anchortd"><div class="anchorpoint anchorleft"></div></td>
<td><label title="When counting something, the number to start from">Start at:</label></td>
<td><label><textarea class="inputeventlisten startat" rows="1" cols="50"></textarea></label></td>
<td class="anchortd"><div class="anchorpoint anchorright"></div></td>
</tr>
<tr class="effect_matchcasetr intermediary">
<td></td>
<td></td>
<td>
<input type="checkbox" class="effect_matchcase inputeventlisten">
<label for="effect_matchcase" title="Make the task case sensitive. What exactly this means will depend on the effect.">Effect is case sensitive</label><br>
</td>
</tr>
<tr class="target_matchcasetr intermediary">
<td></td>
<td></td>
<td>
<input type="checkbox" class="target_matchcase inputeventlisten">
<label for="target_matchcase" title="Make the targeting case sensitive">Target case sensitively</label><br>
</td>
</tr>
<tr class="outputtr">
<td class="anchortd"></td>
<td><label title="Edited text appears here!">Output:</label></td>
<td><label><textarea class="output" rows="10" cols="50"></textarea></label></td>
<td class="anchortd"><div class="anchorpoint anchorright"></div></td>
</tr>
<tr>
<td class="anchortd"></td>
<td></td>
<td class="anchortd">
<button type="button" onclick="AddToChain(this)">Add</button>
<button type="button" onclick="RemoveMod(this)">Remove</button>
</td>
</tr>
</tbody>
</table>
</form>
<script>
let g_Connections = [];
let g_zindex = 0;
AddListeners();
AddDraggableFormListener(document.getElementsByClassName("draggableselectable")[0]);
for (let iCircle = 0; iCircle < document.getElementsByClassName("anchorpoint").length; iCircle++) {
AddDraggableCircleListener(document.getElementsByClassName("anchorpoint")[iCircle]);
}
UpdateParameters(document.getElementsByClassName("copyabletable")[0]);
function AddListeners() {
let InputListenElems = document.getElementsByClassName("inputeventlisten");
for (const elem of InputListenElems) {
const Update = () => UpdateTextBoxes(elem.closest(".copyabletable"));
elem.addEventListener("input", Update);
}
let EffectSelectElems = document.getElementsByClassName("effectselect");
for (const elem of EffectSelectElems) {
elem.onchange = () => UpdateParameters(elem.closest(".copyabletable"));
}
let TargetModeSelectElems = document.getElementsByClassName("targetmodeselect");
for (const elem of TargetModeSelectElems) {
elem.onchange = () => UpdateParameters(elem.closest(".copyabletable"));
}
let TextAreaElems = document.getElementsByTagName("textarea");
for (const elem of TextAreaElems) {
elem.addEventListener("mousedown", () => {
const OnMove = () => UpdateTableConnectionVisuals(elem.closest("form"));
document.addEventListener("mousemove", OnMove);
document.addEventListener("mouseup", () => {
document.removeEventListener("mousemove", OnMove);
}, { once: true });
});
}
}
function AddDraggableFormListener(Element) {
Element.addEventListener("mousedown", () => {
const OnMove = (Event) => Form_OnMouseDrag(Event, Element);
document.addEventListener("mousemove", OnMove);
document.addEventListener("mouseup", () => {
document.removeEventListener("mousemove", OnMove);
}, { once: true });
g_zindex++;
Element.closest("form").style.zIndex = g_zindex;
});
}
function AddDraggableCircleListener(Element) {
Element.addEventListener("mousedown", () => {
const OnMove = (Event) => Circle_OnMouseDrag(Event, Element);
document.addEventListener("mousemove", OnMove);
//on drop
document.addEventListener("mouseup", () => {
document.removeEventListener("mousemove", OnMove);
//find what circle we're on top of, make a connection, and set both circles back to normal
let DropConnection = Element.className.includes("anchorleft");
let MouseOverElements = GetElementsUnderCircle(Element);
for (let iElement = 0; iElement < MouseOverElements.length; iElement++) {
let MouseElem = MouseOverElements[iElement];
if (MouseElem !== Element && MouseElem.className.includes("anchorpoint")) {
ConnectTableRows(Element, MouseElem);
DropConnection = false;
}
}
if (DropConnection) {
RemoveIncomingConnections(Element.closest("tr"));
}
//reset circle's position and style
Element.style.top = "";
Element.style.right = "";
Element.style.position = "";
if (Element.className.includes("anchorright")) {
Element.style.left = "";
Element.className = "anchorpoint anchorright";
} else {
Element.style.left = "";
Element.className = "anchorpoint anchorleft";
}
}, { once: true });
});
}
function AddToChain(Element) {
let Form = Element.closest("form");
let Clone = Form.cloneNode(true);
document.body.appendChild(Clone);
g_zindex++;
Clone.style.zIndex = g_zindex;
AddListeners();
AddDraggableFormListener(Clone.getElementsByClassName("draggableselectable")[0]);
for (let iCircle = 0; iCircle < Clone.getElementsByClassName("anchorpoint").length; iCircle++) {
AddDraggableCircleListener(Clone.getElementsByClassName("anchorpoint")[iCircle]);
}
OffsetTablePos(Clone);
ConnectTableRows(Form.getElementsByClassName("outputtr")[0], Clone.getElementsByClassName("inputtr")[0]);
}
function RemoveMod(Element) {
//do not remove if we're the only mod on the page. we don't have an independent add button, so removing us would make the program unusable.
if (document.body.getElementsByTagName("form").length === 1) {
return;
}
let Form = Element.closest("form");
let TRs = Form.getElementsByTagName("tr");
for (let iTR = 0; iTR < TRs.length; iTR++) {
let TR = TRs[iTR];
RemoveAllConnections(TR);
}
Form.remove();
}
function ConnectTableRows(SrcTR, DestTR) {
//enforce connection directions
//can't connect input to input or output to output
if (SrcTR.className.includes("anchorright") && DestTR.className.includes("anchorright")) {
return;
}
if (SrcTR.className.includes("anchorleft") && DestTR.className.includes("anchorleft")) {
return;
}
//connection going from left to right, flip it around
if (SrcTR.className.includes("anchorleft") && DestTR.className.includes("anchorright")) {
let Temp = SrcTR;
SrcTR = DestTR;
DestTR = Temp;
}
//can't connect to your own table
if (SrcTR.closest("form") === DestTR.closest("form")) {
return;
}
//find TR's now if we didn't aleady
if (SrcTR.tagName !== "TR") {
SrcTR = SrcTR.closest("tr");
}
if (DestTR.tagName !== "TR") {
DestTR = DestTR.closest("tr");
}
//a textbox can only have one input source, so cancel any others this mod might have
RemoveIncomingConnections(DestTR);
//connect
let Line = CreateConnectionLine(SrcTR, DestTR);
document.body.appendChild(Line);
g_Connections.push(SrcTR, DestTR, Line);
//make destination textbox readonly to avoid confusion
DestTR.getElementsByTagName("textarea")[0].setAttribute("readonly", "true");
}
function GetElementInTable(Table, ElementName) {
let TR = Table.getElementsByClassName(ElementName)[0].closest("tr");
let Indices = GetIncomingConnections(TR);
if (Indices.length > 0) {
return g_Connections[Indices[0] - 1].getElementsByTagName("textarea")[0];
} else {
return Table.getElementsByClassName(ElementName)[0];
}
}
function UpdateParameters(Table) {
//some modes have their own intermediary boxes to set how they work
//hide everything by default, re-show based on mode
let IntermedElems = Table.getElementsByClassName("intermediary");
let OldVisibleElems = [];
let NewVisibleElems = [];
for (const elem of IntermedElems) {
if (elem.style.display !== "none") {
OldVisibleElems.push(elem);
elem.style.display = "none";
}
}
let Effect = GetElementInTable(Table, "effectselect");
switch (Effect.value) {
case "prefixsuffix":
NewVisibleElems.push(GetElementInTable(Table, "prefixtr"));
NewVisibleElems.push(GetElementInTable(Table, "suffixtr"));
break;
case "colext":
NewVisibleElems.push(GetElementInTable(Table, "colnotr"));
NewVisibleElems.push(GetElementInTable(Table, "delimtr"));
NewVisibleElems.push(GetElementInTable(Table, "effect_matchcasetr"));
break;
case "replacetable":
NewVisibleElems.push(GetElementInTable(Table, "replacetabletr"));
NewVisibleElems.push(GetElementInTable(Table, "effect_matchcasetr"));
break;
case "allcombos":
NewVisibleElems.push(GetElementInTable(Table, "delimtr"));
break;
case "insertnewline":
NewVisibleElems.push(GetElementInTable(Table, "delimtr"));
NewVisibleElems.push(GetElementInTable(Table, "effect_matchcasetr"));
break;
case "sortnumstrings":
NewVisibleElems.push(GetElementInTable(Table, "tokenstr"));
NewVisibleElems.push(GetElementInTable(Table, "effect_matchcasetr"));
break;
case "sort":
NewVisibleElems.push(GetElementInTable(Table, "effect_matchcasetr"));
NewVisibleElems.push(GetElementInTable(Table, "ignoreprefixestr"));
break;
case "tabtable":
NewVisibleElems.push(GetElementInTable(Table, "desiredtabwidthtr"));
NewVisibleElems.push(GetElementInTable(Table, "delimtr"));
NewVisibleElems.push(GetElementInTable(Table, "effect_matchcasetr"));
break;
case "tabbrackets":
NewVisibleElems.push(GetElementInTable(Table, "openbracketstr"));
NewVisibleElems.push(GetElementInTable(Table, "closebracketstr"));
break;
case "numberlines":
NewVisibleElems.push(GetElementInTable(Table, "delimtr"));
NewVisibleElems.push(GetElementInTable(Table, "startattr"));
break;
default:
break;
}
let TargetMode = GetElementInTable(Table, "targetmodeselect");
switch (TargetMode.value) {
case "withtokens":
case "without_tokens":
NewVisibleElems.push(GetElementInTable(Table, "tokenstr"));
NewVisibleElems.push(GetElementInTable(Table, "target_matchcasetr"));
break;
default:
break;
}
for (let iOldElem = 0; iOldElem < OldVisibleElems.length; iOldElem++) {
if (!NewVisibleElems.includes(OldVisibleElems[iOldElem])) {
RemoveIncomingConnections(OldVisibleElems[iOldElem]);
}
}
for (let iNewElem = 0; iNewElem < NewVisibleElems.length; iNewElem++) {
//if (!OldVisibleElems.includes(NewVisibleElems[iNewElem])) {
NewVisibleElems[iNewElem].style.display = "table-row";
//}
}
UpdateTextBoxes(Table);
UpdateTableConnectionVisuals(Table.closest("form"));
}
function UpdateTextBoxes(Table) {
let Output = GetElementInTable(Table, "output");
let Input = GetElementInTable(Table, "input");
let Pieces = Input.value.split("\n");
let TargetMode = GetElementInTable(Table, "targetmodeselect");
let LinesToEdit = GetTargetLineNums(Pieces, TargetMode, Table);
Output.value = EditLines(Pieces, Table, LinesToEdit).join("\n");
let TRs = Table.getElementsByTagName("tr");
for (let iTR = 0; iTR < TRs.length; iTR++) {
let TR = TRs[iTR];
let Indices = GetOutgoingConnections(TR);
for (let iIndex = 0; iIndex < Indices.length; iIndex++) {
let Index = Indices[iIndex];
UpdateTextBoxes(g_Connections[Index + 1].closest("table"));
}
}
}
//lines not targeted by the target mode are left undisturbed
//create a list of line numbers we want to edit
function GetTargetLineNums(Input, TargetMode, Table) {
let TargetFunction;
let Numbers = [];
switch (TargetMode.value) {
case "duplicatelines":
TargetFunction = (Line) => { return Input.indexOf(Line, Input.indexOf(Line) + 1) >= 0 && Line !== "<BR>" };
break;
case "repeatlines":
TargetFunction = (Line, LineNum) => { return Input.indexOf(Line) !== LineNum && Line !== "<BR>" };
break;
case "uniquelines":
TargetFunction = (Line) => { return Input.indexOf(Line, Input.indexOf(Line) + 1) === -1 && Line !== "<BR>" };
break;
case "emptylines":
TargetFunction = (Line) => { return Line.length === 0 };
break;
case "withtokens":
case "without_tokens":
TargetFunction = (Line) => {
if (GetElementInTable(Table, "tokens") == null)
return false;
let Tokens = GetElementInTable(Table, "tokens").value.split("\n");
for (let iToken = 0; iToken < Tokens.length; iToken++)
{
let strA = GetElementInTable(Table, "target_matchcase").checked ? Line : Line.toUpperCase();
let strB = GetElementInTable(Table, "target_matchcase").checked ? Tokens[iToken] : Tokens[iToken].toUpperCase();
if (strA.includes(strB))
return TargetMode.value === "withtokens";
}
return TargetMode.value === "without_tokens";
};
break;
case "evenlines":
TargetFunction = (Line, LineNum) => { return LineNum % 2 === 0 };
break;
case "oddlines":
TargetFunction = (Line, LineNum) => { return LineNum % 2 === 1 };
break;
default:
console.log("Unknown target mode");
//fallthrough
case "alltext":
TargetFunction = () => { return true };
break;
}
for (let iLine = 0; iLine < Input.length; iLine++) {
if (TargetFunction(Input[iLine], iLine)) {
Numbers.push(iLine);
}
}
return Numbers;
}
function EditLines(Input, Table, LinesToEdit) {
let Output = Input;
let EffectFunction;
let Effect = GetElementInTable(Table, "effectselect");
switch (Effect.value) {
case "insertnewline":
EffectFunction = (Line) => { return GetElementInTable(Table, "effect_matchcase").checked ? Line.replaceAll(GetElementInTable(Table, "delim").value, "\n") : Line.replace(new RegExp(GetElementInTable(Table, "delim").value, "ig"), "\n") };
break;
case "replacetable":
EffectFunction = (Line) => {
let ReplaceTable = GetElementInTable(Table, "replacetable").value.split("\n");
for (let iPair = 0; iPair + 1 < ReplaceTable.length; iPair += 2) {
Line = GetElementInTable(Table, "effect_matchcase").checked ? Line.replaceAll(ReplaceTable[iPair], ReplaceTable[iPair + 1]) : Line.replace(new RegExp(ReplaceTable[iPair], "ig"), ReplaceTable[iPair + 1]);
}
return Line;
}
break;
//can't really think of how i would go about sorting a subset of the input, but can't think of a very good use case either
case "sort":
return Input.sort((a, b) =>
{
let nameA = GetElementInTable(Table, "effect_matchcase").checked ? a : a.toUpperCase();
let nameB = GetElementInTable(Table, "effect_matchcase").checked ? b : b.toUpperCase();
let Prefixes = GetElementInTable(Table, "ignoreprefixes").value.split("\n");
for (let iPrefix = 0; iPrefix < Prefixes.length; iPrefix++)
{
let Prefix = GetElementInTable(Table, "effect_matchcase").checked ? Prefixes[iPrefix] : Prefixes[iPrefix].toUpperCase();
if (Prefix && nameA.indexOf(Prefix) === 0)
nameA = nameA.slice(Prefix.length);
if (Prefix && nameB.indexOf(Prefix) === 0)
nameB = nameB.slice(Prefix.length);
}
if (nameA < nameB)
return -1;
else if (nameA > nameB)
return 1;
return 0;
});
case "sortnumstrings":
return Input.sort((a, b) =>
{
let Tokens = GetElementInTable(Table, "tokens").value;
let A_Count = (GetElementInTable(Table, "effect_matchcase").checked ? a.split(Tokens).length : a.split(new RegExp(GetElementInTable(Table, "delim").value, "i")).length) - 1;
let B_Count = (GetElementInTable(Table, "effect_matchcase").checked ? b.split(Tokens).length : b.split(new RegExp(GetElementInTable(Table, "delim").value, "i")).length) - 1;
if (A_Count < B_Count)
return -1;
else if (A_Count > B_Count)
return 1;
return 0;
});
//what we put in one line depends on all the others
case "tabtable": {
GetElementInTable(Table, "output").style.tabSize = GetElementInTable(Table, "desiredtabwidth").value;
let Buffer = Input;
let TabWidth = GetElementInTable(Table, "desiredtabwidth").value;
let Delimiter = GetElementInTable(Table, "delim").value;
if (!Delimiter || !TabWidth || TabWidth === "0") {
return [];
}
//get rid of existing tabs and spaces that come after delimiter
for (let iLineNum = 0; iLineNum < LinesToEdit.length; iLineNum++) {
let LineNum = LinesToEdit[iLineNum];
let Segments = GetElementInTable(Table, "effect_matchcase").checked ? Buffer[LineNum].split(Delimiter) : Buffer[LineNum].split(new RegExp(Delimiter, "i"));
//start at one to not disturb first segment's leading whitespace (this would be, say, typical code indentation)
for (let iSegment = 1; iSegment < Segments.length; iSegment++) {
Segments[iSegment] = Segments[iSegment].trim();
}
Buffer[LineNum] = Segments.join(Delimiter);
}
//have to loop this because each iteration of tabbing changes the targetcolumns values for subsequent segments
let TargetColumns = [];
let ColNum = 0;
let MaxSegments = 0;
//find longest cell in the column and record length in targetcolumns
do {
for (let iLineNum = 0; iLineNum < LinesToEdit.length; iLineNum++) {
let LineNum = LinesToEdit[iLineNum];
let Line = Buffer[LineNum];
let Segments = GetElementInTable(Table, "effect_matchcase").checked ? Line.split(Delimiter) : Line.split(new RegExp(Delimiter, "i"));
MaxSegments = Math.max(Segments.length, MaxSegments);
let InnerSegment = Segments[ColNum];
let RealLength = InnerSegment.length + Delimiter.length;
let BestLength;
if (TargetColumns[ColNum]) {
BestLength = TargetColumns[ColNum];
} else {
BestLength = 0;
}
TargetColumns[ColNum] = Math.max(BestLength, RealLength);
//round to next tab interval
TargetColumns[ColNum] = Math.ceil(TargetColumns[ColNum] / TabWidth) * TabWidth;
}
ColNum++;
//-1 because last column doesn't need new tabs
} while (ColNum < MaxSegments - 1)
ColNum = 0;
do {
for (let iLineNum = 0; iLineNum < LinesToEdit.length; iLineNum++) {
let LineNum = LinesToEdit[iLineNum];
let Line = Buffer[LineNum];
let Segments = GetElementInTable(Table, "effect_matchcase").checked ? Line.split(Delimiter) : Line.split(new RegExp(Delimiter, "i"));
let InnerSegment = Segments[ColNum].trim();
//add new tabs to match targetcolumns
let TextColumn = InnerSegment.length + Delimiter.length;
let FirsTab = true;
while (TextColumn < TargetColumns[ColNum]) {
Segments[ColNum + 1] = "\t" + Segments[ColNum + 1];
if (FirsTab) {
TextColumn += +TabWidth - (+TextColumn % +TabWidth);
} else {
TextColumn += +TabWidth;
}
FirsTab = false;
}
Buffer[LineNum] = Segments.join(Delimiter);
}
ColNum++;
} while (ColNum < TargetColumns.length)
return Buffer;
}
case "prefixsuffix":
EffectFunction = (Line) => { return GetElementInTable(Table, "prefix").value + Line + GetElementInTable(Table, "suffix").value };
break;
case "colext":
EffectFunction = (Line) => {
let Segments = GetElementInTable(Table, "effect_matchcase").checked ? Line.split(GetElementInTable(Table, "delim").value) : Line.split(new RegExp(GetElementInTable(Table, "delim").value, "i"));
return Segments[Math.min(Segments.length - 1, GetElementInTable(Table, "colno").value)];
}
break;
case "camelseparate":
EffectFunction = (Line) => { return Line.replace(/([A-Z])/g, " $1").trim() };
break;
case "makelowercase":
EffectFunction = (Line) => { return Line.toLowerCase() };
break;
case "makeuppercase":
EffectFunction = (Line) => { return Line.toUpperCase() };
break;
case "delete":
EffectFunction = () => { return "texttoolinternalsignal_delete" };
break;
case "clear":
EffectFunction = () => { return "" };
break;
case "allcombos":
let Buffer = [];
let Results = [];
for (let i = 0; i < Input.length; i++) {
Buffer = [Input[i]];
for (let iResult = 0; iResult < Results.length; iResult++) {
Buffer.push("" + Results[iResult] + GetElementInTable(Table, "delim").value + Input[i]);
}
Results = Results.concat(Buffer);
}
return Results;
case "reverse":
return Input.reverse();
case "tabbrackets":
let Depth = 0;
let OpenChars = GetElementInTable(Table, "openbrackets").value;
let CloseChars = GetElementInTable(Table, "closebrackets").value;
for (let iLineNum = 0; iLineNum < LinesToEdit.length; iLineNum++) {
let LineNum = LinesToEdit[iLineNum];
let Line = Output[LineNum];
//must find closing brackets before adding tabs
for (let iChar = 0; iChar < CloseChars.length; iChar++) {
let Char = CloseChars[iChar];
let Hits = Line.split(Char).length - 1;
Depth -= Hits;
}
//add tabs
for (let iNumTabs = 0; iNumTabs < Depth; iNumTabs++) {
Output[LineNum] = "\t" + Output[LineNum];
}
//find opening brackets
for (let iChar = 0; iChar < OpenChars.length; iChar++) {
let Char = OpenChars[iChar];
let Hits = Line.split(Char).length - 1;
Depth += Hits;
}
}
return Output;
case "numberlines":
EffectFunction = (Line, LineNum) => { return (+LineNum + +GetElementInTable(Table, "startat").value) + GetElementInTable(Table, "delim").value + Line };
break;
default:
console.log("Unknown effect");
//fallthrough
case "copy":
EffectFunction = (Line) => { return Line };
break;
}
let DeletedLines = 0;
for (let iLineNum = 0; iLineNum < LinesToEdit.length; iLineNum++) {
let LineNum = LinesToEdit[iLineNum] - DeletedLines;
Output[LineNum] = EffectFunction(Input[LineNum], LineNum);
if (Output[LineNum] === "texttoolinternalsignal_delete") {
Output.splice(LineNum, 1);
DeletedLines++;
}
}
return Output;
}
function Form_OnMouseDrag(Event, Element) {
let Form = Element.closest("form");
let LeftValue = parseInt(window.getComputedStyle(Form).left);
let TopValue = parseInt(window.getComputedStyle(Form).top);
Form.style.left = `${LeftValue + Event.movementX}px`;
Form.style.top = `${TopValue + Event.movementY}px`;
UpdateTableConnectionVisuals(Form);
}
function Circle_OnMouseDrag(Event, Element) {
let Width = parseInt(window.getComputedStyle(Element).width);
let Margin = parseInt(window.getComputedStyle(Element).margin);
Element.style.left = `${Event.clientX - (Width / 2 + Margin)}px`;
Element.style.top = `${Event.clientY - (Width / 2 + Margin)}px`;
Element.style.right = "0";
Element.style.position = "fixed";
//turn other circles black if we're over them to indicate that we'll choose them
let MouseOverElements = GetElementsUnderCircle(Element);
for (let iElement = 0; iElement < MouseOverElements.length; iElement++) {
let MouseElem = MouseOverElements[iElement];
if (MouseElem.className === "anchorpoint") {
MouseElem.className += " anchorconnectsuggest";
}
}
}
function GetElementsUnderCircle(Circle) {
let LeftValue = parseInt(window.getComputedStyle(Circle).left);
let TopValue = parseInt(window.getComputedStyle(Circle).top);
let WidthValue = parseInt(window.getComputedStyle(Circle).width);
let HeightValue = parseInt(window.getComputedStyle(Circle).height);
return document.elementsFromPoint(+LeftValue + WidthValue / 2, +TopValue + HeightValue / 2);
}
function UpdateTableConnectionVisuals(Form) {
let TRs = Form.getElementsByTagName("tr");
for (let iTR = 0; iTR < TRs.length; iTR++) {
let TR = TRs[iTR];
let Indices = GetAllConnections(TR);
for (let iIndex = 0; iIndex < Indices.length; iIndex++) {
//connections are stored in a list like so:
//source element, destination element, and then the line element that shows they're connected
//modulo to understand our position in the list
let Index = Indices[iIndex];
let OffsetInList = Index % 3;
if (OffsetInList === 0) {
g_Connections[Index + 2].style.cssText = CreateConnectionLine(TR, g_Connections[Index + 1]).style.cssText;//we're element 1, so fix up our line to element 2
} else if (OffsetInList === 1) {
g_Connections[Index + 1].style.cssText = CreateConnectionLine(g_Connections[Index - 1], TR).style.cssText;//we're element 2, so fix up our line to element 1
} else {
debugger;//this shouldn't happen
}
}
}
}
function OffsetTablePos(Element) {
let LeftValue = parseInt(window.getComputedStyle(Element).left);
let TopValue = parseInt(window.getComputedStyle(Element).top);
Element.style.left = `${LeftValue + 20}px`;
Element.style.top = `${TopValue + 20}px`;
}
function GetAllConnections(Element) {
let Indices = [];
for (let iConnection = 0; iConnection < g_Connections.length; iConnection++) {
if (g_Connections[iConnection] === Element) {
Indices.push(iConnection);
}
}
return Indices;
}
function GetOutgoingConnections(Element) {
let Indices = [];
for (let iConnection = 0; iConnection < g_Connections.length; iConnection += 3) {
if (g_Connections[iConnection] === Element) {
Indices.push(iConnection);
}
}
return Indices;
}
function GetIncomingConnections(Element) {
let Indices = [];
for (let iConnection = 1; iConnection < g_Connections.length; iConnection += 3) {
if (g_Connections[iConnection] === Element) {
Indices.push(iConnection);
}
}
return Indices;
}
function RemoveAllConnections(TR) {
let Indices = GetAllConnections(TR);
for (let iIndex = 0; iIndex < Indices.length; iIndex++) {
let Index = Indices[iIndex];
let OffsetInList = Index % 3;
if (OffsetInList === 0) {
RemoveConnection(Index);
} else if (OffsetInList === 1) {
RemoveConnection(Index - 1);
} else {
debugger;//this shouldn't happen
}
}
}
function RemoveIncomingConnections(DestTR) {
let Indices = GetIncomingConnections(DestTR);
for (let iIndex = 0; iIndex < Indices.length; iIndex++) {
let Index = Indices[iIndex];
RemoveConnection(Index - 1);
}
}
function RemoveConnection(SrcTRIndex) {
g_Connections[SrcTRIndex + 2].remove();
let DestTR = g_Connections[SrcTRIndex + 1];
if (DestTR.getElementsByTagName("textarea")[0]) {
DestTR.getElementsByTagName("textarea")[0].removeAttribute("readonly");
}
g_Connections.splice(SrcTRIndex, 3);
}
function CreateConnectionLine(SrcElement, DestElement) {
let Rect1 = SrcElement.getBoundingClientRect();
let Rect2 = DestElement.getBoundingClientRect();
let SrcX = Rect1.left + Rect1.width + 2.5;
let SrcY = Rect1.top + (Rect1.height / 2);
let DestX = Rect2.left - 2.5;
let DestY = Rect2.top + (Rect2.height / 2);
let Length = Math.sqrt(((DestX - SrcX) * (DestX - SrcX)) + ((DestY - SrcY) * (DestY - SrcY)));
let Thickness = 2;
let cx = ((SrcX + DestX) / 2) - (Length / 2);
let cy = ((SrcY + DestY) / 2) - (Thickness / 2);
let Angle = Math.atan2((SrcY - DestY), (SrcX - DestX)) * (180 / Math.PI);
let Line = document.createElement("div");
Line.style.padding = "0";
Line.style.margin = "0";
Line.style.height = Thickness + "px";
Line.style.backgroundColor = "black";
Line.style.lineHeight = "1px";
Line.style.position = "absolute";
Line.style.left = cx + "px";
Line.style.top = cy + "px";
Line.style.width = Length + "px";
Line.style.mozTransform = "rotate(" + Angle + "deg)";
Line.style.otransform = "rotate(" + Angle + "deg)";
Line.style.mstransform = "rotate(" + Angle + "deg)";
Line.style.transform = "rotate(" + Angle + "deg)";
Line.style.zIndex = "-1";
return Line;
}
</script>
</body>
</html>