-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
944 lines (875 loc) · 29.9 KB
/
index.js
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
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
var mode = "add"; // default
// Takes a string in the form 'h:m:s.s', 'm:s.s', or 's' and converts to seconds
function stringToSeconds(timeString) {
var timeSeparator = document.timeCalc.timeSeparator.value;
var sign = 1; // -1 for negative number
if (timeString == "") return 0;
if (timeString.substring(0, 1) == "-") {
sign = -1;
timeString = timeString.substring(1, timeString.length);
}
var days = 0;
var hr = 0;
var mn = 0;
var sec = 0;
var frames = 0;
var timeArray = timeString.split(timeSeparator);
//alert(timeArray.length);
switch (timeArray.length) {
case 1:
if (document.timeCalc.singleFormat[0].checked) {
// days
days = Number(timeArray[0]);
} else if (document.timeCalc.singleFormat[1].checked) {
// hr
hr = Number(timeArray[0]);
} else if (document.timeCalc.singleFormat[2].checked) {
// min
mn = Number(timeArray[0]);
} else if (document.timeCalc.singleFormat[3].checked) {
// sec
sec = Number(timeArray[0]);
} else {
// frames
frames = Number(timeArray[0]);
}
break;
case 2:
if (document.timeCalc.timeFormat[0].checked) {
// days:hr
days = Number(timeArray[0]);
hr = Number(timeArray[1]);
} else if (document.timeCalc.timeFormat[1].checked) {
// hr:min
hr = Number(timeArray[0]);
mn = Number(timeArray[1]);
} else if (document.timeCalc.timeFormat[2].checked) {
// min:sec
mn = Number(timeArray[0]);
sec = Number(timeArray[1]);
} else {
// sec:frames
sec = Number(timeArray[0]);
frames = Number(timeArray[1]);
}
break;
case 3:
if (document.timeCalc.time3Format[0].checked) {
// days:hr:min
days = Number(timeArray[0]);
hr = Number(timeArray[1]);
mn = Number(timeArray[2]);
} else if (document.timeCalc.time3Format[1].checked) {
// hr:min:sec
hr = Number(timeArray[0]);
mn = Number(timeArray[1]);
sec = Number(timeArray[2]);
} else {
// min:sec:frames
mn = Number(timeArray[0]);
sec = Number(timeArray[1]);
frames = Number(timeArray[2]);
}
break;
case 4:
if (document.timeCalc.time4Format[0].checked) {
// days:hr:min:sec
days = Number(timeArray[0]);
hr = Number(timeArray[1]);
mn = Number(timeArray[2]);
sec = Number(timeArray[3]);
} else {
// hr:min:sec:frames
hr = Number(timeArray[0]);
mn = Number(timeArray[1]);
sec = Number(timeArray[2]);
frames = Number(timeArray[3]);
}
break;
case 5:
days = Number(timeArray[0]);
hr = Number(timeArray[1]);
mn = Number(timeArray[2]);
sec = Number(timeArray[3]);
frames = Number(timeArray[4]);
break;
}
//alert(hr + ", " + mn + ", " + sec + ", " + frames)
//alert(sign * (hr*3600 + mn*60 + sec))
return sign * (days * 86400 + hr * 3600 + mn * 60 + sec);
}
// Takes a string in the form 'h:m:s:f', 'm:s:f', 's:f' or 'f' and extract the frames
function stringToFrames(timeString) {
var timeSeparator = document.timeCalc.timeSeparator.value;
var sign = 1; // -1 for negative number
if (timeString == "") return 0;
if (timeString.substring(0, 1) == "-") {
sign = -1;
timeString = timeString.substring(1, timeString.length);
}
var frames = 0;
var timeArray = timeString.split(timeSeparator);
//alert(timeArray.length);
switch (timeArray.length) {
case 1:
if (document.timeCalc.singleFormat[4].checked) {
// f
frames = Number(timeArray[0]);
}
break;
case 2:
if (document.timeCalc.timeFormat[3].checked) {
// s:f
sec = Number(timeArray[0]);
frames = Number(timeArray[1]);
}
break;
case 3:
if (document.timeCalc.time3Format[2].checked) {
// m:s:f
frames = Number(timeArray[2]);
}
break;
case 4:
if (document.timeCalc.time4Format[1].checked) {
// h:m:s:f
frames = Number(timeArray[3]);
}
break;
case 5:
frames = Number(timeArray[4]);
break;
}
//alert(hr + ", " + mn + ", " + sec + ", " + frames)
//alert(sign * (hr*3600 + mn*60 + sec))
return sign * frames;
}
// Takes an hr string, mn string, and sec string and converts to seconds
function stringToSeconds3(dayString, hrString, minString, secString) {
return (
Number(dayString) * 86400 +
Number(hrString) * 3600 +
Number(minString) * 60 +
Number(secString)
);
}
// Takes seconds and converts to h:m:s.s
function secondsToString(seconds, frames, displayFrames) {
if (typeof seconds == "undefined") var seconds = 0;
if (typeof frames == "undefined") var frames = 0;
if (typeof displayFrames == "undefined") var displayFrames = 0;
var myForm = document.timeCalc;
var timeSeparator = document.timeCalc.timeSeparator.value;
var sign = ""; // "-" for negative number
if (seconds < 0) {
sign = "-";
seconds = -1 * seconds;
}
var days = Math.floor(seconds / 86400);
var hr = Math.floor((seconds % 86400) / 3600);
var mn = Math.floor((seconds % 3600) / 60);
//var mn = Math.floor(seconds/60)%60
var sec = round3(seconds % 60);
var timeString = "";
//if (myForm.outputFormat[0].checked || myForm.outputFormat[2].checked || myForm.outputFormat[5].checked) {
// var timeString = "" + sec
//else if (myForm.outputFormat[1].checked || myForm.outputFormat[4].checked) {
// var timeString = "" + mn
//else
// var timeString = "" + hr
//}
if (myForm.outputFormat[0].checked || myForm.outputFormat[1].checked) {
// days:hr:min:sec:frames or days:hr:min:sec
if (days > 0) {
// d,h,m,s are all non-blank
timeString = days + timeSeparator;
if (hr >= 10) timeString = timeString + hr + timeSeparator;
else timeString = timeString + "0" + hr + timeSeparator;
if (mn >= 10) timeString = timeString + mn + timeSeparator;
else timeString = timeString + "0" + mn + timeSeparator;
if (sec >= 10) timeString = timeString + sec;
else timeString = timeString + "0" + sec;
} else if (hr > 0) {
// days is blank, h,m,s are non-blank
timeString = hr + timeSeparator;
if (mn >= 10) timeString = timeString + mn + timeSeparator;
else timeString = timeString + "0" + mn + timeSeparator;
if (sec >= 10) timeString = timeString + sec;
else timeString = timeString + "0" + sec;
} else if (mn > 0) {
// days and hrs are blank, m,s are non-blank
timeString = mn + timeSeparator;
if (sec >= 10) timeString = timeString + sec;
else timeString = timeString + "0" + sec;
} else timeString = sec; // days, hrs and min are blank
} else if (myForm.outputFormat[2].checked || myForm.outputFormat[4].checked) {
// hr:min:sec:frames or hr:min:sec
// days aren't shown, so merge days into hours
hr = days * 24 + hr;
if (hr > 0) {
// d is blank; h,m,s are all non-blank
timeString = hr + timeSeparator;
if (mn >= 10) timeString = timeString + mn + timeSeparator;
else timeString = timeString + "0" + mn + timeSeparator;
if (sec >= 10) timeString = timeString + sec;
else timeString = timeString + "0" + sec;
} else if (mn > 0) {
// days and hr are blank, m,s are non-blank
timeString = mn + timeSeparator;
if (sec >= 10) timeString = timeString + sec;
else timeString = timeString + "0" + sec;
} else timeString = sec; // days, hrs and min are blank
} else if (myForm.outputFormat[3].checked) {
// day:hr:min
// sec aren't shown, so merge seconds into minutes
mn = mn + round3(sec / 60.0);
if (days > 0) {
// d,h,m are all non-blank; s not shown
timeString = days + timeSeparator;
if (hr >= 10) timeString = timeString + hr + timeSeparator;
else timeString = timeString + "0" + hr + timeSeparator;
if (mn >= 10) timeString = timeString + mn + timeSeparator;
else timeString = timeString + "0" + mn + timeSeparator;
} else if (hr > 0) {
// days is blank; h,m are non-blank; s not shown
timeString = hr + timeSeparator;
if (mn >= 10) timeString = timeString + mn + timeSeparator;
else timeString = timeString + "0" + mn + timeSeparator;
} else timeString = mn;
} else if (myForm.outputFormat[6].checked) {
// days:hr
// min & sec aren't shown, so merge minutes & seconds into hours
hr = hr + mn / 60.0;
hr = round3(hr + sec / 3660.0);
if (days > 0) {
if (hr >= 10) timeString = days + timeSeparator + hr;
else timeString = days + timeSeparator + "0" + hr;
} else timeString = hr;
} else if (myForm.outputFormat[7].checked) {
// hr:min
// days & sec aren't shown, so merge days into hours & merge seconds into minutes
hr = days * 24 + hr;
mn = mn + round3(sec / 60.0);
if (hr > 0) {
if (mn >= 10) timeString = hr + timeSeparator + mn;
else timeString = hr + timeSeparator + "0" + mn;
} else timeString = mn;
} else if (myForm.outputFormat[5].checked || myForm.outputFormat[8].checked) {
// min:sec or min:sec:frames
// days,hr aren't shown, so merge days & hr into minutes
mn = days * 1440 + mn;
mn = hr * 60 + mn;
if (mn > 0) {
if (sec >= 10) timeString = mn + timeSeparator + sec;
else timeString = mn + timeSeparator + "0" + sec;
} else timeString = sec;
} else if (myForm.outputFormat[10].checked) {
// days
timeString = round3(seconds / 86400);
} else if (myForm.outputFormat[11].checked) {
// hr
timeString = round3(seconds / 3600);
} else if (myForm.outputFormat[12].checked) {
// min
timeString = round3(seconds / 60);
} else if (myForm.outputFormat[9].checked) {
// sec
timeString = round3(seconds);
} else {
// frames
timeString = round3(seconds);
}
if (displayFrames) {
if (frames >= 10) timeString = timeString + timeSeparator + frames;
else timeString = timeString + timeSeparator + "0" + frames;
}
return sign + timeString;
}
function round2(myNumber) {
return Math.floor(Math.round(myNumber * 100)) / 100;
}
function round3(myNumber) {
return Math.floor(Math.round(myNumber * 1000)) / 1000;
}
function saveData() {
var params = [];
for (i = 1; i <= 40; i++) {
// Save times
val = eval("document.timeCalc.time" + i + ".value");
if (val != "") {
// && !isNaN(val)
params[params.length] = "t" + i + "=" + val;
}
// Save comments
val = eval("document.timeCalc.comments" + i + ".value");
if (val != "") {
params[params.length] = "c" + i + "=" + encodeURI(val);
}
}
// Save options
if (document.timeCalc.plusMinusMode[0].checked == 1)
params[params.length] = "mode=0";
if (document.timeCalc.plusMinusMode[1].checked == 1)
params[params.length] = "mode=1";
if (document.timeCalc.singleFormat[0].checked == 1)
params[params.length] = "fs0=1";
if (document.timeCalc.singleFormat[1].checked == 1)
params[params.length] = "fs1=1";
if (document.timeCalc.singleFormat[2].checked == 1)
params[params.length] = "fs2=1";
if (document.timeCalc.singleFormat[3].checked == 1)
params[params.length] = "fs3=1";
if (document.timeCalc.singleFormat[4].checked == 1)
params[params.length] = "fs4=1";
if (document.timeCalc.timeFormat[0].checked == 1)
params[params.length] = "ft0=1";
if (document.timeCalc.timeFormat[1].checked == 1)
params[params.length] = "ft1=1";
if (document.timeCalc.timeFormat[2].checked == 1)
params[params.length] = "ft2=1";
if (document.timeCalc.timeFormat[3].checked == 1)
params[params.length] = "ft3=1";
if (document.timeCalc.time3Format[0].checked == 1)
params[params.length] = "f3t0=1";
if (document.timeCalc.time3Format[1].checked == 1)
params[params.length] = "f3t1=1";
if (document.timeCalc.time3Format[2].checked == 1)
params[params.length] = "f3t2=1";
if (document.timeCalc.time4Format[0].checked == 1)
params[params.length] = "f4t0=1";
if (document.timeCalc.time4Format[1].checked == 1)
params[params.length] = "f4t1=1";
params[params.length] =
"d=" + encodeURI(document.timeCalc.timeSeparator.value);
if (document.timeCalc.outputFormat[0].checked == 1)
params[params.length] = "o0=1";
if (document.timeCalc.outputFormat[1].checked == 1)
params[params.length] = "o1=1";
if (document.timeCalc.outputFormat[2].checked == 1)
params[params.length] = "o2=1";
if (document.timeCalc.outputFormat[3].checked == 1)
params[params.length] = "o3=1";
if (document.timeCalc.outputFormat[4].checked == 1)
params[params.length] = "o4=1";
if (document.timeCalc.outputFormat[5].checked == 1)
params[params.length] = "o5=1";
if (document.timeCalc.outputFormat[6].checked == 1)
params[params.length] = "o6=1";
if (document.timeCalc.outputFormat[7].checked == 1)
params[params.length] = "o7=1";
if (document.timeCalc.outputFormat[8].checked == 1)
params[params.length] = "o8=1";
if (document.timeCalc.outputFormat[9].checked == 1)
params[params.length] = "o9=1";
if (document.timeCalc.outputFormat[10].checked == 1)
params[params.length] = "o10=1";
if (document.timeCalc.outputFormat[11].checked == 1)
params[params.length] = "o11=1";
if (document.timeCalc.outputFormat[12].checked == 1)
params[params.length] = "o12=1";
if (document.timeCalc.outputFormat[13].checked == 1)
params[params.length] = "o13=1";
if (document.timeCalc.outputFormat[14].checked == 1)
params[params.length] = "o14=1";
//if (document.timeCalc.fractionType.checked == 1) params[params.length] = 'fps=100'
else if (!isNaN(document.timeCalc.fps.value))
params[params.length] = "fps=" + document.timeCalc.fps.value;
if (params.length == 0) var url = baseUrl;
else var url = baseUrl + "?" + params.join("&");
//prompt('URL should be copied to clipboard if you are on PC. If you are on mobile device, copy the URL here: ',url);
/* Alert the copied text */
alert("Original Run Link Copied to Clipboard");
document.getElementById("myInput").value = url;
var copyText = document.getElementById("myInput");
/* Select the text field */
copyText.select();
copyText.setSelectionRange(0, 99999); /* For mobile devices */
//navigator.clipboard.writeText(url);
/* Copy Data (longer to work on mobile) */
var oldContentEditable = myInput.contentEditable,
oldReadOnly = myInput.readOnly,
range = document.createRange();
myInput.contentEditable = true;
myInput.readOnly = false;
range.selectNodeContents(myInput);
var s = window.getSelection();
s.removeAllRanges();
s.addRange(range);
myInput.setSelectionRange(0, 999999); // A big number, to cover anything that could be inside the element.
myInput.contentEditable = oldContentEditable;
myInput.readOnly = oldReadOnly;
document.execCommand("copy");
finalurl = url;
//console.log(finalurl);
return finalurl;
}
function clearFields() {
for (i = 1; i <= 40; i++) {
eval("document.timeCalc.time" + i + '.value = ""');
}
for (i = 1; i <= 40; i++) {
eval("document.timeCalc.cumtime" + i + '.value = ""');
eval("document.timeCalc.comments" + i + '.value = ""');
}
document.timeCalc.timeMin.value = "";
document.timeCalc.timeMax.value = "";
document.timeCalc.timeAvg.value = "";
document.timeCalc.timeTotal.value = "";
document.timeCalc.timeMin2.value = "";
document.timeCalc.timeMax2.value = "";
document.timeCalc.timeAvg2.value = "";
document.timeCalc.timeTotal2.value = "";
document.timeCalc.time1.focus();
}
function addSeconds(sec1, sec2) {
//, fps) {
//if (typeof fps == "undefined") var fps = 1;
if (isNaN(sec1)) return sec2;
if (isNaN(sec2)) return sec1;
//if (fps2 == 100) {
// return sec1 + sec2;
//}
// else {
// Add the fractions
//alert(''+fps+' fps');
var aArray = sec1.toString().split(".");
var bArray = sec2.toString().split(".");
if (aArray.length < 2) aArray[1] = 0;
if (bArray.length < 2) bArray[1] = 0;
if (aArray[1].length < 2) aArray[1] = aArray[1] + "0";
if (bArray[1].length < 2) bArray[1] = bArray[1] + "0";
//alert(aArray[0] + ', ' + aArray[1] + ', ' + bArray[0] + ', ' + bArray[1]);
var tempTotal2 = parseInt(aArray[1]) + parseInt(bArray[1]);
//alert(''+aArray[0] +', '+bArray[0]);
//var tempTotal3 = parseInt(aArray[0]) + parseInt(bArray[0]) + Math.floor(tempTotal2/fps2);
var tempTotal3 = parseInt(aArray[0]) + parseInt(bArray[0]);
//var frames = tempTotal2%fps2;
//if (frames < 10) frames = '0' + frames.toString();
//alert(tempTotal3.toString()+'.'+frames);
//return(tempTotal3.toString()+'.'+frames);
return tempTotal3.toString();
//}
}
// Returns the value of the first selected radio button, else returns nil
function selectedRadioValue(radioGroupObj) {
// eg. document.mainForm.myRadioName
//var radioGroupObj = document.getElementsByName(radioName);
for (var i = 0; i < radioGroupObj.length; i++) {
if (radioGroupObj[i].checked) {
return radioGroupObj[i].value;
}
}
return nil;
}
function changeMode() {
if (document.timeCalc.plusMinusMode[0].checked) mode = "add";
else mode = "sub";
addTimes();
}
function addTimes(field = null) {
if (field) {
lazyInputDot(field);
lazyInputNoSepMode(field);
}
var prevTotalTime = 0;
var prevTotalFrames = 0;
var totalTime = 0;
var totalFrames = 0;
var minsec = 0;
var maxsec = 0;
var minFrames = 0;
var maxFrames = 0;
var count = 0;
var seconds = 0;
var frames = 0;
var origSeconds = 0;
var origFrames = 0;
var timeString = "";
var timeSeparator = document.timeCalc.timeSeparator.value;
var fps = document.timeCalc.fps.value;
if (fps == "" || isNaN(fps)) fps = 0;
else fps = parseInt(fps);
//if (isNaN(fps) || document.timeCalc.fractionType.checked == 1) fps = 100;
// Display the outputFormat
outFormat = selectedRadioValue(document.timeCalc.outputFormat).replace(
/:/g,
timeSeparator
);
writeLayer("totalFormatDisplay", " " + outFormat + " ");
writeLayer("outputFormatDisplay", " " + outFormat + " ");
writeLayer(
"inputFormatDisplay",
//' ' + 'd:h:m:s:f'.replace(/:/g,timeSeparator) + ' <br/>' +
" " +
selectedRadioValue(document.timeCalc.time4Format).replace(
/:/g,
timeSeparator
) +
" <br/>" +
" " +
selectedRadioValue(document.timeCalc.time3Format).replace(
/:/g,
timeSeparator
) +
" <br/>" +
" " +
selectedRadioValue(document.timeCalc.timeFormat).replace(
/:/g,
timeSeparator
) +
" <br/>" +
" " +
selectedRadioValue(document.timeCalc.singleFormat).replace(
/:/g,
timeSeparator
) +
" "
);
//Do frames get displayed?
if (
document.timeCalc.outputFormat[0].checked ||
document.timeCalc.outputFormat[2].checked ||
document.timeCalc.outputFormat[5].checked ||
document.timeCalc.outputFormat[9].checked ||
document.timeCalc.outputFormat[14].checked
) {
var displayFrames = true;
} else {
var displayFrames = false;
}
if (
(document.timeCalc.time4Format[1].checked == 1 ||
document.timeCalc.time3Format[2].checked == 1 ||
document.timeCalc.timeFormat[3].checked == 1 ||
document.timeCalc.singleFormat[4].checked == 1 ||
displayFrames) && // frames were selected
(document.timeCalc.fps.value == "" || document.timeCalc.fps.value < 1)
) {
alert("Please specify frames-per-second > 0");
document.timeCalc.fps.focus();
return;
}
for (i = 1; i <= 40; i++) {
myValue = eval("document.timeCalc.time" + i + ".value");
seconds = origSeconds = stringToSeconds(myValue);
frames = origFrames = stringToFrames(myValue);
//alert('sec1: '+seconds);
//alert('frames1: '+frames);
if (fps > 0) {
seconds = seconds + Math.floor(frames / fps);
//alert('sec2: '+seconds);
frames = frames % fps;
}
if (i == 1) {
minsec = origSeconds;
maxsec = origSeconds;
minFrames = origFrames;
maxFrames = origFrames;
}
eval("document.timeCalc.sec" + i + ".value = seconds");
if (mode == "add") {
// mode = add
totalFrames = totalFrames + frames;
} else {
// mode = subtract
if (i == 1) totalFrames = frames;
else totalFrames = totalFrames - frames;
}
if (fps > 0 && totalFrames >= fps) {
//alert('totalFrames (' + totalFrames + ') are over fps (' + fps + ')');
seconds = seconds + Math.floor(totalFrames / fps);
//alert('sec2: '+seconds);
totalFrames = totalFrames % fps;
}
if (seconds == 0 && (frames == 0 || !displayFrames)) {
eval("document.timeCalc.cumtime" + i + '.value = ""');
} else {
if (mode == "add") {
// mode = add
totalTime = totalTime + seconds;
} else {
// mode = subtract
if (i == 1) totalTime = seconds;
else totalTime = totalTime - seconds;
}
//totalTime = addSeconds(totalTime, seconds, fps);
//if (isNaN(totalTime)) totalTime = 0;
//alert('TotalTime:' + totalTime + ', totalFrames:' + totalFrames + ', displayFrames:' + displayFrames);
timeString = secondsToString(totalTime, totalFrames, displayFrames);
eval("document.timeCalc.cumtime" + i + ".value = timeString");
//eval('document.timeCalc.cumtime'+i+'.value = totalTime');
//minsec = Math.min(minsec, seconds);
//maxsec = Math.max(maxsec, seconds);
if (origSeconds <= minsec) {
if (origSeconds < minsec || origFrames <= minFrames) {
minFrames = origFrames;
}
minsec = origSeconds;
}
if (origSeconds >= maxsec) {
if (origSeconds > maxsec || origFrames >= maxFrames) {
maxFrames = origFrames;
}
maxsec = origSeconds;
}
//alert(origSeconds+' seconds; '+frames+' frames; '+minsec+' minsec; '+minFrames+' minFrames');
count = count + 1;
}
//alert(stringToSeconds(myValue) + ' secs, ' + stringToFrames(myValue)+ ' frames @ ' + fps + ' fps == ' + seconds + ' seconds, ' + frames + ' frames\n' +
// totalTime + ' total seconds, ' + totalFrames + ' total frames\n' +
// 'formatted (displayFrames=' + displayFrames + '): ' + secondsToString(totalTime, totalFrames, displayFrames) +
// '\nmin:'+minsec+':'+minFrames);
prevTotalTime = totalTime;
prevTotalFrames = totalFrames;
}
if (count > 0) {
document.timeCalc.timeMin.value = document.timeCalc.timeMin2.value =
secondsToString(minsec, minFrames, displayFrames);
document.timeCalc.timeMax.value = document.timeCalc.timeMax2.value =
secondsToString(maxsec, maxFrames, displayFrames);
document.timeCalc.timeAvg.value = document.timeCalc.timeAvg2.value =
secondsToString(totalTime / count, totalFrames / count, displayFrames);
} else {
document.timeCalc.timeMin.value = document.timeCalc.timeMin2.value = "";
document.timeCalc.timeMax.value = document.timeCalc.timeMax2.value = "";
document.timeCalc.timeAvg.value = document.timeCalc.timeAvg2.value = "";
}
document.timeCalc.timeTotal.value = document.timeCalc.timeTotal2.value =
secondsToString(totalTime, totalFrames, displayFrames);
//setTimeFromSec(totalTime, 0)
//alert('total frames: ' + totalFrames);
}
function checkKeyPress(nextFieldName, evt) {
var charCode = navigator.appName == "Netscape" ? evt.which : evt.keyCode;
if (charCode == 13) {
// 13 = enter/return
eval("document.timeCalc." + nextFieldName + ".focus()"); //Go to next field
} else if (charCode == 67) {
// 67 = Shift-C
clearFields();
return false;
}
return true;
}
function secToMins(sec) {
return sec / 60.0;
}
function secToHours(sec) {
return sec / 3600.0;
}
function minsToSec(mn) {
return mn * 60.0;
}
function hoursToSec(hr) {
return hr * 3600.0;
}
function changeFT(radioObj) {
// change FractionType (Decimal)
if (radioObj.checked) {
document.timeCalc.fps.value = "";
fps = 100;
}
addTimes();
}
function changeFps(textObj) {
if (isNaN(textObj.value)) {
alert("Frames per second must be a number");
textObj.value = "";
//document.timeCalc.fractionType.checked = true;
document.timeCalc.fps.focus();
} else {
//document.timeCalc.fractionType.checked = false;
fps = textObj.value;
}
addTimes();
}
function writeLayer(layerID, txt) {
if (document.getElementById) {
document.getElementById(layerID).innerHTML = txt;
} else if (document.all) {
document.all[layerID].innerHTML = txt;
} else if (document.layers) {
with (document.layers[layerID].document) {
open();
write(txt);
close();
}
}
}
// var myDate = new Date(2000, 0, 0)
// myDate.setSeconds
// alert(myDate.toString())
var fps = 100; // decimal by default
var baseUrl;
function initPage() {
// Parse url parameters
var param, num, val;
var queryIndex = window.location.href.indexOf("?");
var params = window.location.href.substring(queryIndex + 1).split("&");
if (queryIndex < 0) baseUrl = window.location.href; // no '?' found in url
else baseUrl = window.location.href.substring(0, queryIndex);
if (typeof mode == "undefined") var mode = "add"; // default
for (i = 0; i < params.length; i++) {
param = params[i].split("=");
if (param[0].substr(0, 1) == "t") {
// if t1 - t40, then restore it's time value
num = param[0].substring(1);
if (num != "" && !isNaN(num)) {
eval("document.timeCalc.time" + num + '.value="' + param[1] + '"');
}
} else if (param[0].substr(0, 1) == "c") {
// Restore comments
num = param[0].substring(1);
if (num != "" && !isNaN(num)) {
eval(
"document.timeCalc.comments" +
num +
'.value="' +
decodeURI(param[1]) +
'"'
);
}
} else if (param[0].substr(0, 3) == "f4t") {
// Four-value time format
num = param[0].substring(3);
if (num != "" && !isNaN(num)) {
eval("document.timeCalc.time4Format[" + num + "].checked=1");
}
} else if (param[0].substr(0, 3) == "f3t") {
// Three-value time format
num = param[0].substring(3);
if (num != "" && !isNaN(num)) {
eval("document.timeCalc.time3Format[" + num + "].checked=1");
}
} else if (param[0].substr(0, 2) == "ft") {
// Two-value time format
num = param[0].substring(2);
if (num != "" && !isNaN(num)) {
eval("document.timeCalc.timeFormat[" + num + "].checked=1");
}
} else if (param[0].substr(0, 2) == "fs") {
// One-value time format
num = param[0].substring(2);
if (num != "" && !isNaN(num)) {
eval("document.timeCalc.singleFormat[" + num + "].checked=1");
}
} else if (param[0] == "d") {
// Time delimiter
eval(
'document.timeCalc.timeSeparator.value ="' + decodeURI(param[1]) + '"'
);
} else if (param[0].substr(0, 1) == "o") {
// output format
num = param[0].substring(1);
if (num != "" && !isNaN(num)) {
eval("document.timeCalc.outputFormat[" + num + "].checked=1");
}
} else if (param[0] == "fps") {
// frames/second
num = param[1]; // fps
if (num != "" && !isNaN(num)) {
//if (num == 100) document.timeCalc.fractionType.checked = 1
//else {
//document.timeCalc.fractionType.checked = 0;
document.timeCalc.fps.value = num;
fps = num;
//}
}
} else if (param[0] == "mode") {
// PlusMinusMode
num = param[1]; // mode index
if (num == 0) {
mode = "add";
document.timeCalc.plusMinusMode[0].checked = true;
document.timeCalc.plusMinusMode[1].checked = false;
} else if (num == 1) {
mode = "sub";
document.timeCalc.plusMinusMode[0].checked = false;
document.timeCalc.plusMinusMode[1].checked = true;
}
}
}
window.focus();
addTimes();
document.timeCalc.time1.focus();
return true;
}
function lazyInputDot(field) {
if (!document.getElementById("lazyinput1").checked) return;
field.value = field.value.replaceAll(".", ":");
}
function lazyInputNoSepMode(field) {
if (!document.getElementById("lazyinput2").checked) return;
let len = field.value.length;
let temp_val = field.value;
if (
field.value.indexOf(":") == -1 &&
field.value.indexOf(".") == -1 &&
len > 2
) {
temp_val = temp_val.split("").reverse().join("");
temp_val = temp_val.match(/.{1,2}/g).join(":");
temp_val = temp_val.split("").reverse().join("");
field.value = temp_val;
}
}
function lazyAdd() {
var reset = false;
var time = document.getElementById("lazytime").value;
var level = document.getElementById("lazylevel").value;
var pos_time = -1;
var pos_level = -1;
if (document.getElementById("lazyreset").checked) {
reset = true;
}
if (time) {
var el_times = document.querySelectorAll(".times");
[...el_times].every((el_time, index) => {
if (!el_time.value) {
pos_time = index;
return false;
}
return true;
});
}
if (level) {
var el_levels = document.querySelectorAll(".comments");
[...el_levels].every((el_level, index) => {
if (!el_level.value) {
pos_level = index;
return false;
}
return true;
});
}
var pos = Math.max(pos_time, pos_level);
if (pos != -1) {
if (time) {
el_times[pos].value = time;
addTimes(el_times[pos]);
}
if (level) {
el_levels[pos].value = reset ? level + " Reset" : level;
}
}
lazyClear();
}
function lazyClear() {
document.getElementById("lazytime").value = "";
document.getElementById("lazylevel").value = "";
document.getElementById("lazyreset").checked = false;
}
function formatComments() {
const comments = document.querySelectorAll(
".comments:not(:placeholder-shown)"
);
comments.forEach((comment) => {
comment.value = comment.value.replaceAll("(", "");
comment.value = comment.value.replaceAll(")", "");
// add more if needed
});
}
function clearRowInput(event) {
var input = event.target.parentNode.querySelector("input");
input.value = "";
}