@@ -2,76 +2,78 @@ import { stringifyRuns } from '../ts/ytcf-utils';
2
2
import { fixLeaks } from '../ts/ytc-fix-memleaks' ;
3
3
import { parseMessageRuns } from '../ts/chat-parser' ;
4
4
5
- for ( const eventName of [ 'visibilitychange' , 'webkitvisibilitychange' , 'blur' ] ) {
6
- window . addEventListener ( eventName , event => {
7
- event . stopImmediatePropagation ( ) ;
8
- } , true ) ;
9
- }
10
- const fetchFallback = window . fetch ;
11
- ( window as any ) . fetchFallback = fetchFallback ;
12
- window . fetch = async ( ...args ) => {
13
- const request = args [ 0 ] as Request ;
14
- const url = request . url ;
15
- const result = await fetchFallback ( ...args ) ;
16
-
17
- const currentDomain = ( location . protocol + '//' + location . host ) ;
18
- const ytApi = ( end : string ) : string => `${ currentDomain } /youtubei/v1/live_chat${ end } ` ;
19
- const isReceiving = url . startsWith ( ytApi ( '/get_live_chat' ) ) ;
20
- const isSending = url . startsWith ( ytApi ( '/send_message' ) ) ;
21
- const action = isReceiving ? 'messageReceive' : 'messageSent' ;
22
- if ( isReceiving || isSending ) {
23
- const response = JSON . stringify ( await ( result . clone ( ) ) . json ( ) ) ;
24
- window . dispatchEvent ( new CustomEvent ( action , { detail : response } ) ) ;
5
+ if ( ! window . location . href . includes ( 'v=Lq9eqHDKJPE&ytcfilter=1' ) ) {
6
+ for ( const eventName of [ 'visibilitychange' , 'webkitvisibilitychange' , 'blur' ] ) {
7
+ window . addEventListener ( eventName , event => {
8
+ event . stopImmediatePropagation ( ) ;
9
+ } , true ) ;
25
10
}
26
- return result ;
27
- } ;
28
- // window.dispatchEvent(new CustomEvent('chatLoaded', {
29
- // detail: JSON.stringify(window.ytcfg)
30
- // }));
31
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
32
- window . addEventListener ( 'proxyFetchRequest' , async ( event ) => {
33
- const args = JSON . parse ( ( event as any ) . detail as string ) as [ string , any ] ;
34
- const request = await fetchFallback ( ...args ) ;
35
- const response = await request . json ( ) ;
36
- window . dispatchEvent ( new CustomEvent ( 'proxyFetchResponse' , {
37
- detail : JSON . stringify ( response )
38
- } ) ) ;
39
- } ) ;
11
+ const fetchFallback = window . fetch ;
12
+ ( window as any ) . fetchFallback = fetchFallback ;
13
+ window . fetch = async ( ...args ) => {
14
+ const request = args [ 0 ] as Request ;
15
+ const url = request . url ;
16
+ const result = await fetchFallback ( ...args ) ;
17
+
18
+ const currentDomain = ( location . protocol + '//' + location . host ) ;
19
+ const ytApi = ( end : string ) : string => `${ currentDomain } /youtubei/v1/live_chat${ end } ` ;
20
+ const isReceiving = url . startsWith ( ytApi ( '/get_live_chat' ) ) ;
21
+ const isSending = url . startsWith ( ytApi ( '/send_message' ) ) ;
22
+ const action = isReceiving ? 'messageReceive' : 'messageSent' ;
23
+ if ( isReceiving || isSending ) {
24
+ const response = JSON . stringify ( await ( result . clone ( ) ) . json ( ) ) ;
25
+ window . dispatchEvent ( new CustomEvent ( action , { detail : response } ) ) ;
26
+ }
27
+ return result ;
28
+ } ;
29
+ // window.dispatchEvent(new CustomEvent('chatLoaded', {
30
+ // detail: JSON.stringify(window.ytcfg)
31
+ // }));
32
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
33
+ window . addEventListener ( 'proxyFetchRequest' , async ( event ) => {
34
+ const args = JSON . parse ( ( event as any ) . detail as string ) as [ string , any ] ;
35
+ const request = await fetchFallback ( ...args ) ;
36
+ const response = await request . json ( ) ;
37
+ window . dispatchEvent ( new CustomEvent ( 'proxyFetchResponse' , {
38
+ detail : JSON . stringify ( response )
39
+ } ) ) ;
40
+ } ) ;
40
41
41
- try {
42
- const video = ( window as any )
43
- . parent . yt . config_ . SBOX_SETTINGS . SEARCHBOX_COMPONENT . __dataHost . parentComponent
44
- . __data . data . response . contents . twoColumnWatchNextResults . results . results . contents [ 0 ]
45
- . videoPrimaryInfoRenderer ;
46
- const channel = ( window as any ) . parent . yt . config_ . SBOX_SETTINGS . SEARCHBOX_COMPONENT . __dataHost
47
- . parentComponent . __data . data . response . contents . twoColumnWatchNextResults . results . results
48
- . contents [ 1 ] . videoSecondaryInfoRenderer . owner . videoOwnerRenderer ;
49
- const params = new URLSearchParams ( window . parent . location . search ) ;
50
- window . dispatchEvent ( new CustomEvent ( 'videoInfo' , {
51
- detail : JSON . stringify ( {
52
- video : {
53
- title : stringifyRuns ( parseMessageRuns ( video . title . runs ) ) ,
54
- videoId : video . updatedMetadataEndpoint ?. updatedMetadataEndpoint ?. videoId || params . get ( 'v' )
55
- } ,
56
- channel : {
57
- channelId : channel . navigationEndpoint . browseEndpoint . browseId ,
58
- handle : channel . navigationEndpoint . browseEndpoint . canonicalBaseUrl . split ( '/@' ) [ 1 ] ,
59
- name : stringifyRuns ( parseMessageRuns ( channel . title . runs ) )
60
- }
61
- } )
62
- } ) ) ;
63
- } catch ( e ) {
64
- const videoId = new URLSearchParams ( window . location . search ) . get ( 'v' ) ;
65
- window . dispatchEvent ( new CustomEvent ( 'videoInfo' , {
66
- detail : JSON . stringify (
67
- videoId !== null
68
- ? {
69
- video : {
70
- videoId
42
+ try {
43
+ const video = ( window as any )
44
+ . parent . yt . config_ . SBOX_SETTINGS . SEARCHBOX_COMPONENT . __dataHost . parentComponent
45
+ . __data . data . response . contents . twoColumnWatchNextResults . results . results . contents [ 0 ]
46
+ . videoPrimaryInfoRenderer ;
47
+ const channel = ( window as any ) . parent . yt . config_ . SBOX_SETTINGS . SEARCHBOX_COMPONENT . __dataHost
48
+ . parentComponent . __data . data . response . contents . twoColumnWatchNextResults . results . results
49
+ . contents [ 1 ] . videoSecondaryInfoRenderer . owner . videoOwnerRenderer ;
50
+ const params = new URLSearchParams ( window . parent . location . search ) ;
51
+ window . dispatchEvent ( new CustomEvent ( 'videoInfoYtcFilter' , {
52
+ detail : JSON . stringify ( {
53
+ video : {
54
+ title : stringifyRuns ( parseMessageRuns ( video . title . runs ) ) ,
55
+ videoId : video . updatedMetadataEndpoint ?. updatedMetadataEndpoint ?. videoId || params . get ( 'v' )
56
+ } ,
57
+ channel : {
58
+ channelId : channel . navigationEndpoint . browseEndpoint . browseId ,
59
+ handle : channel . navigationEndpoint . browseEndpoint . canonicalBaseUrl . split ( '/@' ) [ 1 ] ,
60
+ name : stringifyRuns ( parseMessageRuns ( channel . title . runs ) )
61
+ }
62
+ } )
63
+ } ) ) ;
64
+ } catch ( e ) {
65
+ const videoId = new URLSearchParams ( window . location . search ) . get ( 'v' ) ;
66
+ window . dispatchEvent ( new CustomEvent ( 'videoInfoYtcFilter' , {
67
+ detail : JSON . stringify (
68
+ videoId !== null
69
+ ? {
70
+ video : {
71
+ videoId
72
+ }
71
73
}
72
- }
73
- : null )
74
- } ) ) ;
75
- }
74
+ : null )
75
+ } ) ) ;
76
+ }
76
77
77
- fixLeaks ( ) ;
78
+ fixLeaks ( ) ;
79
+ }
0 commit comments