Repository navigation
Expand file tree
/
Copy pathcontent.js
More file actions
1224 lines (992 loc) · 36.7 KB
/
Copy pathcontent.js
File metadata and controls
1224 lines (992 loc) · 36.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
/*
* Instagram Video Controls — content script.
*
* Adds custom video controls to Instagram Reels, Stories,
* and videos. Injected by the extension manifest at
* document-start.
*/
;(() => {
'use strict'
const DEBUG = false
/*
* Progress-bar-only mode: the extension contributes
* just the seek bar. Audio, play/pause and speed stay
* under Instagram's own control.
*
* Set to false to restore the full control bar
* (play, time, speed, mute, volume).
*/
const PROGRESS_ONLY = true
function log(...args) {
if (DEBUG) {
console.debug('[IGVC]', ...args)
}
}
function logError(...args) {
console.error('[IGVC]', ...args)
}
const VIDEO_SELECTOR = 'video'
const initialized = new WeakSet()
/*
* Videos that have actually started playing.
* Controls are offered only for these. A Set (not a
* WeakSet) so we can iterate it when pausing everything.
*/
const activated = new Set()
/*
* IntersectionObserver tracks how much of each video is
* really on screen, clipped by ancestor containers.
* Raw viewport-rect math counts carousel slides swiped
* aside as "visible" — they are clipped by the
* carousel's overflow-hidden window; IO is not.
*/
const visibleRatio = new WeakMap()
const intersectionObserver = new IntersectionObserver(
(entries) => {
for (const entry of entries) {
visibleRatio.set(entry.target, entry.intersectionRatio)
}
},
{ threshold: [0, 0.5, 1] },
)
/*
* User intent, enforced against Instagram's own
* re-assertions. Instagram overwrites play/pause and
* mute state set programmatically, so the intent is
* re-applied in the video event handlers. A real
* (trusted) click on the video clears it.
*/
const playIntent = new WeakMap()
let activeVideo = null
/*
* ONE global audio preference for every video — the
* toggle users expect: unmute once, sound stays on
* while scrolling, on Explore, and across loops.
* Persisted so it survives reloads. Per-video state
* used to capture Instagram's own end-of-loop muting
* and replay it as if the user chose it.
*/
let globalAudioPref = { muted: false, volume: 1 }
/*
* Persisted audio preference, so the toggle survives
* page reloads. Mirrors Instagram's own behavior
* (latest toggle applies everywhere) without depending
* on Instagram's internal storage.
*/
const AUDIO_PREF_KEY = 'igvc-audio-pref'
function loadAudioPref() {
try {
const raw = localStorage.getItem(AUDIO_PREF_KEY)
const pref = raw ? JSON.parse(raw) : null
return pref && typeof pref.muted === 'boolean' ? pref : null
} catch {
return null
}
}
function saveAudioPref() {
try {
if (globalAudioPref) {
localStorage.setItem(
AUDIO_PREF_KEY,
JSON.stringify(globalAudioPref),
)
}
} catch {
// Storage unavailable; stay session-only.
}
}
let overlay = null
let controls = null
let toastTimer = null
// ============================================================
// Helpers
// ============================================================
function formatTime(seconds) {
if (!Number.isFinite(seconds)) {
return '0:00'
}
seconds = Math.max(0, Math.floor(seconds))
const hours = Math.floor(seconds / 3600)
const minutes = Math.floor((seconds % 3600) / 60)
const secs = seconds % 60
if (hours > 0) {
return (
`${hours}:` +
`${String(minutes).padStart(2, '0')}:` +
`${String(secs).padStart(2, '0')}`
)
}
return `${minutes}:` + `${String(secs).padStart(2, '0')}`
}
function createButton(label, title) {
const button = document.createElement('button')
button.type = 'button'
button.className = 'igvc-button'
button.textContent = label
button.title = title
button.setAttribute('aria-label', title)
return button
}
// ============================================================
// Audio state
// ============================================================
/*
* Apply the single global preference to a video.
* volumechange enforcement handles Instagram's
* later re-assertions.
*/
function applyGlobalAudio(video) {
if (!video) return
try {
if (globalAudioPref.muted) {
video.muted = true
} else {
if (video.volume !== globalAudioPref.volume) {
video.volume = globalAudioPref.volume
}
video.muted = false
}
} catch (err) {
// Ignore browser restrictions.
logError('applyGlobalAudio')
logError(err)
}
}
// ============================================================
// Find visible videos
// ============================================================
function getVisibleVideos() {
try {
return [...document.querySelectorAll(VIDEO_SELECTOR)].filter(
(video) => {
if (!(video instanceof HTMLVideoElement)) {
return false
}
if (!activated.has(video)) {
return false
}
/*
* Drop entries for unmounted videos so
* the Set does not grow forever.
*/
if (!video.isConnected) {
activated.delete(video)
return false
}
const rect = video.getBoundingClientRect()
if (rect.width <= 100 || rect.height <= 100) {
return false
}
/*
* Real on-screen fraction, clipped by
* ancestors (carousel window, modals).
*/
if ((visibleRatio.get(video) ?? 0) < 0.5) {
return false
}
return true
},
)
} catch (err) {
logError('getVisibleVideos()')
logError(err)
}
}
/*
* Largest visible area wins. The dominance filter
* (>= 50% visible) already ran in getVisibleVideos,
* so this simply picks the post with the biggest
* on-screen footprint.
*/
function getVisibilityScore(video) {
const rect = video.getBoundingClientRect()
const width = Math.max(
0,
Math.min(window.innerWidth, rect.right) - Math.max(0, rect.left),
)
const height = Math.max(
0,
Math.min(window.innerHeight, rect.bottom) - Math.max(0, rect.top),
)
return width * height
}
function findActiveVideo() {
const videos = getVisibleVideos()
if (!videos.length) return null
/*
* When a modal (post/reel dialog) is open, only
* videos inside it are eligible: feed videos behind
* the backdrop win on raw visible area otherwise.
*/
const inDialog = videos.filter((video) =>
video.closest('[role="dialog"]'),
)
const pool = inDialog.length ? inDialog : videos
pool.sort((a, b) => getVisibilityScore(b) - getVisibilityScore(a))
return pool[0]
}
// ============================================================
// Create overlay
// ============================================================
function createOverlay() {
if (overlay) return
overlay = document.createElement('div')
overlay.id = 'igvc-overlay'
document.body.appendChild(overlay)
// --------------------------------------------------------
// Controls
// --------------------------------------------------------
controls = document.createElement('div')
controls.id = 'igvc-controls'
// --------------------------------------------------------
// Play
// --------------------------------------------------------
const playButton = createButton('▶', 'Play')
// --------------------------------------------------------
// Mute + volume
// --------------------------------------------------------
const audioGroup = document.createElement('div')
audioGroup.className = 'igvc-audio-group'
/*
* Volume wrapper
*/
const volumeWrapper = document.createElement('div')
volumeWrapper.className = 'igvc-volume-wrapper'
/*
* Vertical volume slider
*/
const volume = document.createElement('input')
volume.type = 'range'
volume.className = 'igvc-volume'
volume.min = '0'
volume.max = '1'
volume.step = '0.01'
volume.value = '1'
volume.title = 'Volume'
volume.setAttribute('aria-label', 'Volume')
volumeWrapper.appendChild(volume)
/*
* Mute button
*/
const muteButton = createButton('🔇', 'Unmute')
/*
* Put volume above mute.
*/
audioGroup.appendChild(volumeWrapper)
audioGroup.appendChild(muteButton)
// --------------------------------------------------------
// Time
// --------------------------------------------------------
const time = document.createElement('span')
time.className = 'igvc-time'
time.textContent = '0:00 / 0:00'
// --------------------------------------------------------
// Progress
// --------------------------------------------------------
const progress = document.createElement('input')
progress.type = 'range'
progress.className = 'igvc-progress'
progress.min = '0'
progress.max = '100'
progress.step = '0.1'
progress.value = '0'
progress.title = 'Seek'
// --------------------------------------------------------
// Speed
// --------------------------------------------------------
const speed = document.createElement('select')
speed.className = 'igvc-speed'
speed.title = 'Playback speed'
;[
['0.5', '0.5×'],
['0.75', '0.75×'],
['1', '1×'],
['1.25', '1.25×'],
['1.5', '1.5×'],
['2', '2×'],
].forEach(([value, label]) => {
const option = document.createElement('option')
option.value = value
option.textContent = label
if (value === '1') {
option.selected = true
}
speed.appendChild(option)
})
// --------------------------------------------------------
// Assemble
// --------------------------------------------------------
/*
* PROGRESS_ONLY: the seek bar is the only element
* we add; everything else stays Instagram's.
* The other elements are still created and wired,
* just never attached — flip the flag to restore.
*/
if (!PROGRESS_ONLY) {
controls.appendChild(playButton)
controls.appendChild(time)
controls.appendChild(speed)
/*
* Audio group last: the mute button sits at the
* far right of the bar, matching Instagram's own
* audio control placement.
*/
controls.appendChild(audioGroup)
}
controls.appendChild(progress)
overlay.appendChild(controls)
// --------------------------------------------------------
// Toast
// --------------------------------------------------------
const toast = document.createElement('div')
toast.id = 'igvc-toast'
overlay.appendChild(toast)
// --------------------------------------------------------
// Progress time tooltip
// --------------------------------------------------------
const progressTip = document.createElement('div')
progressTip.id = 'igvc-progress-tip'
overlay.appendChild(progressTip)
// ========================================================
// Event protection
// ========================================================
/*
* The bar lives inside Instagram's <a href>
* wrappers: without preventDefault(), any
* click on it would navigate to the post.
* Bubble phase so the buttons' own handlers
* run first; stopPropagation then keeps the
* event from reaching the page.
*/
;[controls].forEach((element) => {
element.addEventListener('pointerdown', (event) => {
event.stopPropagation()
})
element.addEventListener('click', (event) => {
event.stopPropagation()
event.preventDefault()
})
element.addEventListener('touchstart', (event) => {
event.stopPropagation()
})
})
/*
* Reveal the bar by pointer coordinates. Instagram's
* player overlay intercepts pointer events over the
* video, so CSS :hover on the anchor never fires on
* /p/ pages; the bar is a sibling beneath that
* overlay. Coordinate checks don't care which
* element is on top.
*/
document.addEventListener(
'pointermove',
(event) => {
if (!controls) return
if (!activeVideo) {
controls.classList.remove('igvc-visible')
return
}
const rect = activeVideo.getBoundingClientRect()
const inside =
event.clientX >= rect.left &&
event.clientX <= rect.right &&
event.clientY >= rect.top &&
event.clientY <= rect.bottom
controls.classList.toggle('igvc-visible', inside)
},
{ passive: true },
)
// ========================================================
// Play
// ========================================================
playButton.addEventListener('click', (event) => {
event.preventDefault()
log('play button clicked')
if (!activeVideo) {
return
}
togglePlay(activeVideo)
})
// ========================================================
// Mute
// ========================================================
muteButton.addEventListener('click', (event) => {
event.preventDefault()
if (!activeVideo) return
/*
* One global toggle: sound on/off for every
* video, current and future.
*/
globalAudioPref.muted = !globalAudioPref.muted
saveAudioPref()
applyGlobalAudio(activeVideo)
updateUI()
showToast(globalAudioPref.muted ? 'Muted' : 'Sound on')
})
// ========================================================
// Volume
// ========================================================
volume.addEventListener('input', (event) => {
event.stopPropagation()
if (!activeVideo) return
const value = Number(volume.value)
if (value > 0) {
globalAudioPref.volume = value
globalAudioPref.muted = false
} else {
globalAudioPref.muted = true
}
saveAudioPref()
applyGlobalAudio(activeVideo)
updateUI()
})
// ========================================================
// Seek
// ========================================================
progress.addEventListener('input', (event) => {
event.stopPropagation()
if (!activeVideo) return
if (
!Number.isFinite(activeVideo.duration) ||
activeVideo.duration <= 0
) {
return
}
activeVideo.currentTime =
(Number(progress.value) / 100) * activeVideo.duration
log('seek:', activeVideo.currentTime)
})
// ========================================================
// Progress time tooltip
// ========================================================
progress.addEventListener('pointermove', (event) => {
if (!progressTip) return
if (
!activeVideo ||
!Number.isFinite(activeVideo.duration) ||
activeVideo.duration <= 0
) {
return
}
const rect = progress.getBoundingClientRect()
const fraction = Math.min(
1,
Math.max(0, (event.clientX - rect.left) / rect.width),
)
progressTip.textContent = formatTime(
fraction * activeVideo.duration,
)
progressTip.style.left = `${event.clientX}px`
progressTip.style.top = `${rect.top}px`
progressTip.classList.add('visible')
})
progress.addEventListener('pointerleave', () => {
progressTip?.classList.remove('visible')
})
// ========================================================
// Speed
// ========================================================
speed.addEventListener('change', (event) => {
event.stopPropagation()
if (!activeVideo) return
activeVideo.playbackRate = Number(speed.value)
log('speed:', speed.value)
showToast(`${speed.value}× speed`)
})
// ========================================================
// Trusted clicks win
// ========================================================
/*
* A real user click means the user is driving the
* page directly (including Instagram's own
* click-to-pause). Drop our play/mute intents so
* we never fight actual user input — on any
* surface; [data-interactable] only exists in the
* feed DOM, not on /p/ pages or modals.
*
* Our own control clicks still enforce: this is
* capture phase, so it runs before the button's
* handler sets a fresh intent.
*/
document.addEventListener(
'click',
(event) => {
if (!event.isTrusted || !activeVideo) return
playIntent.delete(activeVideo)
},
true,
)
}
// ============================================================
// Play / pause
// ============================================================
/*
* Toggle playback directly and record the intent.
*
* Instagram re-asserts its own player state after
* programmatic play()/pause() calls (and ignores
* synthetic clicks on its own layers). The intent is
* enforced in the play/pause handlers below until the
* user clicks the video natively.
*/
function togglePlay(video) {
try {
if (!video) return
if (video.paused) {
log('togglePlay: play')
playIntent.set(video, 'play')
applyGlobalAudio(video)
video
.play()
.then(() => {
applyGlobalAudio(video)
})
.catch(() => {})
} else {
log('togglePlay: pause')
playIntent.set(video, 'pause')
video.pause()
}
} catch (err) {
logError('togglePlay()')
logError(err)
}
}
// ============================================================
// UI update
// ============================================================
function updateUI() {
if (!activeVideo || !controls) return
const progress = controls.querySelector('.igvc-progress')
if (!PROGRESS_ONLY) {
const playButton = controls.querySelector('.igvc-button')
const muteButton = controls.querySelector(
'.igvc-audio-group .igvc-button',
)
const time = controls.querySelector('.igvc-time')
const volume = controls.querySelector('.igvc-volume')
// --------------------------------------------------------
// Play
// --------------------------------------------------------
if (activeVideo.paused) {
playButton.textContent = '▶'
playButton.title = 'Play'
playButton.setAttribute('aria-label', 'Play')
} else {
playButton.textContent = '❚❚'
playButton.title = 'Pause'
playButton.setAttribute('aria-label', 'Pause')
}
// --------------------------------------------------------
// Mute
// --------------------------------------------------------
if (activeVideo.muted || activeVideo.volume === 0) {
muteButton.textContent = '🔇'
muteButton.title = 'Unmute'
muteButton.setAttribute('aria-label', 'Unmute')
} else {
muteButton.textContent = '🔊'
muteButton.title = 'Mute'
muteButton.setAttribute('aria-label', 'Mute')
}
// --------------------------------------------------------
// Volume
// --------------------------------------------------------
volume.value = activeVideo.muted ? '0' : String(activeVideo.volume)
// --------------------------------------------------------
// Time
// --------------------------------------------------------
time.textContent =
`${formatTime(activeVideo.currentTime)} / ` +
`${formatTime(activeVideo.duration)}`
}
// --------------------------------------------------------
// Progress
// --------------------------------------------------------
if (progress) {
if (
Number.isFinite(activeVideo.duration) &&
activeVideo.duration > 0
) {
progress.value =
(activeVideo.currentTime / activeVideo.duration) * 100
} else {
progress.value = '0'
}
}
}
// ============================================================
// Position controls
// ============================================================
/*
* The bar sits in the page flow right after the video's
* media block, so only the floating elements (big play,
* toast) need positioning.
*/
function positionControls() {
if (!activeVideo || !controls) return
const rect = activeVideo.getBoundingClientRect()
// --------------------------------------------------------
// Controls bar
// --------------------------------------------------------
/*
* Viewport coordinates: the bar is position: fixed
* inside our body-level overlay.
*
* Slightly narrower than the video and centered, so
* Instagram's own player buttons (audio, tagging)
* at the corners stay clickable.
*/
/*
* Stories: the reply box, like and share buttons
* live at the bottom of the viewer — lift the bar
* above them.
*/
const bottomLift = location.pathname.startsWith('/stories') ? 90 : 0
const barWidth = rect.width * 0.8
controls.style.left = `${rect.left + (rect.width - barWidth) / 2}px`
controls.style.top = `${rect.bottom - bottomLift}px`
controls.style.width = `${barWidth}px`
// --------------------------------------------------------
// Toast
// --------------------------------------------------------
const toast = document.getElementById('igvc-toast')
if (toast) {
toast.style.left = `${rect.left + rect.width / 2}px`
toast.style.top = `${rect.top + rect.height / 2}px`
}
}
// ============================================================
// Toast
// ============================================================
function showToast(message) {
const toast = document.getElementById('igvc-toast')
if (!toast) return
toast.textContent = message
toast.classList.add('visible')
clearTimeout(toastTimer)
toastTimer = setTimeout(() => {
toast.classList.remove('visible')
}, 700)
}
// ============================================================
// Video setup
// ============================================================
function attachVideo(video) {
if (initialized.has(video)) return
initialized.add(video)
intersectionObserver.observe(video)
log('attach video:', video.currentSrc || '(no src)')
/*
* A video that is already playing when we first see
* it counts as activated.
*/
if (!video.paused) {
activated.add(video)
if (!PROGRESS_ONLY) {
applyGlobalAudio(video)
}
}
// --------------------------------------------------------
// Play
// --------------------------------------------------------
video.addEventListener(
'play',
() => {
/*
* The user asked for pause. Override
* Instagram's re-play.
*/
if (playIntent.get(video) === 'pause') {
log('play event: enforcing user pause')
video.pause()
return
}
/*
* Every playing video follows the global
* audio preference — including loop
* restarts, where Instagram re-mutes, and
* Explore hover previews.
*/
if (!PROGRESS_ONLY) {
applyGlobalAudio(video)
requestAnimationFrame(() => {
applyGlobalAudio(video)
})
}
/*
* Explore grid hover previews play on their
* own. Only offer controls there for videos
* the user actually opened (dialog).
*/
if (
location.pathname.startsWith('/explore') &&
!video.closest('[role="dialog"]')
) {
log('play event: explore preview, skipped')
return
}
/*
* Playback started: the video is now
* eligible for controls.
*/
activated.add(video)
log('video activated')
updateActiveVideo()
if (video === activeVideo) {
updateUI()
}
},
true,
)
// --------------------------------------------------------
// Pause
// --------------------------------------------------------
video.addEventListener(
'pause',
() => {
/*
* The user asked for play. Override
* Instagram's re-pause.
*/
if (playIntent.get(video) === 'play') {
log('pause event: enforcing user play')
video.play().catch(() => {})
return
}
if (video === activeVideo) {
updateUI()
}
},
true,
)
// --------------------------------------------------------
// Time
// --------------------------------------------------------
video.addEventListener('timeupdate', () => {
if (video === activeVideo) {
updateUI()
}
})
// --------------------------------------------------------
// Metadata
// --------------------------------------------------------
video.addEventListener('loadedmetadata', () => {
if (video === activeVideo) {
updateUI()
positionControls()
}
})
// --------------------------------------------------------
// Duration
// --------------------------------------------------------
video.addEventListener('durationchange', () => {
if (video === activeVideo) {
updateUI()
}
})
// --------------------------------------------------------
// Volume changes
// --------------------------------------------------------
video.addEventListener(
'volumechange',
() => {
/*
* Enforce the global audio preference
* against Instagram's own re-assertions
* (it re-mutes on loop, scroll, restart).
*/
if (video === activeVideo || activated.has(video)) {
if (!PROGRESS_ONLY) {
if (
video.muted !== globalAudioPref.muted ||
(!globalAudioPref.muted &&
video.volume !== globalAudioPref.volume)
) {
applyGlobalAudio(video)
}
}