-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex3.html
More file actions
1354 lines (1249 loc) · 47.7 KB
/
index3.html
File metadata and controls
1354 lines (1249 loc) · 47.7 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
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 lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!-- Стандартный favicon -->
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" type="image/png" href="favicon-96x96.png" sizes="96x96" />
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<link rel="manifest" href="site.webmanifest" />
<!-- Для iOS/Android -->
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png">
<title>Тайм-трекер | Мой рабочий день</title>
<style>
:root {
/* ------ Цвета (основные и вспомогательные) ------ */
--color-accent: #3a7afe;
--color-accent-hover: #236dfc;
--color-accent-light: #b3d1fd;
--color-accent-xlight: #e4eaff;
--color-bg: #eef3fa;
--color-bg-white: #fff;
--color-bg-footer: #f5f8fe;
--color-bg-btn-active: #e4eaff;
--color-bg-dual-btn: #cafaff;
--color-bg-dual-btn-last: #e4eaff;
--color-bg-calendar: #e8f1ff;
--color-bg-export: #fffbe7;
--color-input-error: #ffe7e7;
--color-weekend: #ff6b6b;
--color-weekend-bg: #fff0f0;
--color-close-btn: #ff4757;
--color-close-btn-hover: #ff2e43;
--color-txt: #222;
--color-txt-grey: #555;
--color-txt-accent: #2995fa;
--color-txt-small: #888;
--color-txt-export: #993;
--color-txt-calendar: #217;
--color-txt-badge: #fff;
--color-txt-error: #ff4343;
/* Остальное */
--radius-main: 18px;
--radius-calendar: 12px;
--radius-export: 14px;
--radius-badge: 8px;
--shadow: 0 3px 20px #0001;
--footer-height: 60px;
--container-padding-v: 1.5rem;
--container-padding-h: 1rem;
--container-padding-bottom: 80px;
}
/* ----- Тёмная тема ----- */
body.dark-theme {
--color-accent: #4f8dff;
--color-accent-hover: #266ce5;
--color-accent-light: #3666e680;
--color-accent-xlight: #262c3f;
--color-bg: #23252a;
--color-bg-white: #23252a;
--color-bg-footer: #242830;
--color-bg-btn-active: #313641;
--color-bg-dual-btn: #242830;
--color-bg-dual-btn-last: #323844;
--color-bg-calendar: #2a2d35;
--color-bg-export: #191b16;
--color-input-error: #691818;
--color-weekend: #ff7f7f;
--color-weekend-bg: #3a2a2a;
--color-close-btn: #ff6b6b;
--color-close-btn-hover: #ff5252;
--color-txt: #f4f6fd;
--color-txt-grey: #aab2c8;
--color-txt-accent: #8bb8ff;
--color-txt-small: #8d99b4;
--color-txt-export: #cca;
--color-txt-calendar: #9ac2ff;
--color-txt-badge: #fff;
--color-txt-error: #ff4343;
}
/* === Базовая сетка и плавность === */
body, .container, .footer-bar, .btn, .dual-btn, .modal-inner, .export {
transition: background .22s, color .22s, border-color .22s;
}
body {
background: var(--color-bg);
color: var(--color-txt);
margin: 0;
padding: 0;
font-family: system-ui,sans-serif;
min-height: 100vh;
}
.container {
padding: var(--container-padding-v) var(--container-padding-h);
padding-bottom: var(--container-padding-bottom);
max-width: 420px;
margin: auto;
background: var(--color-bg-white);
border-radius: var(--radius-main);
margin-top: 3vh;
box-shadow: var(--shadow);
}
h1 {
margin: 0 0 12px;
font-size: 2rem;
font-weight: bold;
color: var(--color-accent);
text-align: center;
}
/* ===== FLEX GRID/COMMON ===== */
.row {
display: flex;
gap: 10px;
margin-bottom: 12px;
}
.row-col {
flex-direction: column;
gap: 6px;
}
.fullw { width:100%; display:block; }
.center { text-align:center; }
hr { margin:16px 0; }
/* ========== Кастомные элементы форм ========== */
/* --- ЧЕКБОКСЫ --- */
input[type="checkbox"] {
appearance: none; -webkit-appearance: none;
width:36px; height:20px; border-radius:16px;
background: var(--color-bg-dual-btn);
border:2px solid var(--color-accent-light);
position: relative;
outline: none; cursor: pointer;
vertical-align: middle;
transition: background .18s, border-color .22s;
margin-right:10px; box-shadow:none;
}
input[type="checkbox"]:checked {
background: var(--color-accent);
border-color: var(--color-accent);
}
input[type="checkbox"]::before {
content:''; position:absolute; left:3px; top:3px;
width:14px; height:14px; border-radius:50%;
background: var(--color-bg-white);
transition: transform .18s, background .22s;
box-shadow: 0 2px 7px #0001;
}
input[type="checkbox"]:checked::before {
transform: translateX(16px);
background: var(--color-bg-white);
}
input[type="checkbox"]:focus-visible {
outline:2px solid var(--color-accent); outline-offset:2px;
}
/* --- SELECT --- */
select {
appearance: none; -webkit-appearance: none;
background: var(--color-bg-dual-btn);
color: var(--color-txt);
border:2px solid var(--color-accent-light);
border-radius:12px;
font-size:1em;
padding: 0.34em 2.2em 0.34em 0.7em;
outline: none;
margin-right:7px; min-width:70px;
transition: background .22s, color .22s, border-color .22s;
box-shadow: none; cursor:pointer; position:relative;
}
select:focus-visible, select:focus { border-color:var(--color-accent); }
select[multiple] { min-height:2.4em; }
select:not([multiple]) {
background-image: url('data:image/svg+xml;utf8,<svg height="18" width="18" xmlns="http://www.w3.org/2000/svg"><path d="M4 7l5 5 5-5" stroke="%23666" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/></svg>');
background-repeat:no-repeat;
background-position:right 0.7em center;
background-size: 1.2em 1.2em;
}
body.dark-theme select:not([multiple]) {
background-image: url('data:image/svg+xml;utf8,<svg height="18" width="18" xmlns="http://www.w3.org/2000/svg"><path d="M4 7l5 5 5-5" stroke="%23aabafc" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/></svg>');
}
/* --- NUMBER INPUT --- */
input[type="number"] {
background: var(--color-bg-dual-btn);
color: var(--color-txt);
border:2px solid var(--color-accent-light);
border-radius:10px; font-size:1em;
padding:0.28em 0.7em; outline:none;
margin-right:5px; box-shadow:none;
transition: background .22s, color .22s, border-color .22s;
}
input[type="number"]:focus { border-color: var(--color-accent); }
/* --- Generic text input? (ненавязчиво) --- */
input[type="text"], input[type="time"] {
background: var(--color-bg-dual-btn);
color: var(--color-txt);
border: 2px solid var(--color-accent-light);
border-radius: 10px;
font-size: 1em;
padding: .28em .7em;
outline: none;
transition: background .22s, color .22s, border-color .22s;
box-shadow: none;
}
input[type="text"]:focus, input[type="time"]:focus {
border-color: var(--color-accent);
}
/* --- Input Error --- */
input.input-error {
border: 2px solid var(--color-txt-error) !important;
background: var(--color-input-error) !important;
animation: shake .4s;
}
/* ==== Dual-кнопки & Основные кнопки ==== */
.dual-btn {
display:flex; flex-direction:row; flex:1 1 0;
border-radius:var(--radius-main); overflow:hidden;
border:2px solid var(--color-accent);
}
.dual-btn .btn {
border:none; border-radius:0; font-size:1.2rem;
background:var(--color-bg-white);
color:var(--color-accent);
box-shadow:none; flex:1 1 0;
display:flex; flex-direction:column;
align-items:center; justify-content:center;
min-width:0; padding:0.85em 0.5em;
}
.dual-btn .btn:first-child { border-right:1px solid var(--color-accent-light); background:var(--color-bg-dual-btn);}
.dual-btn .btn:last-child { background:var(--color-bg-dual-btn-last);}
.btn {
background:var(--color-bg-white);
border:2px solid var(--color-accent);
color:var(--color-accent);
border-radius:var(--radius-main);
font-size:1.3rem; padding:1em 1em;
flex: 1 1 auto; font-weight:500;
cursor:pointer; transition:.1s;
box-shadow:var(--shadow);
}
.btn.active, .btn:active {
background:var(--color-bg-btn-active);
color:var(--color-bg-white);
border-color:var(--color-accent);
}
.btn-sub {
font-size:.76em; color:var(--color-txt-accent);
margin-top:2px; font-weight:400;
letter-spacing:.02em; line-height:1;
}
/* Кнопка-редактирование */
.edit {
background:none; border:none;
color:var(--color-accent);
font-size:1.2em; cursor:pointer; margin-left:6px;
}
/* Кнопка закрытия/отмены */
.btn-close {
background: var(--color-close-btn);
color: white;
border: 2px solid var(--color-close-btn);
}
.btn-close:hover, .btn-close:active {
background: var(--color-close-btn-hover);
border-color: var(--color-close-btn-hover);
}
/* ===== Теги и списки ===== */
.tags-list { margin:.4em 0 0; padding:0; list-style:none;}
.tags-list li { padding:.2em 0; }
.badge {
background:var(--color-accent);
color:var(--color-txt-badge);
border-radius:var(--radius-badge);
padding:.1em .7em; font-size:1em;
}
.small { font-size:.92em; color:var(--color-txt-small); }
/* ==== Календарные кнопки ==== */
.cal-btn {
font-size:1rem; padding:.2em 1em;
margin:.2em; border-radius:var(--radius-calendar);
background:var(--color-bg-calendar);
border: none; color: var(--color-txt-calendar); cursor:pointer;
}
.cal-btn.selected { background:var(--color-accent); color:var(--color-bg-white);}
.cal-btn.weekend {
background: var(--color-weekend-bg);
color: var(--color-weekend);
}
.cal-btn.weekend.selected {
background: var(--color-weekend);
color: white;
}
.sw-btn { margin:.1em .2em; }
/* Дни недели в календаре */
.week-days {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 5px;
margin-bottom: 10px;
text-align: center;
font-weight: bold;
}
.week-day {
padding: 5px;
font-size: 0.9em;
}
.week-day.weekend {
color: var(--color-weekend);
}
/* ==== КНОПКИ В ПОДВАЛЕ ==== */
.footer-bar {
position: fixed; left:0; right:0; bottom:0;
background: var(--color-bg-footer);
border-top: 1px solid var(--color-accent-light);
display: flex; justify-content: space-around; align-items: stretch;
z-index: 10; height: var(--footer-height);
}
.footer-btn {
flex:1 1 0; background:var(--color-bg-white);
border:1px solid var(--color-accent-light);
font-size:1.20em;
color:var(--color-accent);
padding:7px 0 3px 0;
cursor:pointer; outline:none;
display:flex; flex-direction:column; align-items:center; gap:0;
transition:background .15s;
border-radius:8px; line-height:1.0; min-width:0;
user-select:none; margin: 5px 3px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.footer-btn:active, .footer-btn:focus { background:var(--color-bg-btn-active);}
.footer-btn span {
font-size:.74em; color:var(--color-txt-grey);
margin-top:2px; font-weight:400;
}
/* ==== МОДАЛЬНОЕ ОКНО ==== */
.modal {
position: fixed; top:0; left:0; right:0; bottom:0;
background: #0002; z-index:22;
display:flex; align-items:center; justify-content:center;
}
.modal-inner {
scroll-behavior: smooth; background:var(--color-bg-white);
padding:1.2em; border-radius:20px;
max-width:350px; width:95%;
box-shadow:var(--shadow);
max-height:90vh; overflow-y:auto;
}
.close-btn {
float:right; background:none;
border:none; color:#a44; font-size:1.4em; cursor:pointer;
}
/* ==== Экспорт, настройки ==== */
.export {
background:var(--color-bg-export);
padding:.7em .8em; border-radius:var(--radius-export);
margin-top:.6em; color:var(--color-txt-export);
box-shadow: 0 2px 12px #d7dcaf29;
}
/* Добавим стиль для textarea внутри экспорта */
.export textarea {
border-radius:9px;
outline:none;
border:1.2px solid var(--color-accent-xlight);
background: #fffdec;
padding:.7em .9em;
font-size:1em;
width:98%;
min-height:110px;
margin-bottom: 8px;
box-shadow: 0 1px 6px #b7b07130;
color:#625440;
resize:vertical;
}
body.dark-theme .export textarea {
background: #24241e;
color: #dcc;
}
/* Кнопочки в разделе экспорта - делаем компактнее, но читаемыми */
.export .btn {
margin-top:7px;
font-size:1em;
padding:.5em 1em;
border-radius:10px;
}
.export .btn:first-of-type { margin-top:12px; }
/* ==== Ряд с фильтрами в экспорте ==== */
.setting-row {
display:flex; align-items:center; gap:7px; margin:.5em 0;
}
/* ==== Состояния ошибок ==== */
input.input-error {
border:2px solid var(--color-txt-error)!important;
background:var(--color-input-error)!important;
animation:shake .4s;
}
/* ==== АНИМАЦИИ ==== */
@keyframes shake {
0% {transform:translateX(0px);}
20%{transform:translateX(-5px);}
40%{transform:translateX(5px);}
60%{transform:translateX(-4px);}
80%{transform:translateX(4px);}
100%{transform:translateX(0px);}
}
/* ==== Адаптив ==== */
@media (max-width: 400px) {
:root { --footer-height: 48px;}
.container { padding:.5em .3em; margin-top:1vh;}
h1 { font-size:1.3rem;}
.btn { font-size:1rem; padding:.6em .2em;}
.footer-btn span { font-size: 0.70em;}
.footer-btn { font-size: 1.02em;}
.export textarea { font-size:.95em; }
.footer-btn {
padding: 5px 0 2px 0;
margin: 3px 2px;
}
}
@media (min-width: 401px) {
.container { margin-top:6vh;}
}
</style>
</head>
<body>
<div class="container" id="app"></div>
<div class="footer-bar">
<button class="footer-btn" onclick="showCalendar()">📅<br><span>Календарь</span></button>
<button class="footer-btn" onclick="showExport()">📤<br><span>Экспорт</span></button>
<button class="footer-btn" onclick="showSettings()">⚙️<br><span>Настройки</span></button>
<button class="footer-btn" onclick="showAbout()">ℹ️<br><span>О приложении</span></button>
</div>
<!-- Модальное окно (редактор тегов/времени/экспорт/отчет) -->
<div id="modal" style="display:none;"></div>
<script>
/** ================================================================
* TIME TRACKER — основной js-файл приложения
* Все функции, UI и логика
* ================================================================ */
/** === CONSTANTS =============== */
const STORAGE_KEY = "myworkdays22";
const SETTINGS_KEY = "myworkdays_settings";
const DEFAULT_TAG = "НАСТРОЙКА ОБОРУДОВАНИЯ";
const APP_VERSION = "1.0.0 (2024-06-05)"; // для About
/** === LOCALSTORAGE — INIT =============== */
// Основной массив дней с тэгами
let days = JSON.parse(localStorage.getItem(STORAGE_KEY) || "[]");
// Список тэгов
let tagsLib = JSON.parse(localStorage.getItem("tagsLib22") || "[]");
if (!Array.isArray(tagsLib) || tagsLib.length === 0) {
tagsLib = [DEFAULT_TAG];
} else if (!tagsLib.includes(DEFAULT_TAG)) {
tagsLib.unshift(DEFAULT_TAG);
}
// Глобальные настройки UI/защиты
let appSettings = JSON.parse(localStorage.getItem(SETTINGS_KEY) || '{}');
if (typeof appSettings.copyProtect === "undefined") appSettings.copyProtect = false;
if (typeof appSettings.noZoom === "undefined") appSettings.noZoom = false;
if (typeof appSettings.theme === "undefined") appSettings.theme = "light";
if (typeof appSettings.autoTheme === "undefined") appSettings.autoTheme = true;
// =========== SETTINGS HELPERS ==================
function saveSettings() {
localStorage.setItem(SETTINGS_KEY, JSON.stringify(appSettings));
}
function saveAll() {
localStorage.setItem(STORAGE_KEY, JSON.stringify(days));
localStorage.setItem("tagsLib22", JSON.stringify(tagsLib));
}
/** === UI-BEHAVIOR INIT ============ */
function updateCopyProtect() {
if (appSettings.copyProtect) {
document.body.addEventListener('copy', blockCopy, true);
document.body.style.userSelect = "none";
} else {
document.body.removeEventListener('copy', blockCopy, true);
document.body.style.userSelect = "";
}
}
function blockCopy(e) { e.preventDefault(); }
function updateNoZoom() {
let viewport = document.querySelector('meta[name="viewport"]');
if (viewport) {
if (appSettings.noZoom) {
viewport.setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no');
} else {
viewport.setAttribute('content', 'width=device-width, initial-scale=1.0');
}
}
}
function updateTheme() {
if (appSettings.autoTheme && window.matchMedia) {
appSettings.theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
document.body.classList.toggle("dark-theme", appSettings.theme === "dark");
}
if (window.matchMedia) {
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', ()=> {
if(appSettings.autoTheme) updateTheme();
});
}
/** === BASIC HELPERS ======================= */
function findDay(date) { return days.find(d => d.date === date); }
function todayStr() { return (new Date()).toISOString().slice(0,10); }
function toHM(dt) { let [h,m]=dt.split(":").map(Number); return [h||0,m||0]; }
function fromHM(h, m) { return (h<10?'0':'')+h+":"+(m<10?'0':'')+m; }
function roundTime(timeStr, roundMin=10, direction='round') {
let [h, m] = toHM(timeStr);
let total = h*60+m, q = total / roundMin, res;
if(direction==='down') res = Math.floor(q);
else if(direction==='up') res = Math.ceil(q);
else res = Math.round(q);
total = res*roundMin; h = Math.floor(total/60); m = total%60;
return fromHM(h, m);
}
function diffMinutes(tm1, tm2) {
let [h1,m1]=toHM(tm1), [h2,m2]=toHM(tm2);
return (h2*60+m2)-(h1*60+m1);
}
// == INIT UI SETTINGS ==
updateCopyProtect();
updateNoZoom();
updateTheme();
function roundMinutes(totalMin, step=10, direction='round') {
let q = totalMin / step, res;
if(direction==='down') res = Math.floor(q);
else if(direction==='up') res = Math.ceil(q);
else res = Math.round(q);
return res * step;
}
/* === ЭКСПОРТ ОТЧЁТА === */
function showExport() {
let minDate = days.length ? days[0].date : todayStr();
let maxDate = days.length ? days[days.length-1].date : todayStr();
let html = `
<div><b>Экспортировать отчёт</b></div>
<form id="reportForm">
<div class="setting-row">Период:
<select id="per">
<option value="1-15">1–15</option>
<option value="16-31">16–31</option>
<option value="full">Весь месяц</option>
<option value="range">Период</option>
</select>
<input type="date" id="dfrom" style="display:none" value="${minDate}"> -
<input type="date" id="dto" style="display:none" value="${maxDate}">
</div>
<div class="setting-row">Экспорт:
<select id="expType">
<option value="all">Всё</option>
<option value="tags">Только теги</option>
<option value="work">Только рабочие часы (приход/уход)</option>
</select>
</div>
<div class="setting-row">Округление:
<select id="roundM">
<option value="60">До 1 часа</option>
<option value="30">До 30 мин</option>
<option value="10" selected>До 10 мин</option>
</select>
<select id="roundDir">
<option value="round">Обычно</option>
<option value="up">Вверх</option>
<option value="down">Вниз</option>
</select>
</div>
<div class="setting-row">Теги: <select multiple id="tagsFlt" style="min-width:70px;min-height:2em;">
${tagsLib.map(t=>`<option value="${t}" selected>${t}</option>`).join("")}
</select> <span class="small">(для режима "теги")</span></div>
<button class="btn fullw" type="submit">Экспортировать</button>
<button class="btn btn-close fullw" type="button" onclick="closeModal()">Отмена</button>
</form>
<div id="exportResult"></div>
`;
showModal(html);
let perSel = document.getElementById("per");
let fromD = document.getElementById("dfrom");
let toD = document.getElementById("dto");
perSel.onchange = function() {
if(perSel.value==='range'){
fromD.style.display='inline';
toD.style.display='inline';
} else {
fromD.style.display='none';
toD.style.display='none';
}
};
document.getElementById("reportForm").onsubmit = function(e) {
e.preventDefault();
let period = perSel.value;
let from = fromD.value || minDate;
let to = toD.value || maxDate;
let exp = document.getElementById("expType").value;
let roundM = +document.getElementById("roundM").value;
let roundDir = document.getElementById("roundDir").value;
let tagsFlt = Array.from(document.getElementById("tagsFlt").selectedOptions).map(op=>op.value);
let list;
if (period === "1-15") {
list = days.filter(d=>+d.date.slice(8,10)<=15 && inThisMonth(d.date));
} else if(period === "16-31") {
list = days.filter(d=>+d.date.slice(8,10)>=16 && inThisMonth(d.date));
} else if(period === "range") {
list = days.filter(d=>d.date >= from && d.date <= to);
} else { // full
list = days.filter(d=>inThisMonth(d.date));
}
function inThisMonth(dt) {
let selm = days.length ? days[days.length-1].date.slice(5,7) : todayStr().slice(5,7);
return dt.slice(5,7) === selm;
}
let rows = [];
let tagTotals = {};
// ===== ОТЧЁТ ПО РАБОЧЕМУ ВРЕМЕНИ =====
if (exp === 'work' || exp === 'all') {
for (const d of list) {
if (!d.start || !d.end) continue;
let mins = diffMinutes(d.start, d.end);
let rounded = roundMinutes(mins, roundM, roundDir);
let hr = Math.floor(rounded / 60), mn = rounded % 60;
rows.push(`${d.date}: ${d.start} – ${d.end} (${hr}ч ${mn}м)`);
}
}
// ===== ОТЧЁТ ПО ТЕГАМ =====
if (exp === 'tags' || exp === 'all') {
for (const d of list) {
if (!d.tags?.length) continue;
for (const tag of d.tags) {
if (tagsFlt.includes(tag.tag)) {
let mins = diffMinutes(tag.start, tag.end);
if (!tagTotals[tag.tag]) tagTotals[tag.tag] = 0;
tagTotals[tag.tag] += mins > 0 ? mins : 0;
let rounded = roundMinutes(mins, roundM, roundDir);
let hr = Math.floor(rounded / 60), mn = rounded % 60;
rows.push(`${d.date}: ${tag.tag} — ${tag.start}-${tag.end} (${hr}ч ${mn}м)`);
}
}
}
if (Object.keys(tagTotals).length) {
rows.push('\nСуммарно по тегам:');
for (const tag of Object.keys(tagTotals)) {
let tot = tagTotals[tag];
let rounded = roundMinutes(tot, roundM, roundDir);
let hr = Math.floor(rounded / 60), mn = rounded % 60;
rows.push(`${tag}: ${hr}ч ${mn}м`);
}
}
}
let resTxt = rows.join('\n');
document.getElementById("exportResult").innerHTML =
`<div class="export"><b>Готовый текст:</b><br>
<textarea style="width:98%;min-height:120px">${resTxt}</textarea>
<br>
<button class="btn" type="button" onclick="downloadText()">Скачать .txt</button>
<button class="btn" type="button" onclick="copyExportText()">Скопировать</button>
<button class="btn" type="button" onclick="shareToTelegram()">Отправить в Telegram</button>
</div>`;
window.export__text = resTxt;
return false;
};
}
// --- ОТПРАВИТЬ В TELEGRAM ---
function shareToTelegram() {
if (!window.export__text) return;
let text = window.export__text;
if (text.length > 4000) text = text.slice(0, 4000) + '...';
let url = "https://t.me/share/url?url=&text=" + encodeURIComponent(text);
window.open(url, "_blank");
}
// --- СКОПИРОВАТЬ В БУФЕР ---
function copyExportText() {
if (!window.export__text) return;
if (navigator.clipboard) {
navigator.clipboard.writeText(window.export__text)
.then(() => { alert("Текст скопирован!"); })
.catch(() => { fallbackCopy(); });
} else {
fallbackCopy();
}
function fallbackCopy() {
try {
let ta = document.createElement("textarea");
ta.value = window.export__text;
document.body.appendChild(ta);
ta.select();
document.execCommand('copy');
ta.remove();
alert("Текст скопирован!");
} catch {
alert("Не удалось скопировать.");
}
}
}
// --- СКАЧАТЬ TXT ---
function downloadText() {
let b = new Blob([window.export__text || ""], { type:"text/plain" });
let link = document.createElement("a");
link.href = URL.createObjectURL(b);
link.download = "work_report.txt";
link.click();
}
/** =========================================================
* MAIN RENDER FUNCTION (главная страница)
* ========================================================= */
function renderApp() {
let dt = todayStr();
let day = findDay(dt);
let rows = [];
rows.push(`<h1>Мой рабочий день</h1>`);
rows.push(`
<div class="row">
<div class="dual-btn">
<button class="btn" onclick="markNow('start')">➔ ${day?.start || '--:--'}<div class="btn-sub">ТЕКУЩЕЕ ВРЕМЯ</div></button>
<button class="btn" onclick="openManualTime('start')">🕒<div class="btn-sub">ВЫБРАТЬ ВРЕМЯ</div></button>
</div>
<div class="dual-btn">
<button class="btn" onclick="markNow('end')">⏱ ${day?.end || '--:--'}<div class="btn-sub">ТЕКУЩЕЕ ВРЕМЯ</div></button>
<button class="btn" onclick="openManualTime('end')">🕒<div class="btn-sub">ВЫБРАТЬ ВРЕМЯ</div></button>
</div>
</div>
`);
// Итог рабочего дня
if(day?.start && day?.end) {
let time = diffMinutes(day.start, day.end);
rows.push(`<div class="center"><span class="badge">${Math.floor(time/60)}ч ${(time%60).toString().padStart(2,"0")}м</span> общий рабочий день</div>`);
}
// ======= Список тэгов и итоги по тегам ========
rows.push(`<hr><div><b>Деятельность:</b></div>`);
let tagSums = {};
if (day?.tags?.length) {
rows.push('<ul class="tags-list">');
day.tags.forEach((t, i) => {
let st = t.start, en = t.end;
let mins = (st && en) ? diffMinutes(st, en) : 0;
if (!tagSums[t.tag]) tagSums[t.tag] = 0;
tagSums[t.tag] += mins > 0 ? mins : 0;
let hr = Math.floor(mins/60), mn = mins%60;
rows.push(
`<li>
<b>${t.tag}</b> ${st || '--:--'}…${en || '--:--'}${mins>0 ? ` <span class="small">(${hr}ч ${mn}м)</span>` : ''}
<div class="row" style="margin:.3em 0;flex-wrap:wrap;">
<div class="dual-btn">
<button class="btn" onclick="markTagNow(${i}, 'start')">➔ ${t.start || '--:--'}<div class="btn-sub">ТЕКУЩЕЕ</div></button>
<button class="btn" onclick="manualTagTime(${i}, 'start')">🕒<div class="btn-sub">ВЫБРАТЬ</div></button>
</div>
<div class="dual-btn">
<button class="btn" onclick="markTagNow(${i}, 'end')">⏱ ${t.end || '--:--'}<div class="btn-sub">ТЕКУЩЕЕ</div></button>
<button class="btn" onclick="manualTagTime(${i}, 'end')">🕒<div class="btn-sub">ВЫБРАТЬ</div></button>
</div>
<button class="edit" onclick="editTag(${i})" title="Редактировать тег">✎</button>
<button class="edit" onclick="delTag(${i})" title="Удалить тег">✕</button>
</div>
</li>`);
});
// + добавить новый тег
rows.push(`
<li>
<button class="btn fullw" onclick="addTagPlus()" style="display:flex;align-items:center;gap:7px;justify-content:center;margin-top:4px;">
➕<span style="color:#888;font-size:.96em;">Добавить тег</span>
</button>
</li>
`);
rows.push('</ul>');
// Итоги по тегам за сегодня
if (Object.keys(tagSums).length > 0) {
rows.push(`<div class="small" style="margin:7px 0 0 2px;"><b>Итого по тегам за сегодня:</b><br>`);
for (const tag in tagSums) {
let tot = tagSums[tag], hr = Math.floor(tot/60), mn = tot%60;
rows.push(`${tag}: ${hr}ч ${mn}м<br>`);
}
rows.push(`</div>`);
}
} else {
rows.push(`<div class="small">Пока не добавлено</div>
<button class="btn fullw" onclick="addTagPlus()">➕ Добавить тег</button>`);
}
rows.push(`<hr>`);
// Завершаем рендер
document.getElementById('app').innerHTML = rows.join('\n');
closeModal();
}
window.renderApp = renderApp;
/** === MARK HANDLERS ==== */
function markNow(type) {
let dt = todayStr(), now = new Date(), h = now.getHours(), m = now.getMinutes();
let tstr = fromHM(h, m); let day = findDay(dt);
if(!day) { day = {date: dt, start: '', end: '', tags:[]}; days.push(day);}
day[type] = tstr; saveAll(); renderApp();
}
function openManualTime(type) {
let dt = todayStr(), day = findDay(dt) || { date: dt, start: '', end: '', tags: [] };
let val = (day[type] && /^\d\d:\d\d$/.test(day[type]))
? day[type]
: (() => {let d = new Date(), h = d.getHours(), m = d.getMinutes(); return (h<10?'0':'')+h+":"+(m<10?'0':'')+m;})();
let label = type === "start" ? "Время прихода" : "Время ухода";
let html = `
<form id="manualTimeForm">
<label>${label}:<br>
<input type="time" id="manualTimeInput" value="${val}" required>
</label>
<div class="row" style="margin-top:16px;">
<button class="btn fullw" type="submit">Сохранить</button>
<button type="button" class="btn btn-close fullw" onclick="closeModal()">Отмена</button>
</div>
</form>
`;
showModal(html);
document.getElementById('manualTimeForm').onsubmit = function(e) {
e.preventDefault();
const input = document.getElementById('manualTimeInput');
const t = input.value.trim();
if (!t) {
input.classList.add('input-error');
input.focus();
setTimeout(() => input.classList.remove('input-error'), 1000);
alert('Пожалуйста, выберите время!');
return;
}
let curday = findDay(dt);
if(!curday) { curday = { date: dt, start: '', end: '', tags: [] }; days.push(curday); }
curday[type] = t;
saveAll();
renderApp();
};
}
function markTagNow(idx, type) {
let dt = todayStr();
let day = findDay(dt);
if (!day || !day.tags[idx]) return;
let now = new Date();
let h = now.getHours(), m = now.getMinutes();
let tstr = fromHM(h, m);
day.tags[idx][type] = tstr;
saveAll();
renderApp();
}
function manualTagTime(idx, type) {
let dt = todayStr();
let day = findDay(dt);
let t = (day && day.tags[idx] && day.tags[idx][type]) || "";
let label = (type === "start" ? "Начало тега" : "Конец тега");
let html = `
<form id="manualTagTimeForm">
<label>${label}:<br>
<input type="time" id="manualTagTimeInput" value="${t}" required>
</label>
<div class="row" style="margin-top:16px;">
<button class="btn fullw" type="submit">Сохранить</button>
<button type="button" class="btn btn-close fullw" onclick="closeModal()">Отмена</button>
</div>
</form>
`;
showModal(html);
document.getElementById('manualTagTimeForm').onsubmit = function(e) {
e.preventDefault();
const input = document.getElementById('manualTagTimeInput');
const val = input.value.trim();
if (!val) {
input.classList.add('input-error');
input.focus();
setTimeout(() => input.classList.remove('input-error'), 1000);
alert('Пожалуйста, выберите время!');
return;
}
day.tags[idx][type] = val;
saveAll();
renderApp();
};
}
// === Быстрое добавление нового тега ===
function addTagPlus() {
let dt = todayStr();
let day = findDay(dt);
if (!day) return;
let now = new Date();
let tstr = fromHM(now.getHours(), now.getMinutes());
day.tags.push({ tag: DEFAULT_TAG, start: "", end: "" });
saveAll();
renderApp();
}
function editTags() {
let dt = todayStr(); let day = findDay(dt);
if(!day) {alert("Сначала отметьте время прихода (и желательно ухода)!");return;}
showTagModal(null, dt);
}
function editTag(idx) {
let dt = todayStr(); let day = findDay(dt);
showTagModal(idx, dt);
}
function delTag(idx) {
let dt = todayStr(); let day = findDay(dt);
if(day && day.tags && day.tags[idx] !== undefined) {
if(confirm("Удалить тег "+day.tags[idx].tag+"?")) {
day.tags.splice(idx,1);
saveAll();
renderApp();
}
}
}
// === Tag Modal (edit/new) ===
function showTagModal(tagIdx, forDate) {
let day = findDay(forDate);
if (!day) return;
let tagObj;
if (tagIdx !== null && day.tags[tagIdx]) {
tagObj = { ...day.tags[tagIdx] };
} else {
tagObj = { tag: DEFAULT_TAG, start: day.start || "09:00", end: day.end || "18:00" };
}
let tagOptions = [DEFAULT_TAG, ...tagsLib.filter(t => t !== DEFAULT_TAG)]
.map(t => `<option value="${t}"></option>`).join("");
let html = `
<form id="tagForm">
<label>Тег:<br>
<input type="text" list="tagsSug" value="${tagObj.tag || ''}" id="tg" required autocomplete="off">
<datalist id="tagsSug">${tagOptions}</datalist>
</label><br>
<label>Начало:<br>
<input type="time" id="st" value="${tagObj.start}" required>
</label><br>
<label>Конец:<br>
<input type="time" id="en" value="${tagObj.end}" required>
</label><br>
<div class="row">
<button class="btn fullw" type="submit">Сохранить</button>
<button type="button" class="btn btn-close fullw" onclick="closeModal()">Закрыть</button>
</div>
</form>
`;
showModal(html);
document.getElementById('tagForm').onsubmit = function(e) {
e.preventDefault();
let tg = document.getElementById('tg').value.trim();
let st = document.getElementById('st').value, en = document.getElementById('en').value;
if (!tg) return alert("Введите тег");