@@ -21,86 +21,3 @@ document.addEventListener(
2121window . open = ( url , target , features ) => {
2222 window . top . postMessage ( { modrinthOpenUrl : url } , 'https://modrinth.com' )
2323}
24-
25- function muteAudioContext ( ) {
26- if ( window . AudioContext || window . webkitAudioContext ) {
27- const AudioContext = window . AudioContext || window . webkitAudioContext
28- const originalCreateMediaElementSource = AudioContext . prototype . createMediaElementSource
29- const originalCreateMediaStreamSource = AudioContext . prototype . createMediaStreamSource
30- const originalCreateMediaStreamTrackSource = AudioContext . prototype . createMediaStreamTrackSource
31- const originalCreateBufferSource = AudioContext . prototype . createBufferSource
32- const originalCreateOscillator = AudioContext . prototype . createOscillator
33-
34- AudioContext . prototype . createGain = function ( ) {
35- const gain = originalCreateGain . call ( this )
36- gain . gain . value = 0
37- return gain
38- }
39-
40- AudioContext . prototype . createMediaElementSource = function ( mediaElement ) {
41- const source = originalCreateMediaElementSource . call ( this , mediaElement )
42- source . connect ( this . createGain ( ) )
43- return source
44- }
45-
46- AudioContext . prototype . createMediaStreamSource = function ( mediaStream ) {
47- const source = originalCreateMediaStreamSource . call ( this , mediaStream )
48- source . connect ( this . createGain ( ) )
49- return source
50- }
51-
52- AudioContext . prototype . createMediaStreamTrackSource = function ( mediaStreamTrack ) {
53- const source = originalCreateMediaStreamTrackSource . call ( this , mediaStreamTrack )
54- source . connect ( this . createGain ( ) )
55- return source
56- }
57-
58- AudioContext . prototype . createBufferSource = function ( ) {
59- const source = originalCreateBufferSource . call ( this )
60- source . connect ( this . createGain ( ) )
61- return source
62- }
63-
64- AudioContext . prototype . createOscillator = function ( ) {
65- const oscillator = originalCreateOscillator . call ( this )
66- oscillator . connect ( this . createGain ( ) )
67- return oscillator
68- }
69- }
70- }
71-
72- function muteVideo ( mediaElement ) {
73- let count = Number ( mediaElement . getAttribute ( 'data-modrinth-muted-count' ) ?? 0 )
74-
75- if ( ! mediaElement . muted || mediaElement . volume !== 0 ) {
76- mediaElement . muted = true
77- mediaElement . volume = 0
78-
79- mediaElement . setAttribute ( 'data-modrinth-muted-count' , count + 1 )
80- }
81-
82- if ( count > 5 ) {
83- // Video is detected as malicious, so it is removed from the page
84- mediaElement . remove ( )
85- }
86- }
87-
88- function muteVideos ( ) {
89- document . querySelectorAll ( 'video, audio' ) . forEach ( function ( mediaElement ) {
90- muteVideo ( mediaElement )
91-
92- if ( ! mediaElement . hasAttribute ( 'data-modrinth-muted' ) ) {
93- mediaElement . addEventListener ( 'volumechange' , ( ) => muteVideo ( mediaElement ) )
94-
95- mediaElement . setAttribute ( 'data-modrinth-muted' , 'true' )
96- }
97- } )
98- }
99-
100- document . addEventListener ( 'DOMContentLoaded' , ( ) => {
101- muteVideos ( )
102- muteAudioContext ( )
103-
104- const observer = new MutationObserver ( muteVideos )
105- observer . observe ( document . body , { childList : true , subtree : true } )
106- } )
0 commit comments