-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathffzenhancing.js
More file actions
1736 lines (1568 loc) · 81.4 KB
/
ffzenhancing.js
File metadata and controls
1736 lines (1568 loc) · 81.4 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
'use strict';
(() => {
let version = '6.121';
let notify_icon = __ffzenhancing_base_url + 'notify.png';
let notify_icon_original = document.querySelector('link[rel="icon"]') && document.querySelector('link[rel="icon"]').href;
let ffz_is_player = window.location.hostname.startsWith('player');
let ffzenhancing_focus_input_area_after_emote_select;
let ffzenhancing_keep_delay_low;
let ffzenhancing_keep_delay_low_delay;
let ffzenhancing_keep_delay_low_delay_low_latency;
let ffzenhancing_keep_delay_low_rate;
let ffzenhancing_keep_delay_low_latency_was_changed;
let ffzenhancing_fix_tooltips;
let ffzenhancing_doubleclick_username_paste_in_chat;
let ffzenhancing_move_users_in_chat_to_bottom;
let ffzenhancing_hide_rooms_header;
let ffzenhancing_hide_chat_collapse_button;
let ffzenhancing_auto_reload_on_error_2000;
let ffzenhancing_auto_reload_on_hanged_video;
let ffzenhancing_auto_reload_on_hanged_video_after;
let ffzenhancing_auto_reload_on_hanged_video_currentTime;
let ffzenhancing_auto_check_player_quality;
let ffzenhancing_auto_check_player_compressor;
let ffzenhancing_pin_mentions;
let ffzenhancing_reset_after_delay;
let ffzenhancing_reset_after_delay_delay;
let ffzenhancing_animate_static_gif_emotes_on_mouse_hover;
let ffzenhancing_auto_click_claim_bonus_points;
let ffzenhancing_fix_emote_select;
let ffzenhancing_highlight_user_messages;
let ffzenhancing_fix_addon_load;
let ffzenhancing_visibility_hook_time;
let ffzenhancing_fix_video_freeze_on_tab_change;
let ffzenhancing_always_show_open_thread_button;
let ffzenhancing_always_show_open_thread_button_handler_hidden;
let ffzenhancing_always_show_open_thread_button_handler_click;
let ffzenhancing_pause_vod_on_click;
let timeoutPeriodicCheckVideoInfo = 0;
let handlers_already_attached = {};
let timers = {};
let timeoutShowCard;
let timeoutCheckCard;
let ignore_next_click_event = false;
let current_player_volume;
let current_player_muted;
let current_player_quality;
let added_styles = {};
let visibility_hook_enabled = false;
let orig_visibilityStateProc;
let visibility_hook_timeout;
let resetPlayerTimeout = false;
let compressPlayerWanted;
let currentPlayerUserPaused = false;
let prev_player_onStateChanged;
let added_message_highlights = {};
let playbackRate_set_by_us = false;
let orig_playbackRate_set;
let recently_clicked_playerQualityChange = false;
let buffer_times = [];
function isPlayerOrUserRoute() {
return ffz_is_player || ffz.site.router.current.name == 'user';
}
function getReactInstance(el) {
for (const prop_name in el) {
if (prop_name.startsWith('__reactInternalInstance$')) return el[prop_name];
}
}
function getMessageObj(el) {
const inst = getReactInstance(el);
if (inst) return inst.return.pendingProps.message;
}
function getPropertyDescriptor(o, p) {
let desc;
do {
desc = Object.getOwnPropertyDescriptor(o, p);
o = Object.getPrototypeOf(o);
} while (!desc);
return desc;
}
Object.prototype.__mylookupGetter__ = function(p, return_set) {
let desc = getPropertyDescriptor(this, p);
return desc ? (return_set ? desc.set : desc.get) : undefined;
};
Object.defineProperty(Object.prototype, '__mylookupGetter__', {
enumerable: false
});
function replaceFunctions() {
try {
if (ffzenhancing_fix_addon_load) {
ffz.addons.loadAddon = async function(id) {
const addon = this.getAddon(id);
if (!addon)
throw new Error(`Unknown add-on id: ${id}`);
let module = this.resolve(`addon.${id}`);
if (module) {
if (!module.loaded)
await module.load();
this.emit(':addon-loaded', id);
return;
}
const el = ffz.constructor.utilities.dom.createElement('script', {
id: `ffz-loaded-addon-${addon.id}`,
type: 'text/javascript',
src: addon.src || `${addon.dev ? 'https://localhost:8001' : ffz.constructor.utilities.constants.SERVER}/script/addons/${addon.id}/script.js?_=${ffz.constructor.utilities.time.getBuster(30)}`,
crossorigin: 'anonymous'
});
document.head.appendChild(el);
await this.waitFor(`addon.${id}:registered`);
module = this.resolve(`addon.${id}`);
if (module && !module.loaded)
await module.load();
this.emit(':addon-loaded', id);
};
}
try {
ffzenhancing_always_show_open_thread_button_handler_hidden = ffz.site.children.chat.chat_line.actions.actions.reply.hidden;
ffzenhancing_always_show_open_thread_button_handler_click = ffz.site.children.chat.chat_line.actions.actions.reply.click;
} catch {}
if (ffz.settings.get('chat.filtering.display-deleted') === 'DETAILED') {
ffz.site.children.chat.ChatBuffer.ready((cls, instances) => {
const t = ffz.site.children.chat;
const old_mount = cls.prototype.componentDidMount;
cls.prototype.componentDidMount = function() {
setTimeout(() => {
try {
this.__ffz_enhancingInstall();
} catch {}
}, 1000);
return old_mount.call(this);
};
cls.prototype.__ffz_enhancingInstall = function() {
if (this.__ffz_enhancing_installed)
return;
this.__ffz_enhancing_installed = true;
const inst = this;
const handler = inst.props.messageHandlerAPI;
if (handler) {
if (inst.handleMessage === undefined) {
handler.addMessageHandler(my_handleMessage);
} else {
const orig_handleMessage = inst.handleMessage;
handler.removeMessageHandler(orig_handleMessage);
handler.addMessageHandler(my_handleMessage);
handler.addMessageHandler(orig_handleMessage);
}
}
function my_handleMessage(msg) {
if (msg) {
try {
const types = t.chat_types || {};
const mod_types = t.mod_types || {};
if (msg.type === types.Moderation && inst.unsetModeratedUser) {
if (inst.props.isCurrentUserModerator)
return;
const mod_action = msg.moderationType;
let new_action;
if (mod_action === mod_types.Ban)
new_action = 'ban';
else if (mod_action === mod_types.Timeout)
new_action = 'timeout';
if (new_action)
msg.moderationActionType = new_action;
else
return;
if (mod_action === mod_types.Timeout || mod_action === mod_types.Ban) {
for (const line of ffz.site.children.chat.chat_line.ChatLine.instances) {
const m = line.props.message;
if (m.user.userLogin === msg.userLogin && (m.modActionType === 'timeout' || m.modActionType === 'ban' || m.modActionType === 'delete')) {
m.modActionType = msg.moderationActionType;
m.duration = msg.duration;
m.banned = true;
m.deleted = true;
line.forceUpdate();
}
}
}
}
} catch {}
}
}
};
for (const inst of instances) {
try {
inst.__ffz_enhancingInstall();
} catch {}
}
});
}
} catch {}
}
function new_onStateChanged(e) {
try {
if (e === "Idle") {
currentPlayerUserPaused = this.paused;
} else {
currentPlayerUserPaused = false;
}
prev_player_onStateChanged.call(this, e);
} catch {}
}
function playerMount() {
try {
if ((ffz.site.children.player.current.core || ffz.site.children.player.current.playerInstance.core).onStateChanged === new_onStateChanged) return;
prev_player_onStateChanged = (ffz.site.children.player.current.core || ffz.site.children.player.current.playerInstance.core).onStateChanged;
(ffz.site.children.player.current.core || ffz.site.children.player.current.playerInstance.core).onStateChanged = new_onStateChanged;
} catch {}
}
function getElementByXpath(xpath) {
return document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
function findClosestBySelector(el, selector, depth) {
if (depth === undefined) depth = 1;
let parent = el;
for (let i = 0; i <= depth; i++) {
if (parent.matches && parent.matches(selector)) return parent;
parent = parent.parentNode;
if (!parent) return false;
}
return false;
}
function visibilityStateHookProc() {
if (visibility_hook_enabled) return 'visible';
return orig_visibilityStateProc();
}
function hiddenHookProc() {
if (document.pictureInPictureElement != null) return false;
return document.visibilityState === 'hidden';
}
function enableVisibilityHook() {
clearTimeout(visibility_hook_timeout);
visibility_hook_timeout = setTimeout(disableVisibilityHook, ffzenhancing_visibility_hook_time * 1000);
visibility_hook_enabled = true;
}
function disableVisibilityHook() {
clearTimeout(visibility_hook_timeout);
visibility_hook_enabled = false;
}
function playbackRateSetHook(rate) {
try {
if (ffzenhancing_keep_delay_low && !playbackRate_set_by_us && isPlayerOrUserRoute()) return rate;
} catch {}
return orig_playbackRate_set.call(this, rate);
};
function checkCard() {
clearTimeout(timeoutCheckCard);
if (document.querySelector('.viewer-card')) return timeoutCheckCard = setTimeout(checkCard, 1000);
removeAllHighlightedMessages();
}
function highlightMessages(username) {
if (!username) return;
const style = addStyleToSite('highlight_' + username, `
.ffz-notice-line[data-user="${username}"],
.chat-line__message:not(.chat-line--inline)[data-user="${username}"] {
background-color: #a50000;
}
`);
if (style) added_message_highlights[username] = style;
clearTimeout(timeoutCheckCard);
timeoutCheckCard = setTimeout(checkCard, 1000);
}
function removeAllHighlightedMessages() {
for (const username in added_message_highlights) {
removeStyleFromSite('highlight_' + username);
delete added_message_highlights[username]
}
}
function addStyleToSite(style_id, style_text) {
if (added_styles[style_id]) return;
let style = document.createElement('style');
style.textContent = style_text;
document.body.appendChild(style);
added_styles[style_id] = style;
return style;
}
function removeStyleFromSite(style_id) {
if (!(style_id in added_styles)) return;
try {
document.body.removeChild(added_styles[style_id]);
} catch {}
delete added_styles[style_id];
}
function processStaticEmoteRestore(el) {
el.srcset = el.srcset.replace(/https:\/\//g, 'https://cache.ffzap.com/https://');
}
function processStaticEmote(e, el, process_parent_children, skip_set_mouseout) {
if (!el) return false;
let processed_children = [];
if (process_parent_children) {
for (const child of el.parentNode.querySelectorAll('img')) {
if (child == el) continue;
let processed_child = processStaticEmote(e, child, false, true);
if (processed_child) processed_children.push(processed_child);
}
}
let can_process_el = el.srcset && el.srcset.startsWith('https://cache.ffzap.com/https://');
if (processed_children.length == 0 && !can_process_el) return false;
if (!skip_set_mouseout) {
let proc = () => {
if (can_process_el) processStaticEmoteRestore(el);
for (const child of processed_children) {
processStaticEmoteRestore(child);
}
e.target.removeEventListener('mouseout', proc);
};
e.target.addEventListener('mouseout', proc);
}
if (can_process_el) {
el.srcset = el.srcset.replace(/https:\/\/cache\.ffzap\.com\/https:\/\//g, 'https://');
return el;
}
return false;
}
function onNotifyWindowFocus() {
if (orig_visibilityStateProc() !== 'hidden') document.querySelector('link[rel="icon"]').href = notify_icon_original;
}
function playerQualityChanged(q) {
try {
if (!recently_clicked_playerQualityChange) return;
recently_clicked_playerQualityChange = false;
if (!isPlayerOrUserRoute()) return;
const autoQualityMode = (ffz.site.children.player.current.core || ffz.site.children.player.current.playerInstance.core).state.autoQualityMode;
if (autoQualityMode) {
ffz.settings.provider.delete('ffzenhancing.video-quality');
return;
}
const s = {
height: q.height,
framerate: q.framerate,
};
ffz.settings.provider.set('ffzenhancing.video-quality', s);
} catch {}
}
function getCurrentPlayerState() {
current_player_volume = undefined;
current_player_muted = undefined;
current_player_quality = undefined;
try {
current_player_volume = ffz.site.children.player.current.getVolume();
} catch {}
try {
current_player_muted = ffz.site.children.player.current.isMuted();
} catch {}
try {
current_player_quality = ffz.site.children.player.current.getQuality();
} catch {}
}
function setCurrentPlayerState() {
if (current_player_volume !== undefined) {
try {
ffz.site.children.player.current.setVolume(current_player_volume);
} catch {}
}
if (current_player_muted !== undefined) {
try {
ffz.site.children.player.current.setMuted(current_player_muted);
} catch {}
}
if (current_player_quality !== undefined && current_player_quality !== '') {
try {
ffz.site.children.player.current.setQuality(current_player_quality);
} catch {}
}
}
function ffzResetPlayer() {
enableVisibilityHook();
//ffz.emit('site.player:reset');
try {
ffz.site.children.player.resetPlayer(ffz.site.children.player.Player.first);
setTimeout(playerCompressorCheck, 1000);
} catch {}
}
function getChatInput() {
const el = ffz.resolve('site.chat.input').ChatInput.first.autocompleteInputRef.componentRef;
return el.value !== undefined ? el.value : el.props.value;
}
function setChatInput(txt) {
const el = ffz.resolve('site.chat.input').ChatInput.first.autocompleteInputRef;
el.setValue(txt);
el.componentRef.focus();
}
function setChatSelection(start, end) {
const el = ffz.resolve('site.chat.input').ChatInput.first;
el.chatInputRef.setSelectionRange(start, end);
el.autocompleteInputRef.componentRef.focus();
}
function focusChat() {
const txt = getChatInput();
setChatSelection(txt.length, txt.length);
}
function usernameElementClicked(el) {
if (
el.classList.contains('chat-author__display-name') ||
el.classList.contains('chat-author__intl-login') ||
el.classList.contains('chat-line__message-mention') && !el.classList.contains('ffz-i-threads') ||
el.parentNode.matches('span.chatter-name[role="button"]') ||
el.parentNode.matches('span.ffz--giftee-name[role="button"]') ||
((el.classList.contains('tw-link') || el.parentNode.classList.contains('tw-link')) && (
el.parentNode.parentNode.classList.contains('chatter-list-item') || // chatter name in chatter list
el.parentNode.parentNode.parentNode.parentNode.classList.contains('viewer-card-header__display-name') // chatter name link in viewer card
))
) {
return true;
}
return false;
}
function getLoginNameFromElement(el) {
let max_level = 10;
while (max_level >= 0) {
const data_login = el.getAttribute('data-login');
if (data_login !== null) return data_login;
const data_user = el.getAttribute('data-user');
if (data_user !== null) {
try {
return JSON.parse(data_user).login;
} catch {}
return data_user;
}
el = el.parentNode;
max_level--;
}
return false;
}
function clickFfzBigPlayButton() {
const buttonPlay = document.querySelector('button[data-a-target="player-overlay-play-button"]');
if (buttonPlay) {
enableVisibilityHook();
buttonPlay.click();
return true;
}
return false;
}
function isVodAndNotPaused() {
try {
const video = (ffz.site.children.player.current.core || ffz.site.children.player.current.playerInstance.core).mediaSinkManager.video;
if (video) {
let broadcast_id;
broadcast_id = ffz.site.children.player.current.getSessionData()['BROADCAST-ID'];
if (broadcast_id === undefined || Number.isNaN(broadcast_id)) { // broadcast_id is NaN when user was offline or in vod, preventing endless refreshes
if (!currentPlayerUserPaused) {
return true;
}
}
}
} catch {}
return false;
}
function getVideoLiveAndNotPaused() {
try {
const video = (ffz.site.children.player.current.core || ffz.site.children.player.current.playerInstance.core).mediaSinkManager.video;
if (video) {
let broadcast_id;
if (!isPlayerOrUserRoute()) return false;
broadcast_id = ffz.site.children.player.current.getSessionData()['BROADCAST-ID'];
if (broadcast_id !== undefined && !Number.isNaN(broadcast_id)) { // broadcast_id is NaN when user was offline or in vod, preventing endless refreshes
if (!currentPlayerUserPaused) {
return video;
}
}
}
} catch {}
return false;
}
function playerQualityCheck() {
if (!ffzenhancing_auto_check_player_quality) return;
if (timers['playerQualityCheck']) {
clearTimeout(timers['playerQualityCheck']);
}
try {
if (!recently_clicked_playerQualityChange && document.visibilityState !== 'hidden' && isPlayerOrUserRoute()) {
const def_quality = ffz.settings.provider.get('ffzenhancing.video-quality');
let autoQualityMode = (ffz.site.children.player.current.core || ffz.site.children.player.current.playerInstance.core).state.autoQualityMode;
if (autoQualityMode && ffz_is_player && def_quality) autoQualityMode = false;
if (!autoQualityMode && def_quality) {
const cur_quality = ffz.site.children.player.current.getQuality();
if (def_quality.height != cur_quality.height || def_quality.framerate != cur_quality.framerate || cur_quality.variantSource !== 'source') {
const new_quality = ffz.site.children.player.current.getQualities()
.filter(q => q.height == def_quality.height && q.framerate <= def_quality.framerate || q.height < def_quality.height)
.sort((a, b) => {
if (a.variantSource === 'source') return -1;
if (b.variantSource === 'source') return 1;
if (a.height > b.height) return -1;
if (a.height < b.height) return 1;
return 0;
})
.at(0);
if (new_quality && new_quality.variantSource != cur_quality.variantSource) {
ffz.site.children.player.current.setQuality(new_quality);
}
}
}
}
} catch {}
timers['playerQualityCheck'] = setTimeout(playerQualityCheck, 5000);
}
function compressPlayerChange() {
try {
let video = getVideoLiveAndNotPaused();
if (video) compressPlayerWanted = !video._ffz_compressed;
} catch {}
}
function playerCompressorCheck() {
if (!ffzenhancing_auto_check_player_compressor) return;
if (timers['playerCompressorCheck']) {
clearTimeout(timers['playerCompressorCheck']);
}
try {
let btn = ffz.site.children.player.Player.first.props.containerRef.querySelector('.ffz--player-comp button');
if (!btn.__ffz_enhancing_installed) {
btn.addEventListener('click', compressPlayerChange, true);
btn.__ffz_enhancing_installed = true;
}
} catch {}
try {
let video = getVideoLiveAndNotPaused();
if (video && compressPlayerWanted !== undefined && compressPlayerWanted !== !!video._ffz_compressed) {
ffz.site.children.player.compressPlayer.call(ffz.site.children.player, ffz.site.children.player.Player.first, document.createEvent('Event'));
}
} catch {}
timers['playerCompressorCheck'] = setTimeout(playerCompressorCheck, 5000);
}
function error_2000_check() {
if (!ffzenhancing_auto_reload_on_error_2000) {
if (timers['error_2000_check']) {
clearInterval(timers['error_2000_check']);
delete timers['error_2000_check'];
}
return;
}
if (!currentPlayerUserPaused) {
for (const el of document.querySelectorAll('.content-overlay-gate')) {
if (el.textContent.includes('1000') || el.textContent.includes('2000') || el.textContent.includes('3000') || el.textContent.includes('4000') || el.textContent.includes('5000')) {
ffzResetPlayer();
break;
}
}
}
if (!timers['error_2000_check']) {
timers['error_2000_check'] = setInterval(error_2000_check, 2000);
}
}
function playerFreezeCheck() {
if (!ffzenhancing_auto_reload_on_hanged_video) {
return;
}
if (timers['playerFreezeCheck']) {
clearTimeout(timers['playerFreezeCheck']);
}
const video = getVideoLiveAndNotPaused();
if (video) {
if (!clickFfzBigPlayButton()) {
if (ffzenhancing_auto_reload_on_hanged_video_currentTime !== 0 && ffzenhancing_auto_reload_on_hanged_video_currentTime == video.currentTime) {
ffzResetPlayer();
}
ffzenhancing_auto_reload_on_hanged_video_currentTime = video.currentTime;
}
}
timers['playerFreezeCheck'] = setTimeout(playerFreezeCheck, ffzenhancing_auto_reload_on_hanged_video_after * 1000);
}
function schedulePeriodicCheckVideoInfo(ms) {
clearTimeout(timeoutPeriodicCheckVideoInfo);
timeoutPeriodicCheckVideoInfo = setTimeout(periodicCheckVideoInfo, ms || 300);
}
function increasePlayerPlaybackSpeed(video) {
playbackRate_set_by_us = true;
video.playbackRate = ffzenhancing_keep_delay_low_rate;
playbackRate_set_by_us = false;
ffzenhancing_keep_delay_low_latency_was_changed = true;
}
function resetPlayerPlaybackSpeed(video) {
if (ffzenhancing_keep_delay_low_latency_was_changed) {
playbackRate_set_by_us = true;
video.playbackRate = 1;
playbackRate_set_by_us = false;
ffzenhancing_keep_delay_low_latency_was_changed = false;
}
buffer_times = [];
}
function checkDroppingFrames(obj) {
try {
if (!ffzenhancing_fix_video_freeze_on_tab_change || orig_visibilityStateProc() !== 'visible') return;
const max_tries = 40;
const try_interval = 100;
const detect_time = 500;
if (obj === undefined) obj = {};
if (obj.tries > max_tries) return;
const cur_decoded_frames = ffz.site.children.player.current.getDecodedFrames();
const cur_dropped_frames = ffz.site.children.player.current.getDroppedFrames();
if (!obj.done) {
const new_obj = {
prev_decoded_frames: cur_decoded_frames,
prev_dropped_frames: cur_dropped_frames,
};
if (
obj.prev_decoded_frames === undefined ||
obj.prev_decoded_frames === cur_decoded_frames
) {
new_obj.tries = (obj.tries || 0) + 1;
return setTimeout(checkDroppingFrames, try_interval, new_obj);
} else {
new_obj.done = true;
return setTimeout(checkDroppingFrames, detect_time, new_obj);
}
}
const isDropping = cur_dropped_frames - obj.prev_dropped_frames === cur_decoded_frames - obj.prev_decoded_frames;
if (isDropping) {
ffz.site.children.player.current.pause();
ffz.site.children.player.current.play();
}
} catch {}
}
function periodicCheckVideoInfo() {
const video = getVideoLiveAndNotPaused();
if (video) {
let liveLatency;
try {
liveLatency = (ffz.site.children.player.current.core && ffz.site.children.player.current.core.state && ffz.site.children.player.current.core.state.liveLatency) ||
(ffz.site.children.player.current.stats && ffz.site.children.player.current.stats.broadcasterLatency) ||
(ffz.site.children.player.current.core && ffz.site.children.player.current.core.stats && ffz.site.children.player.current.core.stats.broadcasterLatency) ||
(ffz.site.children.player.current.playerInstance && ffz.site.children.player.current.playerInstance.core && ffz.site.children.player.current.playerInstance.core.state && ffz.site.children.player.current.playerInstance.core.state.liveLatency);
} catch {}
if (liveLatency !== undefined) {
if (ffzenhancing_reset_after_delay) {
if (liveLatency > ffzenhancing_reset_after_delay_delay) {
ffzResetPlayer();
schedulePeriodicCheckVideoInfo(5000);
return;
}
}
if (ffzenhancing_keep_delay_low) {
let isLowDelayEnabled = false;
try {
isLowDelayEnabled = ffz.site.children.player.current.isLiveLowLatency() && window.localStorage.getItem('lowLatencyModeEnabled') !== 'false';
} catch {}
const delay = isLowDelayEnabled ? ffzenhancing_keep_delay_low_delay_low_latency : ffzenhancing_keep_delay_low_delay;
if (liveLatency > delay) {
try {
const buffer_time = (ffz.site.children.player.current.core || ffz.site.children.player.current.playerInstance.core).state.bufferedPosition - (ffz.site.children.player.current.core || ffz.site.children.player.current.playerInstance.core).state.position;
if (!Number.isNaN(buffer_time)) {
buffer_times.push(buffer_time);
if (buffer_times.length < 20) {
schedulePeriodicCheckVideoInfo();
return;
}
const min_buffer = Math.min.apply(null, buffer_times);
buffer_times.shift();
if (min_buffer < (isLowDelayEnabled ? 1 : 1.5)) {
resetPlayerPlaybackSpeed(video);
schedulePeriodicCheckVideoInfo(5000);
return;
}
}
} catch {}
increasePlayerPlaybackSpeed(video);
schedulePeriodicCheckVideoInfo();
return;
} else {
resetPlayerPlaybackSpeed(video);
}
} else {
resetPlayerPlaybackSpeed(video);
}
}
}
if (ffzenhancing_keep_delay_low || ffzenhancing_reset_after_delay) schedulePeriodicCheckVideoInfo(5000);
}
function periodicCheckClaimBonus() {
if (!ffzenhancing_auto_click_claim_bonus_points) return;
let button = getElementByXpath('//button[.//div[contains(@class, "claimable-bonus__icon")]]');
if (button && orig_visibilityStateProc() === 'visible') button.click();
if (timers['periodicCheckClaimBonus']) {
clearTimeout(timers['periodicCheckClaimBonus']);
}
timers['periodicCheckClaimBonus'] = setTimeout(periodicCheckClaimBonus, 5000);
}
function processSettings_schedule() {
setTimeout(processSettings, 1000);
}
function processSettings() {
// temp fixes
try {
function checkShowPinnedSetting(val) {
if (val === undefined) val = ffz.settings.get('chat.bits.show-pinned');
if (!val) {
addStyleToSite('ffzenhancing_hide_leaderboard', `
.chat-room__content > .tw-transition[class^="ScTransitionBase-sc-"]:first-child {
display: none;
}
`);
} else {
removeStyleFromSite('ffzenhancing_hide_leaderboard');
}
}
ffz.settings.on('settings:changed:chat.bits.show-pinned', checkShowPinnedSetting);
checkShowPinnedSetting();
} catch {}
let el;
let appendEl;
// ffzenhancing_move_users_in_chat_to_bottom
if (!window.location.href.endsWith('/squad')) {
function checkLoadFinished() {
if (ffzenhancing_move_users_in_chat_to_bottom) {
el = document.querySelector('.stream-chat-header button[data-test-selector="chat-viewer-list"]');
appendEl = document.querySelector('.chat-input__buttons-container > div:first-child');
} else {
el = document.querySelector('.chat-input__buttons-container button[data-test-selector="chat-viewer-list"]');
appendEl = document.querySelector('.stream-chat-header > div:last-child');
}
if (el && appendEl) {
if (!el.__click_handler) {
let clicked = false;
el.__click_handler = e => {
clicked = !clicked;
if (clicked) {
ffzenhancing_move_users_in_chat_to_bottom = false;
ffzenhancing_hide_rooms_header = false;
} else {
ffzenhancing_move_users_in_chat_to_bottom = ffz.settings.get('ffzenhancing.move_users_in_chat_to_bottom');
ffzenhancing_hide_rooms_header = ffz.settings.get('ffzenhancing.hide_rooms_header');
}
processSettings();
};
el.addEventListener('click', el.__click_handler);
}
el = el.parentNode;
el.parentNode.removeChild(el);
appendEl.prepend(el);
if (ffzenhancing_move_users_in_chat_to_bottom) {
addStyleToSite('ffzenhancing_move_users_in_chat_to_bottom', `
[data-test-selector="chat-input-buttons-container"] [role="dialog"] {
margin-left: -30px;
}
`);
} else {
removeStyleFromSite('ffzenhancing_move_users_in_chat_to_bottom');
}
let tooltip = el.querySelector('.tw-tooltip');
if (tooltip && tooltip.id) {
if (ffzenhancing_move_users_in_chat_to_bottom) {
addStyleToSite('ffzenhancing_move_users_in_chat_to_bottom_tooltip', `
[id="${tooltip.id}"] {
top: unset;
bottom: 100%;
margin-top: unset;
margin-bottom: 6px;
}
[id="${tooltip.id}"]::after {
top: unset;
bottom: -3px;
}
`);
} else {
removeStyleFromSite('ffzenhancing_move_users_in_chat_to_bottom_tooltip');
}
}
}
}
let timeoutChatLoaded;
if (ffz.resolve('site.chat')) ffz.resolve('site.chat').PointsButton.ready(() => {
clearTimeout(timeoutChatLoaded);
timeoutChatLoaded = setTimeout(checkLoadFinished, 1000);
});
}
// fix for broken pinned chat messages
addStyleToSite('ffzenhancing_fix_broken_pinned_chat_messages', `
.pinned-chat__message {
min-height: 0;
}
`);
// ffzenhancing_hide_rooms_header
if (!window.location.href.endsWith('/squad')) {
el = document.querySelector('.stream-chat-header');
if (el) {
if (ffzenhancing_hide_rooms_header) {
addStyleToSite('ffzenhancing_hide_rooms_header', `
.stream-chat-header {
height: 0;
opacity: 0;
pointer-events: none;
z-index: auto !important;
}
button[data-a-target="chat-viewer-list"][aria-label="Close"] {
margin-left: 30px;
}
.chat-input__buttons-container .tw-align-items-center .tw-mg-r-1 {
height: 30px;
}
`);
} else {
removeStyleFromSite('ffzenhancing_hide_rooms_header');
}
}
}
// ffzenhancing_pause_vod_on_click
if (ffzenhancing_pause_vod_on_click) {
if (!handlers_already_attached['ffzenhancing_pause_vod_on_click']) {
handlers_already_attached['ffzenhancing_pause_vod_on_click'] = e => {
if (!findClosestBySelector(e.target, '.player-overlay-background, [data-a-target="player-overlay-click-handler"]', 7)) return;
if (isVodAndNotPaused()) ffz.site.children.player.current.pause();
};
document.body.addEventListener('click', handlers_already_attached['ffzenhancing_pause_vod_on_click']);
}
} else {
if (handlers_already_attached['ffzenhancing_pause_vod_on_click']) {
document.body.removeEventListener('click', handlers_already_attached['ffzenhancing_pause_vod_on_click']);
delete handlers_already_attached['ffzenhancing_pause_vod_on_click'];
}
}
// ffzenhancing_hide_chat_collapse_button
if (ffzenhancing_hide_chat_collapse_button) {
addStyleToSite('ffzenhancing_hide_chat_collapse_button', `
.right-column:not(.right-column--fullscreen, .right-column--collapsed) .right-column__toggle-visibility {
display: none !important;
}
.right-column.right-column--fullscreen .right-column__toggle-visibility {
left: -35px;
}
`);
} else {
removeStyleFromSite('ffzenhancing_hide_chat_collapse_button');
}
// ffzenhancing_fix_tooltips
if (ffzenhancing_fix_tooltips) {
addStyleToSite('ffzenhancing_fix_tooltips', '.ffz__tooltip {pointer-events: none;}');
} else {
removeStyleFromSite('ffzenhancing_fix_tooltips');
}
// ffzenhancing_fix_emote_select
if (ffzenhancing_fix_emote_select) {
addStyleToSite('ffzenhancing_fix_emote_select', '.ffz--inline {display: inline-block;}');
} else {
removeStyleFromSite('ffzenhancing_fix_emote_select');
}
// ffzenhancing_animate_static_gif_emotes_on_mouse_hover
if (ffzenhancing_animate_static_gif_emotes_on_mouse_hover) {
if (!handlers_already_attached['ffzenhancing_animate_static_gif_emotes_on_mouse_hover']) {
handlers_already_attached['ffzenhancing_animate_static_gif_emotes_on_mouse_hover'] = e => {
if (e.target.nodeName == 'IMG' && e.target.classList.contains('chat-line__message--emote')) { // mouse over emote in chat
processStaticEmote(e, e.target, true);
} else if (e.target.nodeName == 'BUTTON' && e.target.classList.contains('emote-picker__emote-link')) { // mouse over emote in emote picker
processStaticEmote(e, e.target.querySelector('img'));
}
};
document.body.addEventListener('mouseover', handlers_already_attached['ffzenhancing_animate_static_gif_emotes_on_mouse_hover']);
}
} else {
if (handlers_already_attached['ffzenhancing_animate_static_gif_emotes_on_mouse_hover']) {
document.body.removeEventListener('mouseover', handlers_already_attached['ffzenhancing_animate_static_gif_emotes_on_mouse_hover']);
delete handlers_already_attached['ffzenhancing_animate_static_gif_emotes_on_mouse_hover'];
}
}
// ffzenhancing_auto_check_player_quality
if (ffzenhancing_auto_check_player_quality) {
try {
if (!handlers_already_attached['PlayerQualityChange_click']) {
handlers_already_attached['PlayerQualityChange_click'] = true;
document.body.addEventListener('click', e => {
if (!ffzenhancing_auto_check_player_quality) return;
if (!isPlayerOrUserRoute()) return;
if (!findClosestBySelector(e.target, '[data-a-target="player-settings-submenu-quality-option"]', 2)) return;
recently_clicked_playerQualityChange = true;
});
}
ffz.site.children.player.current.removeEventListener('PlayerQualityChanged', playerQualityChanged);
ffz.site.children.player.current.addEventListener('PlayerQualityChanged', playerQualityChanged);
} catch {}
}
// ffzenhancing_always_show_open_thread_button
try {