-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
2509 lines (2408 loc) · 88 KB
/
index.html
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
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html>
<head>
<title>
Lists
</title>
<base target="_blank">
<link rel="icon" href="favicon.ico">
<script src="https://www.gstatic.com/firebasejs/4.6.1/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.6.1/firebase-firestore.js"></script>
<script src="https://epicenterprograms.github.io/standards/behavior/firebaseinit.js"></script>
<script src="https://epicenterprograms.github.io/standards/behavior/general.js"></script>
<script src="https://epicenterprograms.github.io/standards/behavior/storage.js"></script>
<!--
<script src="file:///C:/Users/rtben/Documents/GitHub/standards/behavior/general.js"></script>
<script src="file:///C:/Users/rtben/Documents/GitHub/standards/behavior/storage.js"></script>
-->
<script>
var S = Standards.general;
var M = Standards.storage;
M.session.defaultLocation = "/lists/Default/items"; //// "lists/items" "lists/default/items"
M.local.defaultLocation = "/lists/Default/items"; //// "lists/items" "lists/default/items"
M.server.defaultLocation = "/lists"; //// "lists/default/items"
var currentList = "Default";
var itemSet = {};
var itemNumber = 1;
var now = new Date();
var week = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
var dayThreshold = 7;
var mergeData = false;
var deleteData = false;
var advancedSettingsSection;
var advancedEditorSection;
var pastDueNumber = 0;
var dueTodayNumber = 0;
var storagePlace = "local";
var noisemaker;
var labelList = [];
var itemBeingEdited = "";
var recyclingBin = {};
var sampleList = [
{
description: "finish my math homework",
elaboration: "chapter 7, activity 5, questions 5-20",
importance: 4,
recurrence: "weekly",
time: "monday wednesday friday~11:59 pm",
difficulty: 4,
lastFinished: now.getTime(),
done: false,
lastUpdated: now.getTime()
},
{
description: "go to work",
importance: 4,
recurrence: "weekly",
time: "monday tuesday wednesday thursday friday~4:00 pm",
lastFinished: now.getTime(),
done: false,
lastUpdated: now.getTime()
},
{
description: "oil the door hinge",
importance: 1,
recurrence: "indefinite",
time: now.getTime() + 86400000 + "~",
difficulty: 2,
lastFinished: now.getTime() - 172800000,
done: false,
lastUpdated: now.getTime()
},
{
description: "brush my teeth",
importance: 3,
recurrence: "daily",
time: "~10:30 pm",
difficulty: 1,
lastFinished: now.getTime(),
done: false,
labels: ["sanitary"],
lastUpdated: now.getTime()
},
{
description: "cut the grass",
importance: 2,
recurrence: "indefinite",
time: now.getTime() + 700000000 + "~",
difficulty: 4,
lastFinished: now.getTime(),
done: false,
lastUpdated: now.getTime()
},
{
description: "go to Joe's party",
importance: 2,
recurrence: "once",
time: function () {
let time = new Date(now.getTime() + 345600000);
return (time.getMonth()+1) + "/" + time.getDate() + "/" + time.getFullYear() + "~8:00 pm";
}(),
lastFinished: now.getTime(),
done: false,
labels: ["fun"],
lastUpdated: now.getTime()
},
{
description: "take out the trash",
importance: 3,
recurrence: "weekly",
time: "friday~7:00 pm",
lastFinished: now.getTime(),
done: true,
labels: ["sanitary"],
lastUpdated: now.getTime()
},
{
description: "have game night",
elaboration: "play hangman, charades, and Apples to Apples",
importance: 2,
recurrence: "monthly",
time: "10~8:00 pm",
lastFinished: now.getTime(),
done: false,
labels: ["fun"],
lastUpdated: now.getTime()
},
{
description: "sign up for the charity event",
elaboration: "5 Giving Way, room 213",
importance: 2,
recurrence: "once",
time: function () {
let time = new Date(now.getTime() - 86400000);
return (time.getMonth() + 1) + "/" + time.getDate() + "/" + time.getFullYear() + "~5:00 pm";
}(),
lastFinished: now.getTime()-172800000,
done: false,
lastUpdated: now.getTime()
},
{
description: "find my keys",
elaboration: "check under the couch",
importance: 5,
recurrence: "indefinite",
time: now.getTime() + "~",
difficulty: 5,
lastFinished: now.getTime(),
done: true,
lastUpdated: now.getTime()
},
{
description: "have breakfast with Sally",
importance: 3,
recurrence: "once",
time: (function () {
let year = (now.getMonth()>10 ? now.getFullYear()+1 : now.getFullYear());
let month = ((now.getMonth()>10 ? 0 : now.getMonth()+1)+1);
let day = (now.getDate()+1);
let time = "~8:00 am";
if (String(month).length == 1) {
month = "0" + month;
}
if (String(day).length == 1) {
day = "0" + day;
}
return year + " " + month + " " + day + time;
})(),
lastFinished: now.getTime(),
done: false,
labels: ["fun"],
lastUpdated: now.getTime()
},
{
description: "clean my room",
importance: 2,
recurrence: "continual",
time: now.getTime() + 2200000000 + "~",
difficulty: 5,
lastFinished: now.getTime() - 1000000000,
done: false,
labels: [],
lastUpdated: now.getTime()
},
{
description: "go jogging",
importance: 5,
recurrence: "continual",
time: now.getTime() + "~",
difficulty: 3,
lastFinished: now.getTime() - 200000000,
done: false,
labels: [],
lastUpdated: now.getTime()
}
];
function makeDynamicItem(description, item) {
/**
adds a dynamic list item to itemSet
*/
// makes a Date object for the due date (assigned to "then")
let importance = item.importance;
let date = item.time;
let recurrence = item.recurrence;
let lastFinished = item.lastFinished;
let done = item.done;
let labels = item.labels;
var originalDate = date;
var then = date.split("~")[0].trim();
var time = " " + date.split("~")[1].trim();
function combine(array) {
return new Date(array.join(" ") + time);
}
let beginning = new Date(Number(lastFinished));
switch (recurrence) { // sets the exact time of the (next) event
case "continual":
case "indefinite":
then = new Date(Number(then)); // Number() is needed because "then" is a string
// "date" can't also be set here because it causes the due time displayed to always be what it was originally
break;
case "once":
if (then.includes("/")) { ////
then = new Date([].concat(then.split("/")[2], then.split("/").slice(0, 2)).join(" ") + time);
date = then.getMonth() + 1 + "/" + then.getDate() + "/" + then.getFullYear() + time;
} else {
then = new Date(then + time);
date = then.getMonth() + 1 + "/" + then.getDate() + "/" + then.getFullYear() + time;
}
break;
case "monthly":
if (beginning.getDate() == then) {
if (beginning.getTime() <= combine([beginning.getFullYear(), beginning.getMonth()+1, then]).getTime()) {
then = combine([beginning.getFullYear(), beginning.getMonth()+1, then]);
} else {
if (beginning.getMonth() + 2 <= 12) {
then = combine([beginning.getFullYear(), beginning.getMonth()+2, then]);
} else {
then = combine([beginning.getFullYear()+1, 1, then]);
}
}
} else if (beginning.getDate() < then) {
then = new Date(beginning.getTime() + (then-beginning.getDate())*86400000);
} else {
if (beginning.getMonth() + 2 <= 12) {
then = combine([beginning.getFullYear(), beginning.getMonth()+2, then]);
} else {
then = combine([beginning.getFullYear()+1, 1, then]);
}
}
date = then.getMonth()+1 + "/" + then.getDate() + "/" + then.getFullYear() + time;
break;
case "weekly":
let closest = Infinity;
then.split(" ").forEach(function(weekday) {
let number = week.indexOf(weekday);
if (beginning.getDay() > number) {
number = 7 + number - beginning.getDay();
} else {
number -= beginning.getDay();
}
if (number < closest) {
closest = number;
}
});
closest += beginning.getDay();
if (closest > 6) {
closest -= 7;
}
if (beginning.getDay() == closest) {
if (beginning.getTime() <= combine([beginning.getFullYear(), beginning.getMonth()+1, beginning.getDate()]).getTime()) {
then = combine([beginning.getFullYear(), beginning.getMonth()+1, beginning.getDate()]);
} else {
closest = Infinity;
then.split(" ").forEach(function(weekday) {
let number = week.indexOf(weekday);
if (beginning.getDay() + 1 > number) {
number = 6 + number - beginning.getDay();
} else {
number -= beginning.getDay() + 1;
}
if (number < closest) {
closest = number;
}
});
closest += beginning.getDay() + 1;
if (closest > 6) {
closest -= 7;
}
if (beginning.getDay() < closest) {
then = new Date(beginning.getTime() + (closest-beginning.getDay())*86400000);
then = combine([then.getFullYear(), then.getMonth()+1, then.getDate()]);
} else {
then = new Date(beginning.getTime() + (7+closest-beginning.getDay())*86400000);
then = combine([then.getFullYear(), then.getMonth()+1, then.getDate()]);
}
}
} else if (beginning.getDay() < closest) {
then = new Date(beginning.getTime() + (closest-beginning.getDay())*86400000);
then = combine([then.getFullYear(), then.getMonth()+1, then.getDate()]);
} else {
then = new Date(beginning.getTime() + (7+closest-beginning.getDay())*86400000);
then = combine([then.getFullYear(), then.getMonth()+1, then.getDate()]);
}
date = then.getMonth()+1 + "/" + then.getDate() + "/" + then.getFullYear() + time;
break;
case "daily":
then = combine([beginning.getFullYear(), beginning.getMonth()+1, beginning.getDate()]);
if (beginning.getTime() > then.getTime()) {
then = new Date(then.getTime()+86400000);
}
date = then.getMonth()+1 + "/" + then.getDate() + "/" + then.getFullYear() + time;
break;
}
// sets the urgency of the item
now = new Date();
if (recurrence == "indefinite" || recurrence == "continual") {
date = then.getTime() - now.getTime();
if (date <= 0) {
date = "Immediately";
} else if (date <= 250000000) {
date = "Soon";
} else if (date <= 700000000) {
date = "Later";
} else if (date <= 1600000000) {
date = "In a while";
} else {
date = "At some point";
}
var urgency = (then.getTime()-now.getTime())/1000;
if (urgency < 54000) { // Negative numbers will put it at the end, not the top.
urgency = 54000; // This causes indefinite items to effectively never be any closer than 15 hours away.
}
urgency = Math.round(urgency * (10-importance));
} else if (recurrence == "daily") {
var urgency = Math.round(Math.abs(then.getTime()-now.getTime())/100*(10-importance));
} else {
var urgency = Math.round(Math.abs(then.getTime()-now.getTime())/1000*(10-importance));
}
if (item.difficulty) {
urgency = Math.round(urgency * ((6 - item.difficulty) / 2));
} else {
urgency = Math.round(urgency * 1.5);
}
// creates the HTML objects to be displayed
let checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.id = "item" + itemNumber;
itemNumber++;
let label = document.createElement("span");
if (recurrence == "indefinite" || recurrence == "continual") {
label.title = "Due: {0}\nImportance: {1}".format(date, importance);
} else {
if (then.getTime() - now.getTime() < 86400000) {
label.title = "Due:{0}\nImportance: {1}".format(time, importance);
} else if (then.getTime() - now.getTime() < 518400000) {
label.title = "Due: {0}\nImportance: {1}".format(["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][then.getDay()]+time, importance);
} else {
label.title = "Due: {0}\nImportance: {1}".format(["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][then.getDay()]+", "+date, importance);
}
}
label.innerHTML = decodeURIComponent(description);
// sets label highlighting
if (then.getTime() >= now.getTime() || recurrence == "indefinite" || recurrence == "continual") {
let later;
if (recurrence == "indefinite") {
if (then.getTime() <= now.getTime()) {
label.style.fontWeight = "bold";
if (importance == 5) {
label.style.textDecoration = "underline";
} else if (importance == 4) {
label.style.WebkitTextDecorationStyle = "dotted"; // for Safari
label.style.textDecoration = "underline dotted";
}
label.innerHTML = "<mark style='background:#00ff00'>" + label.innerHTML + "</mark>";
} else if (then.getTime() - now.getTime() < (then.getTime()-lastFinished) / 3) {
label.innerHTML = "<mark style='background:#88ff88'>" + label.innerHTML + "</mark>";
}
} else if (recurrence == "continual") {
if (then.getTime() <= now.getTime()) {
label.style.fontWeight = "bold";
label.innerHTML = "<mark style='background:#00aaff'>" + label.innerHTML + "</mark>";
} else if (then.getTime() - now.getTime() < (then.getTime()-lastFinished) / 3) {
label.innerHTML = "<mark style='background:#88aaff'>" + label.innerHTML + "</mark>";
}
} else if (recurrence == "daily") {
if (then.getTime() - now.getTime() < 10800000) { // if it's closer than 3 hours away
label.style.fontWeight = "bold";
if (importance == 5) {
label.style.textDecoration = "underline";
} else if (importance == 4) {
label.style.WebkitTextDecorationStyle = "dotted";
label.style.textDecoration = "underline dotted";
}
label.innerHTML = "<mark style='background:#ff00ff'>" + label.innerHTML + "</mark>";
} else if (then.getTime() - now.getTime() < 21600000) { // if it's closer than 6 hours away
label.innerHTML = "<mark style='background:#ff88ff'>" + label.innerHTML + "</mark>";
}
} else {
////////////////////////////////////////// setting the due-today number should be done somewhere around here
if (now.getHours() < dayThreshold) { // if the current time is before the day threshold (defaults to 8:00am)
later = new Date(new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime() + 86400000);
} else {
later = new Date(new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime() + 172800000);
}
if (then.getTime() < later.getTime()) {
label.style.fontWeight = "bold";
if (importance == 5) {
label.style.textDecoration = "underline";
} else if (importance == 4) {
label.style.WebkitTextDecorationStyle = "dotted";
label.style.textDecoration = "underline dotted";
}
label.innerHTML = "<mark>" + label.innerHTML + "</mark>";
} else if (then.getTime() < later.getTime() + 86400000) {
label.innerHTML = "<mark style='background:#ffff88'>" + label.innerHTML + "</mark>";
}
}
} else {
label.style.fontWeight = "bold";
if (importance == 5) {
label.style.textDecoration = "underline solid red";
} else if (importance == 4) {
label.style.WebkitTextDecorationStyle = "dotted";
label.style.textDecoration = "underline dotted red";
}
label.style.color = "red";
label.title = "Past due";
pastDueNumber++;
}
// puts the elements into a container
let section = document.createElement("section");
section.className = "list-item";
section.appendChild(checkbox);
section.appendChild(label);
if (item.elaboration) { // if there's an elaboration
let img = document.createElement("img");
img.src = "expandable.svg";
img.className = "icon";
section.appendChild(img);
}
let elements = document.createElement("div");
elements.appendChild(section);
// crosses out finished items
if (done) {
if (then.getTime() < now.getTime() && recurrence != "indefinite" && recurrence != "continual") {
pastDueNumber--;
}
label.style.textDecoration = "line-through";
label.title = "Finished";
label.style.color = "inherit";
label.style.fontWeight = "inherit";
if (label.children.length > 0) { // if there's a <mark> tag
label.children[0].style.background = "inherit";
}
if (recurrence != "indefinite" && recurrence != "once" && now.getTime() > then.getTime()) {
lastFinished = then.getTime() + 1;
done = false;
let storedItem = M[storagePlace].recall(description);
storedItem.lastFinished = lastFinished;
storedItem.done = done;
M[storagePlace].store(description, storedItem);
var needsToRunFunctionAgain = true;
}
}
/*
if (done) {
function handler(mutations, observer) {
mutations.forEach(function(mutation) {
mutation.addedNodes.forEach(function(node) {
if (node == checkbox) {
checkbox.check();
watcher.disconnect();
}
});
});
}
var watcher = new MutationObserver(handler) || webkitMutationObserver(handler);
watcher.observe(getId("list"), {"childList":true, "subtree":true});
}
*/
// adds the item to the priority list or runs the function again
if (needsToRunFunctionAgain) {
item.time = originalDate;
item.lastFinished = lastFinished;
item.done = done;
makeDynamicItem(description, item);
} else {
if (isNaN(urgency) || S.getType(urgency) != "Number") {
throw 'The item with the description "' + decodeURIComponent(description) + '" has a non-number urgency.';
}
let increment = 0;
while (itemSet[urgency + increment] != undefined) {
// while there's a target key value already taken, increase the target key by 1
// (prevents overwriting when things have the same due-date and importance)
increment++;
}
itemSet[urgency+increment] = {description: decodeURIComponent(description), importance: importance, done: done, elements: elements.innerHTML, labels: labels};
}
}
function makeStaticItem(description, item) {
/**
adds a static list item to itemSet
*/
// creates the HTML objects to be displayed
let checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.id = "item" + itemNumber++;
let label = document.createElement("span");
label.title = "Item position: " + item.position;
label.innerHTML = decodeURIComponent(description);
// sets label highlighting
if (!item.positioned && !item.done) {
label.innerHTML = "<mark>" + label.innerHTML + "</mark>";
}
// puts the elements into a container
let section = document.createElement("section");
section.className = "list-item";
section.appendChild(checkbox);
section.appendChild(label);
if (item.elaboration) { // if there's an elaboration
let img = document.createElement("img");
img.src = "expandable.svg";
img.className = "icon";
section.appendChild(img);
}
let elements = document.createElement("div");
elements.appendChild(section);
// crosses out finished items
if (item.done) {
label.style.textDecoration = "line-through";
label.title = "Finished";
}
if (item.position>0 && itemSet.hasOwnProperty(item.position-1) || item.position<0 && itemSet.hasOwnProperty(item.position)) { // if the position is taken
// corrects the stored items
S.forEach(M[storagePlace].list(), function (key) {
if (description != key) {
let currentItem = M[storagePlace].recall(key);
if (item.position > 0) {
if (currentItem.position >= item.position) {
currentItem.position++;
}
} else {
if (currentItem.position <= item.position) {
currentItem.position--;
}
}
M[storagePlace].store(key, currentItem);
}
});
// corrects the items in itemSet
let newSet = [];
S.forEach(itemSet, function (value, placement) {
newSet.push({ placement: Number(placement), value: value });
});
S.forEach(newSet, function (currentItem) {
if (item.position > 0) {
if (currentItem.placement >= item.position - 1) {
currentItem.placement++;
}
} else {
if (currentItem.placement <= item.position - 1) {
currentItem.placement--;
}
}
});
itemSet = {};
S.forEach(newSet, function (obj) {
itemSet[obj.placement] = obj.value;
});
}
if (item.position > 0) {
itemSet[item.position-1] = { description: decodeURIComponent(description), importance: item.importance, done: item.done, elements: elements.innerHTML, labels: item.labels };
} else {
itemSet[item.position] = { description: decodeURIComponent(description), importance: item.importance, done: item.done, elements: elements.innerHTML, labels: item.labels };
}
}
function makeRandomItem(description, item) {
/**
adds a randomly ordered list item to itemSet
*/
// creates the HTML objects to be displayed
let checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.id = "item" + itemNumber++;
let label = document.createElement("span");
label.title = "Importance: " + item.importance;
label.innerHTML = decodeURIComponent(description);
// sets label highlighting
if (now.getTime() - item.lastUpdated > 2000000000) { // if it's been more than about 23 days
label.style.fontWeight = "bold";
if (importance == 5) {
label.style.textDecoration = "underline";
} else if (importance == 4) {
label.style.WebkitTextDecorationStyle = "dotted"; // for Safari
label.style.textDecoration = "underline dotted";
}
label.innerHTML = "<mark>" + label.innerHTML + "</mark>";
} else if (now.getTime() - item.lastUpdated > 1000000000) { // if it's been more than about 11.5 days
label.innerHTML = "<mark style='background:#ffff88'>" + label.innerHTML + "</mark>";
}
// puts the elements into a container
let section = document.createElement("section");
section.className = "list-item";
section.appendChild(checkbox);
section.appendChild(label);
if (item.elaboration) { // if there's an elaboration
let img = document.createElement("img");
img.src = "expandable.svg";
img.className = "icon";
section.appendChild(img);
}
let elements = document.createElement("div");
elements.appendChild(section);
// crosses out finished items
if (item.done) {
label.style.textDecoration = "line-through";
label.title = "Finished";
label.style.color = "inherit";
label.style.fontWeight = "inherit";
if (label.children.length > 0) { // if there's a <mark> tag
label.children[0].style.background = "inherit";
}
}
// sets the placement
let placement = Math.round((6-item.importance) * 100 + Math.random() * 100 - 50);
// adds the item to the priority list
let increment = 0;
while (itemSet[placement + increment] != undefined) {
// while there's a target key value already taken, increase the target key by 1
// (prevents overwriting when things have the same due-date and importance)
increment++;
}
itemSet[placement + increment] = { description: decodeURIComponent(description), importance: item.importance, done: item.done, elements: elements.innerHTML, labels: item.labels };
}
function includeDynamicItem() {
let enoughInformation = true;
if (!(S.getId("description").value.trim() && S.getId("importance").value && S.getId("recurrence").value)) {
enoughInformation = false;
} else {
if (S.getId("recurrence").value == "indefinite") {
if (!S.getId("timeframe").value) {
enoughInformation = false;
}
} else if (S.getId("recurrence").value != "continual") {
if (!S.getId("time").value) {
enoughInformation = false;
}
}
}
if (enoughInformation) {
now = new Date();
let description = encodeURIComponent(S.getId("description").value.trim().replace(/</g, "<").replace(/>/g, ">"));
let date = "";
let time = S.getId("time").value.trim();
if (time.search(/\d(?:am|pm)/) > -1) { // if there's an am or pm not preceeded by a space
time = time.slice(0, time.indexOf("m")-1) + " " + time.slice(time.indexOf("m")-1);
}
switch (S.getId("recurrence").value) {
case "continual":
date = now.getTime() + Math.pow(6-Number(S.getId("importance").value), 2) * 200000000;
case "indefinite":
switch (S.getId("timeframe").value) { // sets when the highlight will become most apparent
case "immediately":
date = 0; // now
break;
case "soon":
date = 250000000; // in a little less than 3 days
break;
case "later":
date = 700000000; // in a little more than 8 days
break;
case "aWhile":
date = 1600000000; // in about 18.5 days
break;
case "somePoint":
date = 3628800000; // in exactly 42 days
break;
case "same":
date = Number(M[storagePlace].recall(description).time.split("~")[0]) - now.getTime(); // at the pre-estblished time
break;
}
if (time > 0 && S.getId("timeframe").value != "same") {
date += date*.1 * (Math.random()*2-1); // varies the time set by 10% (helps prevent a bunch of things being due at the same time)
}
date += now.getTime();
break;
case "once":
date = S.getId("fullDate").value.replace(/-/g, " ");
/* //// previously for quick selecting with a day of the week
var then = S.getId("fullDate").value;
then = week.indexOf(then.toLowerCase());
if (now.getDay() == then) {
if (now.getTime() <= new Date([now.getFullYear(), now.getMonth() + 1, now.getDate()].join(" ") + " " + time).getTime()) {
date = now.getMonth() + 1 + "/" + now.getDate() + "/" + now.getFullYear();
} else {
then = new Date(now.getTime() + 604800000);
date = then.getMonth() + 1 + "/" + then.getDate() + "/" + then.getFullYear();
}
} else if (now.getDay() < then) {
then = new Date(now.getTime() + (then - now.getDay()) * 86400000);
date = then.getMonth() + 1 + "/" + then.getDate() + "/" + then.getFullYear();
} else {
then = new Date(now.getTime() + (7 + then - now.getDay()) * 86400000);
date = then.getMonth() + 1 + "/" + then.getDate() + "/" + then.getFullYear();
}
*/
break;
case "monthly":
date = S.getId("day").value;
break;
case "weekly":
let numberChecked = 0;
week.forEach(function(ID) {
if (S.getId(ID).checked) {
date += ID + " ";
numberChecked++;
}
});
if (numberChecked == 0) { //// This checking should integrate with enoughInformation.
alert("You need to check at least one day of the week.");
return;
}
date.trim();
break;
}
date += "~" + time;
// sets labels
let labels = S.getId("labels").value.trim().split(",");
S.forEach(labels, function (label, index) {
labels[index] = label.trim();
});
// stores the information
if (S.getId("recurrence").value == "indefinite" && S.getId("timeframe").value == "same") {
M[storagePlace].store(description, { importance: S.getId("importance").value, time: date, recurrence: S.getId("recurrence").value, lastFinished: M[storagePlace].recall(description).lastFinished, lastUpdated: now.getTime(), done: false, labels: labels, elaboration: S.getId(advancedEditorSection, "elaboration").value, difficulty: Number(advancedEditorSection.querySelector("#difficulty").value) });
} else {
M[storagePlace].store(description, { importance: S.getId("importance").value, time: date, recurrence: S.getId("recurrence").value, lastFinished: now.getTime(), lastUpdated: now.getTime(), done: false, labels: labels, elaboration: S.getId(advancedEditorSection, "elaboration").value, difficulty: Number(advancedEditorSection.querySelector("#difficulty").value) });
}
// resets stuff
cancel();
// refreshes the list
refresh();
setTimeout(function () {
refresh(true);
}, 0);
// randomly displays inspiring messages (if desired)
if (S.getId(advancedSettingsSection, "inspiringMessages").checked && Math.floor(Math.random()*5) == 0) {
let messages = ["You're the best!", "You're worth it.", "Nothing can stop you.", "You rock!", "You're an amazing person.", "The world wouldn't be the same without you.", "I love you."];
S.makeDialog(messages[Math.floor(Math.random()*messages.length)], "Thank you");
}
} else {
alert("You left out at least one required field.");
}
}
function includeStaticItem() {
let enoughInformation = true;
if (S.getId("description").value.trim() == "") {
enoughInformation = false;
}
if (enoughInformation) {
now = new Date();
// sets the position
let position;
let unfinishedListLength = 0;
let positioned = false;
S.forEach(M[storagePlace].list(), function (key) {
if (!M[storagePlace].recall(key).done) {
unfinishedListLength++;
}
});
if (S.getId("positioner").value.trim() == "") {
if (S.getId("importance").value == "") {
position = unfinishedListLength + 1;
} else {
position = Math.ceil(unfinishedListLength * (6-Number(S.getId("importance").value)) / 5 + 1);
positioned = true;
}
} else {
position = Number(S.getId("positioner").value);
positioned = true;
}
if (position < 1) {
position = 1;
}
if (position > unfinishedListLength + 1) {
position = unfinishedListLength + 1;
} else if (position < unfinishedListLength + 1) {
S.forEach(M[storagePlace].list(), function (key) {
let item = M[storagePlace].recall(key);
if (item.position >= position) {
item.position++;
M[storagePlace].store(key, item);
}
});
}
// sets labels
let labels = S.getId("labels").value.trim().split(",");
S.forEach(labels, function (label, index) {
labels[index] = label.trim();
});
// stores the information
M[storagePlace].store(encodeURIComponent(S.getId("description").value.trim().replace(/</g, "<").replace(/>/g, ">")), { position: position, importance: S.getId("importance").value, done: false, positioned: positioned, lastFinished: now.getTime(), lastUpdated: now.getTime(), labels: labels, elaboration: S.getId(advancedEditorSection, "elaboration").value });
// resets stuff
cancel();
// refreshes the list
refresh();
setTimeout(function () {
refresh(true);
}, 0);
// randomly displays inspiring messages (if desired)
if (S.getId(advancedSettingsSection, "inspiringMessages").checked && Math.floor(Math.random()*5) == 0) {
let messages = ["You're the best!", "You're worth it.", "Nothing can stop you.", "You rock!", "You're an amazing person.", "The world wouldn't be the same without you.", "I love you."];
S.makeDialog(messages[Math.floor(Math.random()*messages.length)], "Thank you");
}
} else {
alert("You left out at least one required field.");
}
}
function includeRandomItem() {
let enoughInformation = true;
if (S.getId("description").value.trim() == "" || S.getId("importance").value == "") {
enoughInformation = false;
}
if (enoughInformation) {
now = new Date();
// sets labels
let labels = S.getId("labels").value.trim().split(",");
S.forEach(labels, function (label, index) {
labels[index] = label.trim();
});
// stores the information
M[storagePlace].store(encodeURIComponent(S.getId("description").value.trim().replace(/</g, "<").replace(/>/g, ">")), { importance: S.getId("importance").value, done: false, lastUpdated: now.getTime(), labels: labels, elaboration: S.getId(advancedEditorSection, "elaboration").value });
// resets stuff
cancel();
// refreshes the list
refresh();
setTimeout(function () {
refresh(true);
}, 0);
// randomly displays inspiring messages (if desired)
if (S.getId(advancedSettingsSection, "inspiringMessages").checked && Math.floor(Math.random() * 5) == 0) {
let messages = ["You're the best!", "You're worth it.", "Nothing can stop you.", "You rock!", "You're an amazing person.", "The world wouldn't be the same without you.", "I love you."];
S.makeDialog(messages[Math.floor(Math.random() * messages.length)], "Thank you");
}
} else {
alert("You left out at least one required field.");
}
}
function showHide() {
switch (S.getId("recurrence").value) {
case "indefinite":
S.getId("once").style.display = "none";
S.getId("weekly").style.display = "none";
S.getId("monthly").style.display = "none";
S.getId("timeSection").style.display = "none";
S.getId("indefinite").style.display = "block";
break;
case "once":
S.getId("indefinite").style.display = "none";
S.getId("monthly").style.display = "none";
S.getId("weekly").style.display = "none";
S.getId("once").style.display = "block";
S.getId("timeSection").style.display = "block";
break;
case "monthly":
S.getId("indefinite").style.display = "none";
S.getId("once").style.display = "none";
S.getId("weekly").style.display = "none";
S.getId("monthly").style.display = "block";
S.getId("timeSection").style.display = "block";
break;
case "weekly":
S.getId("indefinite").style.display = "none";
S.getId("once").style.display = "none";
S.getId("monthly").style.display = "none";
S.getId("weekly").style.display = "table";
S.getId("timeSection").style.display = "block";
break;
case "daily":
S.getId("indefinite").style.display = "none";
S.getId("once").style.display = "none";
S.getId("monthly").style.display = "none";
S.getId("weekly").style.display = "none";
S.getId("timeSection").style.display = "block";
break;
case "continual":
default:
S.getId("indefinite").style.display = "none";
S.getId("once").style.display = "none";
S.getId("monthly").style.display = "none";
S.getId("weekly").style.display = "none";
S.getId("timeSection").style.display = "none";
break;
}
}
function mergeInformation(localTakesPrecedence) {
////
now = new Date();
S.getId("list").innerHTML = "<p>Syncing your data...</p>";
itemSet = {};
pastDueNumber = 0;
dueTodayNumber = 0;
recyclingBin = {};
////
new Promise(function (resolve, reject) {
if (localTakesPrecedence) { // if the local information should be given precedence over the server information
S.getId("list").innerHTML = "<p>Storing your data...</p>";
let information = M[storagePlace].list("/lists/");
information.splice(information.indexOf("start-up settings"), 1);
let listenable = new S.Listenable();
listenable.value = 0;
listenable.addEventListener("set", function (value) {
if (value >= information.length) { // when all items have been stored
S.getId("list").innerHTML = "<p>Deleting unwanted server information...</p>";
listenable.removeEventListener("set", arguments.callee);
listenable.value = undefined;
M.server.list("./", function (data) {
listenable.value = 0;
listenable.addEventListener("set", function (itemsLeft) {
if (itemsLeft == 0) {
listenable.removeEventListener("set", arguments.callee);
resolve();
}
});
if (data.length > 0) {
// deletes account data not not present in the current data
let deleting = false;
S.forEach(data, function (key) {
if (!information.includes(key)) {
deleting = true;
listenable.value++;
recyclingBin[key] = { // basically just retains the description as a reminder in case worst comes to worst
importance: 5,
recurrence: "indefinite",
time: now.getTime() + "~",
difficulty: 3,
lastFinished: now.getTime(),
done: false,
lastUpdated: now.getTime()
};
M.server.forget("./" + key, function () {
listenable.value--;
}).catch(function (error) {
reject(error);
});
}
});
if (!deleting) {
listenable.value = 0;
}
} else {
resolve();
}
}).catch(function (error) {
reject(error);
});
}
});
if (information.length > 0) {