/**
 * 本模块负责实现原生脚本拦截模块
 * 这里指的原生脚本是那些非直接写入原生HTML，而是后续由JavaScript添加进DOM的脚本
 * 本模块导入优先级极高
 */ /**
 * 本模块负责实现原生脚本拦截模块
 * 这里指的原生脚本是那些非直接写入原生HTML，而是后续由JavaScript添加进DOM的脚本
 * 本模块导入优先级极高
 */ ( function ( ) { try { class NodeHook { static appendChild = Node . prototype . appendChild ; static insertBefore = Node . prototype . insertBefore ; static rules : [ string [ ] , string | undefined ] [ ] = [ ] ; static jsonp : [ string [ ] , Function ] [ ] = [ ] ; jsonphook = ( url , callback ) => NodeHook . jsonp . push ( [ url , callback ] ) ; removeJsonphook = ( id ) => NodeHook . jsonp . splice ( id - 1 , 1 ) ; constructor ( ) { this . appendChild ( ) ; this . insertBefore ( ) ; } intercept ( rule , replaceURL ? ) { NodeHook . rules . push ( [ rule , replaceURL ] ) ; } appendChild ( ) { Node . prototype . appendChild = function < T extends Node > ( newChild ) : T { newChild . nodeName == 'SCRIPT' && ( < any > newChild ) . src && ( NodeHook . rules . forEach ( d => { d [ 0 ] . every ( d => ( < any > newChild ) . src . includes ( d ) ) && ( d [ 1 ] ? ( ( < any > newChild ) . src = d [ 1 ] ) : ( < any > newChild ) . removeAttribute ( "src" ) ) ; } ) , NodeHook . jsonp . forEach ( d => { d [ 0 ] . every ( d => ( < any > newChild ) . src . includes ( d ) ) && d [ 1 ] ( new Proxy ( new Object ( ) , { set : ( t , p , v ) => { p == "url" && ( ( < any > newChild ) . src = v ) ; return true ; } , get : ( t , p ) => { return p == "url" ? ( < any > newChild ) . src : undefined ; } } ) ) ; } ) ) ; return < T > NodeHook . appendChild . call ( this , newChild ) ; } ; } insertBefore ( ) { Node . prototype . insertBefore = function < T extends Node > ( newChild , refChild ) : T { newChild . nodeName == 'SCRIPT' && ( < any > newChild ) . src && ( NodeHook . rules . forEach ( d => { d [ 0 ] . every ( d => ( < any > newChild ) . src . includes ( d ) ) && ( d [ 1 ] ? ( ( < any > newChild ) . src = d [ 1 ] ) : ( < any > newChild ) . removeAttribute ( "src" ) ) ; } ) , NodeHook . jsonp . forEach ( d => { d [ 0 ] . every ( d => ( < any > newChild ) . src . includes ( d ) ) && d [ 1 ] ( new Proxy ( new Object ( ) , { set : ( t , p , v ) => { p == "url" && ( ( < any > newChild ) . src = v ) ; return true ; } , get : ( t , p ) => { return p == "url" ? ( < any > newChild ) . src : undefined ; } } ) ) ; } ) ) ; return < T > NodeHook . insertBefore . call ( this , newChild , refChild ) ; } ; } } const nodeHook = new NodeHook ( ) ; API . scriptIntercept = ( rule , replaceURL ? ) => nodeHook . intercept ( rule , replaceURL ) ; API . jsonphook = ( url , callback ) => nodeHook . jsonphook ( url , callback ) ; API . removeJsonphook = ( id ) => nodeHook . removeJsonphook ( id ) ; } catch ( e ) { toast . error ( "Node.js" , e ) ; } } ) ( ) ; declare namespace API { param rule param replaceURL function scriptIntercept ( rule , replaceURL ? ) ; param url param callback returns function jsonphook ( url , callback ) ; param id function removeJsonphook ( id ) ; }