-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.js
2781 lines (2235 loc) · 122 KB
/
settings.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
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
/*** /settings.js
* _____ _ _ _ _
* / ____| | | | | (_) (_)
* | (___ ___| |_| |_ _ _ __ __ _ ___ _ ___
* \___ \ / _ \ __| __| | '_ \ / _` / __| | / __|
* ____) | __/ |_| |_| | | | | (_| \__ \_| \__ \
* |_____/ \___|\__|\__|_|_| |_|\__, |___(_) |___/
* __/ | _/ |
* |___/ |__/
*/
/** @file Defines the settings for the extension.
* <style>[pill]{font-weight:bold;white-space:nowrap;border-radius:1rem;padding:.25rem .75rem}[good]{background:#e8f0fe;color:#174ea6}[bad]{background:#fce8e6;color:#9f0e0e;}</style>
* @author Ephellon Grey (GitHub {@link https://github.com/ephellon @ephellon})
* @module
*/
;
/**
* Returns an extension URL for a resource
*
* @param {string} [path = ""] The (absolute) path to the resource
* @return {string<URL>} The modified URL to the resource
*/
function getURL(path = '') {
let url = parseURL(top.location);
return url.origin + path.replace(/^(?!\/)/, '/');
}
// Handle updates here
(async function(version) {
// Handle storage change
if(compareVersions(`${ version } ≥ 5.32.4`)) {
let v5_32_4 = await Storage.get('v5_32_4');
Storage_change: if(parseBool(v5_32_4) == false)
await alert.silent(`There is a new storage system in place, please press OK to proceed. All settings will be transferred.`).then(async() => {
let sync = await Container.storage.sync.get();
for(let key in sync)
Container.storage.local.set({ [key]: sync[key] });
Storage.set({ v5_32_4: true });
});
}
// Convert settings
if(compareVersions(`${ version } = 5.32.5`)) {
let opt = 'auto_chat__vip';
let val = (await Storage.get(opt))?.[opt];
Storage.set({ [opt]: val === true? 'vip': val === false? null: val });
}
// Convert "Lurking Message" to "Lurking Rules"
if(compareVersions(`${ version } ≥ 5.32.10`)) {
let opt = 'auto_chat__lurking_message';
let nxt = 'lurking_rules';
let val = (await Storage.get(nxt))?.[nxt] ?? (await Storage.get(opt))?.[opt];
Storage.set({ [nxt]: val });
}
})(Manifest.version);
const PRIVATE_OBJECT_CONFIGURATION = Object.freeze({
writable: false,
enumerable: false,
configurable: false,
});
let // These are option names. Anything else will be removed
usable_settings = [
/* Automation */
// Away Mode
'away_mode',
'away_mode__hide_chat',
'away_mode__volume_control',
'away_mode__volume',
'away_mode_schedule',
// Auto-claim Bonuses
'auto_claim_bonuses',
// Claim Drops
'claim_drops',
'claim_drops__interval',
// Auto-Follow
'auto_follow_none',
'auto_follow_raids',
'auto_follow_time',
'auto_follow_time_minutes',
'auto_follow_all',
'live_reminders',
'keep_live_reminders',
// Keep Watching
'stay_live',
'stay_live__ignore_channel_reruns',
// Up Next Preference
'next_channel_preference',
// First in Line
'first_in_line_none',
'first_in_line',
'first_in_line_time_minutes',
'first_in_line_plus',
'first_in_line_plus_time_minutes',
'first_in_line_all',
'first_in_line_all_time_minutes',
'up_next__one_instance',
// Greedy Raiding
'greedy_raiding',
'greedy_raiding_leave_before',
// Parse Commands
'parse_commands',
'parse_commands__create_links',
// Prevent Raiding
'prevent_raiding',
// Prevent Hosting
'prevent_hosting',
// Prime Loot
'claim_loot',
// Prime Subscription
'claim_prime',
'claim_prime__max_claims',
// Kill Extensions
'kill_extensions',
// Auto Accept Mature Content
'auto_accept_mature',
// Auto-Focus*
'auto_focus',
'auto_focus_detection_threshold',
'auto_focus_poll_interval',
'auto_focus_poll_image_type',
// Time Zones
'time_zones',
// View Mode
'view_mode',
/* Chat & Messaging */
// Highlight Mentions
'highlight_mentions',
// Extra
'highlight_mentions_extra',
// Show Pop-ups
'highlight_mentions_popup',
// Highlight phrases
'highlight_phrases',
// phrase Rules
'phrase_rules',
// Filter Messages
'filter_messages',
'filter_rules',
'filter_messages__bullets_coin',
'filter_messages__bullets_raid',
'filter_messages__bullets_subs',
'filter_messages__bullets_note',
'filter_messages__bullets_paid',
// BetterTTV Emotes
'bttv_emotes',
'auto_load_bttv_emotes',
'bttv_emotes_maximum',
'bttv_emotes_location',
'bttv_emotes_channel',
'bttv_emotes_extras',
// TODO: Chat Commands
// 'chat_commands',
// 'commands',
// Convert Emotes*
'convert_emotes',
// Link Maker (chat)
'link_maker__chat',
// Auto-Chat (VIP)
'auto_chat__vip',
'auto_chat__mentions',
'auto_chat__lurking_message', // ↓ Replaced: v5.32.10
'lurking_rules', // ↑
'auto_chat__wait_time',
// Native Twitch Replies
'native_twitch_reply',
// Notification Sounds
'mention_audio',
'phrase_audio',
'whisper_audio',
'whisper_audio_sound',
// Prevent spam
'prevent_spam',
'prevent_spam_look_back',
'prevent_spam_minimum_length',
'prevent_spam_ignore_under',
// Accessibility
// Chat
'simplify_chat',
'simplify_chat_monotone_usernames',
'simplify_chat_font',
'simplify_page_font',
// 'simplify_chat_reverse_emotes',
// Display
'simplify_look_auto_marquee',
'simplify_look_normalize_text',
// Recover chat
'recover_chat',
// Recover messages
'recover_messages',
// Soft Unban
'soft_unban',
'soft_unban_keep_bots',
'soft_unban_prevent_clipping',
'soft_unban_fade_old_messages',
/* Currencies */
// Convert Bits
'convert_bits',
// Channel Points Receipt
'channelpoints_receipt_display',
// Rewards Calculator
'rewards_calculator',
/* Customization */
// Away Mode Button Placement
'away_mode_placement',
// Hide Blank Ads
'hide_blank_ads',
// Watch Time Text Placement
'watch_time_placement',
// Points Collected Text Placement
'points_receipt_placement',
// Point Watcher Text placement
'point_watcher_placement',
// Stream Preview
'stream_preview',
'stream_preview_scale',
'stream_preview_sound',
'stream_preview_position',
// Accent Color
'accent_color',
/* Data-Collection Features */
// Fine Details
'fine_details',
// Store integration
'store_integration',
'store_integration__steam',
'store_integration__playstation',
'store_integration__xbox',
'store_integration__nintendo',
// DVR Settings
'video_clips__file_type',
'video_clips__quality',
'video_clips__length',
'video_clips__dvr',
'video_clips__trophy',
'video_clips__trophy_length',
'record_foreign_rewards',
/* Error Recovery */
// Recover Video
'recover_video',
// Recover Stream
'recover_stream',
// Recover Ads
'recover_ads',
// Recover Frames
'recover_frames',
'recover_frames__allow_embed',
// Recover Page
'recover_pages',
// Keep Pop-out
'keep_popout',
/* Developer Options */
// Log messages
'display_in_console',
'display_in_console__log',
'display_in_console__warn',
'display_in_console__error',
'display_in_console__remark',
'display_in_console__notice',
'display_in_console__ignore',
// Display stats
'show_stats',
// Enable emperimental features
'experimental_mode',
// Extra Keyboard Shortcuts
'extra_keyboard_shortcuts',
// Low Data Mode
'low_data_mode',
// User Defined Settings
'user_language_preference',
/* "Hidden" options */
'sync-token',
'clientID',
'oauthToken',
];
/**
* An over-arching date-picker schema.
* @typedef {object} PickedDate
*
* @property {array<string~integer>} days The days (0-indexed) for the schedule: <strong>0</strong> ⇒ <strong>Sunday</strong> ... <strong>6</strong> ⇒ <strong>Saturday</strong>
* @property {string<integer>} duration The duration of the schedule (in hours) for the schedule
* @property {string<boolean>} status The state of the schedule: <strong>true</strong> ⇒ <code>ON</code>; <strong>false</strong> ⇒ <code>OFF</code>
* @property {string<integer>} time The hour for the schedule to begin (24-hour, 0-indexed): <strong>0</strong> to <strong>23</strong> (<em>inclusive</em>)
*/
/**
* Creates a new Twitch-style date input for schedules.
* @author GitHub {@link https://github.com/ephellon @ephellon}
*
* @simply new DatePicker(defaultDate:Date?, defaultStatus:boolean?, defaultTime:number?<hour{0...23}>, defaultDuration:number?<milliseconds>) → Promise<array[object]>
*/
class DatePicker {
static values = [];
static weekdays = 'Sun Mon Tue Wed Thu Fri Sat'.split(' ');
static months = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ');
/** @constructor
*
* @param {Date} [defaultDate] The date to highlight and use
* @param {boolean} [defaultStatus = false] The default state for the scheduler: <strong>true</strong> ⇒ <code>ON</code>; <strong>false</strong> ⇒ <code>OFF</code>
* @param {number<integer>} [defaultTime = null] The hour to use (24-hour, 0-indexed): <strong>0</strong> to <strong>23</strong> (<em>inclusive</em>)
* @param {number<integer>} [defaultDuration = 1] The default duration (in hours): <strong>1</strong> to <strong>168</strong> (<em>inclusive</em>)
* @return {PickedDate} A promised array containing the user's preferred schedule options
*/
constructor(defaultDate, defaultStatus = false, defaultTime = null, defaultDuration = 1) {
let date = +new Date(defaultDate ?? +new Date),
h = 60 * 60 * 1000,
d = 24 * h,
f = furnish;
let locale = SETTINGS?.user_language_preference ?? 'en';
let preExisting = defined(defaultDate) && (defined(defaultTime) || defaultDuration > 1);
let now = new Date(date.floorToNearest(h)),
timezone = (now + '').replace(/[^]+\(([^]+?)\)[^]*/, '$1').replace(/(?<=^|\s)(.)[^\s]*/g, '$1').replace(/\s+/g, ''),
timeOptions = new Array(24).fill(0).map((v, i, a) => +now + (i * h)).map(d => new Date(d).getHours()),
[timeDefault] = [defaultTime, ...timeOptions].filter(defined),
[AM, PM] = [11, 23].map(h => new Date(`1970-01-01T${ h }:00:00Z`).toLocaleTimeString(locale).toLocaleUpperCase().replace(/(?:.+?)(\D*)$/, '$1').trim()),
startingHour = now.getHours(),
meridiem = (startingHour < 12? AM: PM);
let durationOptions = new Array(23).fill(0).map((v, i, a) => i + 1);
durationOptions = [...durationOptions, ...new Array(7).fill(0).map((v, i, a) => 24 * (i + 1))];
let dayOptions = new Array(7).fill(0).map((v, i, a) => i),
dayDefault = now.getDay();
let statusOptions = new Array(2).fill(0).map((v, i, a) => !!i);
let to12H = (time, symbols = [AM, PM]) => [(time == 0? 12: time > 12? time - 12: time), symbols[+(time > 11)]].join(' ');
let daySelect = f(`select.edit`, { type: 'days', value: dayDefault, multiple: true, selected: 1, onchange: ({ currentTarget }) => currentTarget.setAttribute('selected', currentTarget.selectedOptions.length) },
...dayOptions.map(value => f(`option${ (value == dayDefault? '[selected]': '') }`, { value, 'tr-id': 'day-of-week' }, DatePicker.weekdays[value]))
),
statusSelect = f(`select.edit`, { type: 'status', value: defaultStatus, 'tr-id': 'toggle' },
...statusOptions.map(value => f(`option${ (value == defaultStatus? '[selected]': '') }`, { value }, 'off on'.split(' ')[+value]))
),
timeSelect = f(`select.edit`, { type: 'time', value: timeDefault },
...timeOptions.map(value =>
f(`option${ (value == timeDefault? '[selected]': '') }`, { value },
(
AM.length && PM.length?
// Uses meridiem indicators
to12H(value, (value % 12? [AM, PM]: [' \u{1f31a}', ' \u{1f31e}'])):
// Uses 24H format only
value + (value % 12? '': [' \u{1f31a}', ' \u{1f31e}'][+(value > 11)])
)
)
)
),
durationSelect = f(`select.edit`, { type: 'duration', value: defaultDuration },
...durationOptions.map(value => {
let timeString = toTimeString(value * h),
timeType = timeString.replace(/[^a-z]|s$/ig, '').replace(/ie$/i, 'y');
return f(`option${ (value == defaultDuration? '[selected]': '') }`, { value, 'tr-id': timeType }, timeString);
})
);
daySelect.value = dayDefault;
let container =
f(`.tt-modal-wrapper.context-root`).with(
f(`.tt-modal-body`).with(
f(`.tt-modal-container`).with(
// Header
f('.tt-modal-header').with(
f('h3', { innerHTML: Glyphs.modify('calendar', { height: 30, width: 30 }).toString() }, ' Create a new schedule')
),
// Body
f('.tt-modal-content.details.context-body').with(
f('div', { style: 'width:-webkit-fill-available; width:-moz-available' },
// Frequency
f('div', { 'pad-bottom': true },
f('.title').with('Frequency'),
f('.summary').with(
daySelect,
f('.subtitle', {
innerHTML: `Use <code>${ GetMacro('Ctrl') }</code> and/or <code>${ GetMacro('Shift') }</code> to select multiple days.`
})
)
),
// Status & Functionality
f('div', { 'pad-bottom': true },
f('.title').with('Functionality'),
f('.summary').with(
statusSelect,
'at',
timeSelect,
'for',
durationSelect,
f('.subtitle', {
innerHTML: `Times will be saved in your current timezone <span>(${ timezone })</span>.`
})
)
),
// Submit / Cancel
f('div', { 'pad-bottom': true },
// Add more
f('div', { style: 'width:fit-content' },
f('.checkbox.left', { onmouseup: event => $('input', event.currentTarget).click() },
f('input.add-more', { type: 'checkbox', name: 'add-more-times' }),
f('label', { for: 'add-more-times' }, 'Add another schedule')
)
),
// Continue
f('button', {
'tr-id': 'ok',
onmousedown: event => {
let { currentTarget } = event;
let values = $.all('select[type]', currentTarget.closest('.context-body')).map(select => [select.getAttribute('type'), (select.multiple? [...select.selectedOptions].map(option => option.value): select.value)]);
let object = {};
for(let [key, value] of values)
object[key] = value;
DatePicker.values.push(object);
},
onmouseup: event => {
let { currentTarget } = event,
addNew = $('.add-more', currentTarget.closest(':not(button)')).checked;
if(addNew)
new DatePicker();
else
$('#date-picker-value').value = JSON.stringify(DatePicker.values.filter(defined));
wait(100).then(() => currentTarget.closest('.context-root')?.remove());
},
}, ['Continue', 'Save'][+preExisting]),
// Cancel
f(`button.${ ['edit', 'remove'][+preExisting] }`, {
'tr-id': ['nk', 'rm'][+preExisting],
onmousedown: event => DatePicker.values.push(null),
onmouseup: event => {
let { currentTarget } = event;
$('#date-picker-value').value = JSON.stringify(DatePicker.values.filter(defined));
wait(100).then(() => currentTarget.closest('.context-root')?.remove());
},
}, ['Cancel', 'Delete'][+preExisting]),
// Hidden
f('input#date-picker-value', { type: 'text', style: 'display:none!important' })
)
)
)
)
)
);
// Translate(locale, container);
document.body.append(container);
return when.defined(() => JSON.parse($('#date-picker-value')?.value || 'null')).then(values => { DatePicker.values = []; return values });
}
}
/**
* An over-arching command-maker schema.
* @typedef {object} Command
*
* @property {string<integer>} authority The authority level that user's need to use the command
* @property {string<array>} command The command and aliases (comma-separated)
* @property {string<integer~seconds>} cooldown The cooldown time (in seconds)
* @property {string} reply The reply to send when the command is invoked
* @property {string} type The type of command: <strong>reply</strong>, <strong>announcement</strong>, <strong>recurring</strong>
*/
/** @FIXME
* Creates a new Twitch-style command input.
* @author GitHub {@link https://github.com/ephellon @ephellon}
*
* @simply new CommandMaker(defaultName:string, defaultStatus:boolean?, defaultLevel:number?<Command-Authority>, defaultCooldown:number?<seconds>, defaultType:string?) → Promise<array[object]>
*/
class CommandMaker {
static values = [];
/**
* An over-arching authority-level schema. Used by StreamElements and NightBot.
* @typedef {enum} AuthorityLevels
*
* @property {number} everyone <strong>100</strong> → <em>Anyone</em>, <em>Everyone</em>
* @property {number} follower <strong>250</strong> → <em>Follower</em>, <em>Regular</em>
* @property {number} subscriber <strong>300</strong> → <em>Subscriber</em>
* @property {number} vip <strong>400</strong> → <em>VIP</em>
* @property {number} moderator <strong>500</strong> → <em>Moderator</em>
* @property {number} admin <strong>1000</strong> → <em>Administrator</em>, <em>Super Moderator</em>
* @property {number} owner <strong>1500</strong> → <em>Broadcaster</em>, <em>Owner</em>
*/
static levels = [['Everyone',100],['Follower',250],['Subscriber',300],['VIP',400],['Moderator',500],['Administrator',1000],['Owner',1500]].map(([who, authority]) => [new String(who), authority]).map(([who, authority]) =>
CommandMaker[who.toLowerCase()] = Object.defineProperties(who, {
find: {
value(value) {
let levels = {
owner: 1500,
broadcaster: 1500,
administrator: 1000,
moderator: 500,
vip: 400,
subscriber: 300,
regular: 250,
follower: 250,
everyone: 100,
anyone: 100,
};
for(let level in levels)
if(level.startsWith(value?.toLowerCase?.()))
return levels[level];
return value;
}
},
level: { value: authority },
not: { value(level) { return this.level < this.find(level) } },
is: { value(level) { return this.level >= this.find(level) } },
})
);
static badges = {
everyone: 'https://static-cdn.jtvnw.net/user-default-pictures-uv/215b7342-def9-11e9-9a66-784f43822e80-profile_image-70x70.png',
follower: 'https://static-cdn.jtvnw.net/badges/v1/d12a2e27-16f6-41d0-ab77-b780518f00a3/3',
subscriber: 'https://static-cdn.jtvnw.net/badges/v1/5d9f2208-5dd8-11e7-8513-2ff4adfae661/3',
vip: 'https://static-cdn.jtvnw.net/badges/v1/b817aba4-fad8-49e2-b88a-7cc744dfa6ec/3',
moderator: 'https://static-cdn.jtvnw.net/badges/v1/3267646d-33f0-4b17-b3df-f923a41db1d0/3',
admin: 'https://static-cdn.jtvnw.net/badges/v1/d97c37bd-a6f5-4c38-8f57-4e4bef88af34/3',
owner: 'https://static-cdn.jtvnw.net/badges/v1/5527c58c-fb7d-422d-b71b-f309dcb85cc1/3',
};
/** @constructor
*
* @param {string} [defaultName] The default command name
* @param {boolean} [defaultStatus = true] The default command-enabled status
* @param {number<integer~AuthorityLevels>} [defaultLevel = CommandMaker.everyone] The default authority-level for command usage
* @param {number<integer~seconds>} [defaultCooldown = { user: 10, global: 3 }] The cooldown time (in seconds)
* @param {string} [defaultType = "reply"] The command type: <strong>reply</strong>, <strong>announcement</strong>, <strong>recurring</strong>
* @return {Promise<array~Command>} A promised array containing commands
*/
constructor(defaultName, defaultStatus = true, defaultLevel = CommandMaker.everyone, defaultCooldown = { user: 10, global: 3 }, defaultType = 'reply') {
let f = furnish;
let locale = SETTINGS?.user_language_preference ?? 'en';
let preExisting = defaultName?.length > 0;
let who = f('select.edit#authority', {
value: defaultLevel,
style: `background-image:url("${ CommandMaker.badges.everyone }")`,
onchange({ target }) {
let [selected] = target.selectedOptions,
who = selected.getAttribute('name');
target.modStyle(`background-image:url("${ CommandMaker.badges[who] }")`);
},
}).with(
...CommandMaker.levels.map(who =>
f(`option[value=${ who.level }][name=${ who.toLowerCase() }]`).with(
who.replace(/[^aeiou]$/i, '$&s')
.replace(/^(admin|staff)s$/i, 'Twitch Staff & $&')
.replace(/^(owner)s$/i, 'Only you ($1)')
)
)
),
type = f('select.edit#type', {
value: defaultType,
onchange({ target }) {
let [selected] = target.selectedOptions,
type = selected.value;
},
}).with(
f('option[value=reply]').with('Individual reply'), // An individual response
f('option[value=announcement]').with('General reply (announcement)'), // A general response
f('option[value=recurring]').with('A recurring announcement'), // A recurring-notice
),
each = f('span[fix-unit=sec]').with(f(`input#cooldown.edit`, { type: 'number', min: 0, max: 2_592_000, value: 10 }));
let conversionTable = [3600, 28800, 86400, 6048001, 2592000].map(s => `${ toTimeString(s * 1000) } = ${ comify(s) }`).join(' • ');
let container =
f(`.tt-modal-wrapper.context-root`).with(
f(`.tt-modal-body`).with(
f(`.tt-modal-container`).with(
// Header
f('.tt-modal-header').with(
f('h3', { innerHTML: Glyphs.modify('chat', { height: 30, width: 30 }).toString() }, ' Create a new command')
),
// Body
f('.tt-modal-content.details.context-body').with(
f('div', { style: 'width:-webkit-fill-available; width:-moz-available' },
// Frequency
f('div', { 'pad-bottom': true },
f('.title').with('Metadata'),
f('.summary').with(
f.h4('Name'),
f('span[pre-unit=!]').with(f(`input#command`, { placeholder: 'Command name(s)', pattern: '.{1,100}' })),
f('.subtitle', {
style: 'margin-bottom: .5rem',
innerHTML: `This is what users type into chat to activate the command. Use a comma (<code>,</code>) to separate names.`
}),
f.h4('Type'),
type,
f('.subtitle', {
style: 'margin-bottom: .5rem',
innerHTML: `This determines how the command is handled.`
}),
f.h4('Response'),
f(`input#reply`, { placeholder: 'Reply...', type: 'text' }),
f('.subtitle', {
style: 'margin-bottom: .5rem',
innerHTML: `This is what will be replied to chat.`
})
)
),
// Functionality
f('div', { 'pad-bottom': true },
f('.title').with('User(s)'),
f('.summary').with(
f.div(who, 'can use the command.')
)
),
f('div', { 'pad-bottom': true },
f('.title').with('Cooldown'),
f('.summary').with(
f.div('The ', f.ins('per person'), ' cooldown is ', each),
f.hr(),
f('.subtitle').with(conversionTable)
)
),
// Submit / Cancel
f('div', { 'pad-bottom': true },
// Notice...
f('.subtitle', {
innerHTML: `Commands will only be available while you are <b alert-text top-tooltip='Have chat open'>online</b>.`
}),
// Add more
f('div', { style: 'width:fit-content' },
f('.checkbox.left', { onmouseup: event => $('input', event.currentTarget).click() },
f('input.add-more', { type: 'checkbox', name: 'add-more-commands' }),
f('label', { for: 'add-more-commands' }, 'Add another command')
)
),
// Continue
f('button', {
'tr-id': 'ok',
onmousedown: event => {
let { currentTarget } = event;
let values = $.all('[id]', currentTarget.closest('.context-body')).map(element => [element.getAttribute('id'), (element.multiple? [...element.selectedOptions].map(option => option.value): element.value)]);
let object = {};
for(let [key, value] of values)
object[key] = value;
CommandMaker.values.push(object);
},
onmouseup: event => {
let { currentTarget } = event,
addNew = $('.add-more', currentTarget.closest(':not(button)')).checked;
// TODO - handle multiple names (,) delimeted
if(addNew)
new CommandMaker();
else
$('.command-maker-value').value = JSON.stringify(CommandMaker.values.filter(defined));
wait(100).then(() => currentTarget.closest('.context-root')?.remove());
},
}, ['Continue', 'Save'][+preExisting]),
// Cancel
f(`button.${ ['edit', 'remove'][+preExisting] }`, {
'tr-id': ['nk', 'rm'][+preExisting],
onmousedown: event => CommandMaker.values.push(null),
onmouseup: event => {
let { currentTarget } = event;
$('.command-maker-value').value = JSON.stringify(CommandMaker.values.filter(defined));
wait(100).then(() => currentTarget.closest('.context-root')?.remove());
},
}, ['Cancel', 'Delete'][+preExisting]),
// Hidden
f('input.command-maker-value', { type: 'text', style: 'display:none!important' })
)
)
)
)
)
);
// Translate(locale, container);
document.body.append(container);
return when.defined(() => JSON.parse($('.command-maker-value')?.value || 'null')).then(values => { CommandMaker.values = []; return values });
}
}
let Glyphs = {
// Twitch
...top.Glyphs,
// Accessibility
accessible: '<svg fill="var(--white)" width="100%" height="100%" version="1.1" viewBox="0 0 1224 792" x="0px" y="0px" enable-background="new 0 0 1224 792" xml:space="preserve"><g><path d="M833.556,367.574c-7.753-7.955-18.586-12.155-29.656-11.549l-133.981,7.458l73.733-83.975 c10.504-11.962,13.505-27.908,9.444-42.157c-2.143-9.764-8.056-18.648-17.14-24.324c-0.279-0.199-176.247-102.423-176.247-102.423 c-14.369-8.347-32.475-6.508-44.875,4.552l-85.958,76.676c-15.837,14.126-17.224,38.416-3.097,54.254 c14.128,15.836,38.419,17.227,54.255,3.096l65.168-58.131l53.874,31.285l-95.096,108.305 c-39.433,6.431-74.913,24.602-102.765,50.801l49.66,49.66c22.449-20.412,52.256-32.871,84.918-32.871 c69.667,0,126.346,56.68,126.346,126.348c0,32.662-12.459,62.467-32.869,84.916l49.657,49.66 c33.08-35.166,53.382-82.484,53.382-134.576c0-31.035-7.205-60.384-20.016-86.482l51.861-2.889l-12.616,154.75 c-1.725,21.152,14.027,39.695,35.18,41.422c1.059,0.086,2.116,0.127,3.163,0.127c19.806,0,36.621-15.219,38.257-35.306 l16.193-198.685C845.235,386.445,841.305,375.527,833.556,367.574z"/><path d="M762.384,202.965c35.523,0,64.317-28.797,64.317-64.322c0-35.523-28.794-64.323-64.317-64.323 c-35.527,0-64.323,28.8-64.323,64.323C698.061,174.168,726.856,202.965,762.384,202.965z"/><path d="M535.794,650.926c-69.668,0-126.348-56.68-126.348-126.348c0-26.256,8.056-50.66,21.817-70.887l-50.196-50.195 c-26.155,33.377-41.791,75.393-41.791,121.082c0,108.535,87.983,196.517,196.518,196.517c45.691,0,87.703-15.636,121.079-41.792 l-50.195-50.193C586.452,642.867,562.048,650.926,535.794,650.926z"/></g></svg>',
// Creative Commons
cc: '<svg fill="var(--grey)" width="100%" height="100%" version="1.1" viewBox="0 0 20 20" x="0px" y="0px"><path d="M10.089 19.0119C15.0659 19.0119 19.1004 14.9773 19.1004 10.0005C19.1004 5.02361 15.0659 0.989075 10.089 0.989075C5.11217 0.989075 1.07764 5.02361 1.07764 10.0005C1.07764 14.9773 5.11217 19.0119 10.089 19.0119Z" fill="white"></path><path d="M9.98172 0C12.779 0 15.1606 0.976578 17.1246 2.9288C18.0647 3.86912 18.7794 4.94383 19.2675 6.15197C19.7553 7.36043 20 8.64295 20 10.0002C20 11.3692 19.7584 12.6521 19.2769 13.848C18.7947 15.0443 18.0831 16.1012 17.1431 17.0178C16.1671 17.9818 15.0599 18.7203 13.8215 19.2322C12.5836 19.7441 11.3036 20 9.98234 20C8.66107 20 7.39605 19.7475 6.1876 19.2409C4.97945 18.7353 3.896 18.0031 2.93755 17.045C1.97909 16.0868 1.25002 15.0062 0.750012 13.8037C0.250004 12.6011 0 11.3336 0 10.0002C0 8.67857 0.252816 7.40793 0.758762 6.1876C1.26471 4.96727 2.00003 3.87506 2.96411 2.91067C4.86883 0.97064 7.20793 0 9.98172 0ZM10.018 1.80378C7.73231 1.80378 5.80947 2.6016 4.24975 4.19663C3.4638 4.99445 2.85973 5.89009 2.43723 6.88417C2.01409 7.87825 1.80315 8.91701 1.80315 10.0005C1.80315 11.072 2.01409 12.1049 2.43723 13.0983C2.86004 14.093 3.4638 14.9799 4.24975 15.7596C5.03539 16.5396 5.92197 17.1343 6.91073 17.5456C7.89856 17.9562 8.93451 18.1615 10.018 18.1615C11.0892 18.1615 12.1274 17.9537 13.1346 17.5368C14.1405 17.1196 15.0474 16.519 15.8574 15.7334C17.4168 14.2096 18.1962 12.2989 18.1962 10.0008C18.1962 8.89358 17.9937 7.84606 17.589 6.85792C17.185 5.86978 16.5953 4.98914 15.8221 4.21475C14.214 2.60754 12.2799 1.80378 10.018 1.80378ZM9.89265 8.33982L8.55295 9.03639C8.40982 8.7392 8.2345 8.53045 8.02638 8.41138C7.81793 8.29263 7.62449 8.23294 7.44574 8.23294C6.55323 8.23294 6.10635 8.82201 6.10635 10.0008C6.10635 10.5364 6.21947 10.9645 6.44541 11.2861C6.67167 11.6077 7.00511 11.7686 7.44574 11.7686C8.02919 11.7686 8.43982 11.4827 8.67826 10.9114L9.91016 11.5364C9.64828 12.0249 9.28515 12.4086 8.82076 12.6883C8.35701 12.9683 7.84481 13.108 7.28511 13.108C6.39229 13.108 5.67165 12.8346 5.12414 12.2864C4.57663 11.7389 4.30288 10.977 4.30288 10.0011C4.30288 9.04858 4.57976 8.29294 5.13321 7.73325C5.68665 7.17386 6.38604 6.89386 7.23168 6.89386C8.47013 6.89323 9.35671 7.37543 9.89265 8.33982ZM15.6606 8.33982L14.339 9.03639C14.1962 8.7392 14.0202 8.53045 13.8121 8.41138C13.6033 8.29263 13.4036 8.23294 13.214 8.23294C12.3211 8.23294 11.8742 8.82201 11.8742 10.0008C11.8742 10.5364 11.9877 10.9645 12.2136 11.2861C12.4396 11.6077 12.7727 11.7686 13.214 11.7686C13.7968 11.7686 14.2077 11.4827 14.4455 10.9114L15.6956 11.5364C15.4221 12.0249 15.0527 12.4086 14.589 12.6883C14.1246 12.9683 13.6187 13.108 13.0711 13.108C12.1661 13.108 11.4433 12.8346 10.902 12.2864C10.3595 11.7389 10.0889 10.977 10.0889 10.0011C10.0889 9.04858 10.3655 8.29294 10.9195 7.73325C11.4727 7.17386 12.1721 6.89386 13.0174 6.89386C14.2555 6.89323 15.1371 7.37543 15.6606 8.33982Z"></path></svg>',
// GitHub
github: '<svg fill="currentColor" width="32" height="32" version="1.1" viewBox="0 0 16 16" x="0px" y="0px"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path></svg>',
// Google Chrome
chrome: '<svg width="100%" height="100%" version="1.1" viewbox="0 0 190 190" x="0px" y="0px"><circle fill="#FFF" cx="85.314" cy="85.713" r="83.805"/><path fill-opacity=".1" d="M138.644 100.95c0-29.454-23.877-53.331-53.33-53.331-29.454 0-53.331 23.877-53.331 53.331H47.22c0-21.039 17.055-38.094 38.093-38.094s38.093 17.055 38.093 38.094"/><circle fill-opacity=".1" cx="89.123" cy="96.379" r="28.951"/><linearGradient id="a" gradientUnits="userSpaceOnUse" x1="-149.309" y1="-72.211" x2="-149.309" y2="-71.45" gradientTransform="matrix(82 0 0 82 12328.615 5975.868)"><stop offset="0" stop-color="#81b4e0"/><stop offset="1" stop-color="#0c5a94"/></linearGradient><circle fill="url(#a)" cx="85.314" cy="85.712" r="31.236"/><linearGradient id="b" gradientUnits="userSpaceOnUse" x1="-114.66" y1="591.553" x2="-114.66" y2="660.884" gradientTransform="translate(202.64 -591.17)"><stop offset="0" stop-color="#f06b59"/><stop offset="1" stop-color="#df2227"/></linearGradient><path fill="url(#b)" d="M161.5 47.619C140.525 5.419 89.312-11.788 47.111 9.186a85.315 85.315 0 0 0-32.65 28.529l34.284 59.426c-6.313-20.068 4.837-41.456 24.905-47.77a38.128 38.128 0 0 1 10.902-1.752"/><linearGradient id="c" gradientUnits="userSpaceOnUse" x1="-181.879" y1="737.534" x2="-146.834" y2="679.634" gradientTransform="translate(202.64 -591.17)"><stop offset="0" stop-color="#388b41"/><stop offset="1" stop-color="#4cb749"/></linearGradient><path fill="url(#c)" d="M14.461 37.716c-26.24 39.145-15.78 92.148 23.363 118.39a85.33 85.33 0 0 0 40.633 14.175l35.809-60.948c-13.39 16.229-37.397 18.529-53.625 5.141a38.096 38.096 0 0 1-11.896-17.33"/><linearGradient id="d" gradientUnits="userSpaceOnUse" x1="-64.479" y1="743.693" x2="-101.81" y2="653.794" gradientTransform="translate(202.64 -591.17)"><stop offset="0" stop-color="#e4b022"/><stop offset=".3" stop-color="#fcd209"/></linearGradient><path fill="url(#d)" d="M78.457 170.28c46.991 3.552 87.965-31.662 91.519-78.653a85.312 85.312 0 0 0-8.477-44.007H84.552c21.036.097 38.014 17.23 37.917 38.269a38.099 38.099 0 0 1-8.205 23.443"/><linearGradient id="e" gradientUnits="userSpaceOnUse" x1="-170.276" y1="686.026" x2="-170.276" y2="625.078" gradientTransform="translate(202.64 -591.17)"><stop offset="0" stop-opacity=".15"/><stop offset=".3" stop-opacity=".06"/><stop offset="1" stop-opacity=".03"/></linearGradient><path fill="url(#e)" d="M14.461 37.716l34.284 59.426a38.093 38.093 0 0 1 1.523-25.904L15.984 35.43"/><linearGradient id="f" gradientUnits="userSpaceOnUse" x1="-86.149" y1="705.707" x2="-128.05" y2="748.37" gradientTransform="translate(202.64 -591.17)"><stop offset="0" stop-opacity=".15"/><stop offset=".3" stop-opacity=".06"/><stop offset="1" stop-opacity=".03"/></linearGradient><path fill="url(#f)" d="M78.457 170.28l35.809-60.948a38.105 38.105 0 0 1-22.095 12.951L76.933 170.28"/><linearGradient id="chrome-logo-gradient" gradientUnits="userSpaceOnUse" x1="-86.757" y1="717.981" x2="-80.662" y2="657.797" gradientTransform="translate(202.64 -591.17)"><stop offset="0" stop-opacity=".15"/><stop offset=".3" stop-opacity=".06"/><stop offset="1" stop-opacity=".03"/></linearGradient><path fill="url(#chrome-logo-gradient)" d="M161.5 47.619H84.552a38.094 38.094 0 0 1 29.712 14.476l48.759-12.189"/></svg>',
};
let SETTINGS,
TRANSLATED = false,
INITIAL_LOAD = true;
let SUPPORTED_LANGUAGES = ["bg","cs","da","de","el","es","fi","fr","hu","it","ja","ko","nl","no","pl","ro","ru","sk","sv","th","tr","vi"];
function RedoRuleElements(rules, ruleType, delimeter, scopes) {
if(nullish(rules))
return;
delimeter ??= ',';
scopes ??= 'all';
rules = rules.split(delimeter).sort();
if(scopes.equals('all'))
scopes = 'channel user badge emote text regexp';
scopes = scopes.split(' ');
for(let rule of rules) {
if(!rule?.length)
continue;
let E = document.createElement('button'),
R = document.createElement('button');
let ruleID = UUID.from(rule).value;
let itemType;
if(scopes.contains('channel') && /^\/[\w+\-]+/.test(rule)) {
itemType = 'channel';
} else if(scopes.contains('user') && /^@[\w+\-]+/.test(rule)) {
itemType = 'user';
} else if(scopes.contains('badge') && /^<[^>]+>/.test(rule)) {
itemType = 'badge';
} else if(scopes.contains('emote') && /^:[\w\-]+:$/.test(rule)) {
itemType = 'emote';
} else if(scopes.contains('text') && /^[\w]+$/.test(rule)) {
itemType = 'text';
} else if(scopes.contains('regexp')) {
itemType ??= 'regexp';
}
itemType ??= 'text';
if($.defined(`#${ ruleType }_rules [${ ruleType }-type="${ itemType }"i] [${ ruleType }-id="${ ruleID }"i]`))
continue;
// "Edit" button
E.innerHTML = `<code fill>${ encodeHTML(rule) }</code>`;
E.classList.add('edit');
E.setAttribute(`${ ruleType }-id`, ruleID);
E.onclick = event => {
let { currentTarget } = event,
{ textContent } = currentTarget,
input = $(`#${ ruleType }_rules-input`);
input.value = [...input.value.split(delimeter), textContent].filter(v => v?.trim()?.length).join(delimeter);
currentTarget.remove();
};
E.setAttribute('up-tooltip', `Edit rule`);
E.setAttribute('tr-skip', true);
E.append(R);
// "Remove" button
R.id = ruleID;
R.innerHTML = Glyphs.modify('trash', { fill: 'white', height: '20px', width: '20px' });
R.classList.add('remove');
R.onclick = event => {
let { currentTarget } = event,
{ id } = currentTarget;
$(`[${ ruleType }-id="${ id }"]`)?.remove();
event.stopPropagation();
};
R.setAttribute('up-tooltip', `Remove rule`);
$(`#${ ruleType }_rules [${ ruleType }-type="${ itemType }"i]`).setAttribute('not-empty', true);
$(`#${ ruleType }_rules [${ ruleType }-type="${ itemType }"i]`)?.append(E);
$(`#${ ruleType }_rules-input`).value = "";
}
}
function RedoTimeElements(schedules, scheduleType) {
if(!schedules?.length)
return;
schedules = JSON.parse(schedules);
for(let schedule of schedules) {
let { days, time, duration, status } = schedule;
// Add buttons per day
if(defined(days))
for(let day of days)
CreateTimeElement(({ day, time, duration, status }), scheduleType);
else
CreateTimeElement(schedule, scheduleType);
}
}
function CreateTimeElement(self, scheduleType) {
let { day, time, duration, status } = self,
scheduleID = UUID.from(self).value;
if($.defined(`#${ scheduleType }_schedule [day="${ day }"][time="${ time }"]`))
return;
let E = document.createElement('button'),
R = document.createElement('button');
// "Edit" button
E.innerHTML = `<code fill>${ encodeHTML(`${ ['\u{1f534}','\u{1f7e2}'][+parseBool(status)] } ${ time }:00 + ${ toTimeString(duration * 3_600_000, '?hours_h') }`) }</code>`;
E.classList.add('edit');
E.setAttribute(`${ scheduleType }-id`, scheduleID);
for(let key in self)
E.setAttribute(key, self[key]);
E.onclick = event => {
let { currentTarget } = event;
let day = parseInt(currentTarget.getAttribute('day')),
time = parseInt(currentTarget.getAttribute('time')),
duration = parseInt(currentTarget.getAttribute('duration')),
status = parseBool(currentTarget.getAttribute('status'));
let date = new Date,
dayOffset = (date.getDate() - (date.getDay() - day));
dayOffset = (dayOffset > 0)?
dayOffset:
dayOffset + 7;
let offset = new Date([DatePicker.months[date.getMonth()], dayOffset, date.getFullYear(), time].join(' '));
new DatePicker(offset, status, time, duration).then(schedules => RedoTimeElements(JSON.stringify(schedules), scheduleType));
currentTarget.remove();
};
E.setAttribute('up-tooltip', `Edit schedule`);
E.setAttribute('tr-skip', true);
E.append(R);
// "Remove" button
R.id = scheduleID;
R.innerHTML = Glyphs.modify('trash', { fill: 'white', height: '20px', width: '20px' });
R.classList.add('remove');
R.onclick = event => {
let { currentTarget } = event,
{ id } = currentTarget;
$(`[${ scheduleType }-id="${ id }"]`)?.remove();
event.stopPropagation();
};
R.setAttribute('up-tooltip', `Remove schedule`);
// Add to parent container
$(`#${ scheduleType }_schedule [day-of-week="${ day }"i]`)?.setAttribute('not-empty', true);
$(`#${ scheduleType }_schedule [day-of-week="${ day }"i]`)?.append(E);
}
async function SaveSettings() {
let { extractValue } = SaveSettings;
let elements = $.all(usable_settings.map(name => '#' + name + ':not(:invalid)').join(', ')),
using = elements.map(element => element.id);
// Edit settings before exporting them (if needed)
for(let id of using)
switch(id) {
case 'filter_rules': {
let rules = [],
input = extractValue($('#filter_rules-input'));
if(parseBool(input))
rules = input.split(',');
for(let rule of $.all('#filter_rules code'))
rules.push(rule.textContent);
rules = rules.isolate().filter(rule => rule.length);
SETTINGS.filter_rules = rules.sort().join(',');
RedoRuleElements(SETTINGS.filter_rules, 'filter');
} break;
case 'phrase_rules': {
let rules = [],
input = extractValue($('#phrase_rules-input'));
if(parseBool(input))
rules = input.split(',');
for(let rule of $.all('#phrase_rules code'))
rules.push(rule.textContent);
rules = rules.isolate().filter(rule => rule.length);
SETTINGS.phrase_rules = rules.sort().join(',');
RedoRuleElements(SETTINGS.phrase_rules, 'phrase');
} break;
case 'lurking_rules': {
let rules = [],
input = extractValue($('#lurking_rules-input'));
if(parseBool(input))
rules = input.split(';');
for(let rule of $.all('#lurking_rules code'))
rules.push(rule.textContent);
rules = rules.isolate().filter(rule => rule.length);
SETTINGS.lurking_rules = rules.sort().join(';');
RedoRuleElements(SETTINGS.lurking_rules, 'lurking', ';', 'channel badge text');
} break;
case 'away_mode_schedule': {
let times = [];
for(let button of $.all('#away_mode_schedule button[duration]')) {
let day = parseInt(button.getAttribute('day')),
time = parseInt(button.getAttribute('time')),
duration = parseInt(button.getAttribute('duration')),
status = parseBool(button.getAttribute('status'));
times.push({ day, time, duration, status });
}