1- import { Vista } from '@rxliuli/vista'
2- import { finder } from '@medv/finder'
3- import { interceptEvent } from './event'
1+ import { observe } from '../../lib/filters'
42
53export function nonStop ( ) {
64 Object . defineProperty ( document , 'hidden' , {
@@ -12,57 +10,17 @@ export function nonStop() {
1210 configurable : true ,
1311 } )
1412 document . hasFocus = ( ) => true
15- const observer = new MutationObserver ( ( mutations ) => {
16- mutations . forEach ( ( mutation ) => {
17- mutation . addedNodes . forEach ( ( node ) => {
18- if (
19- node . nodeName === 'YTMUSIC-YOU-THERE-RENDERER' ||
20- ( node instanceof HTMLElement && node . querySelector ( 'ytmusic-you-there-renderer' ) )
21- ) {
22- console . log ( 'Auto-closing "Are you there?" dialog' )
23-
24- setTimeout ( ( ) => {
25- const yesButton = document . querySelector (
26- 'ytmusic-you-there-renderer:not([aria-hidden="true"]) button[aria-label="Yes"]' ,
27- )
28- if ( yesButton instanceof HTMLButtonElement ) {
29- yesButton . click ( )
30- console . log ( 'Clicked "Yes" button' )
31- }
32- } , 100 )
33- }
34- } )
35- } )
36- } )
37- observer . observe ( document . body , {
38- attributes : true ,
39- } )
40- new Vista ( [ interceptEvent ] )
41- . use ( async ( c , next ) => {
42- if (
43- c . event . target instanceof HTMLVideoElement ||
44- c . event . target instanceof HTMLAudioElement ||
45- c . event . target instanceof HTMLImageElement ||
46- c . event . target instanceof XMLHttpRequest ||
47- c . event . target instanceof IDBRequest ||
48- c . event . target instanceof IDBTransaction ||
49- c . event . target instanceof SourceBuffer
50- ) {
51- return await next ( )
13+ observe (
14+ document . body ,
15+ 'ytmusic-you-there-renderer:not([aria-hidden="true"]) button[aria-label="Yes"]' ,
16+ ( [ yesButton ] ) => {
17+ if ( yesButton instanceof HTMLButtonElement ) {
18+ console . log ( 'Auto-closing "Are you there?" dialog via observer' )
19+ setTimeout ( ( ) => {
20+ yesButton . click ( )
21+ console . log ( 'Clicked "Yes" button' )
22+ } , 100 )
5223 }
53- if ( c . event . target === window || c . event . target === document ) {
54- if (
55- [ 'focus' , 'focusin' , 'pageshow' , 'visibilitychange' , 'mouseenter' , 'mouseover' , 'mousemove' ] . includes (
56- c . event . type ,
57- )
58- ) {
59- console . log ( 'Blocked event listener:' , c . event . target , c . event . type )
60- return
61- }
62- }
63-
64- console . log ( 'Event:' , c . event . type , c . event . target instanceof Element ? finder ( c . event . target ) : null )
65- await next ( )
66- } )
67- . intercept ( )
24+ } ,
25+ )
6826}
0 commit comments