import { WaitForScript } from "@pioneerjs/core" ; import { log } from "electron-log" ; import { Frame , HTTPRequest , Page } from "puppeteer-core" ; import { AxiosGet } from "../../../../electron/axios" ; import { sleep } from "../../../common/utils" ; import { LoginScript } from "../../../login/types" ; import { waitForNavigation } from "../../utils" ; export function CXRequestScriptHook ( page ) { page . setRequestInterception ( true ) ; page . on ( "request" , async ( req ) => { await requestHook ( req , "videojs" , ( body ) => { console . log ( "超星视频脚本拦截" ) ; return ( body . replace ( "mouseout" , "" ) . replace ( "ratechange" , "" ) . replace ( "[1, 1.25, 1.5, 2]" , "[1, 1.25, 1.5, 2,4,8,16]" ) . replace ( "f.on('play'" , "f.on('ended',()=>h('log'))\nf.on('play'" ) ) ; } ) ; await requestHook ( req , "doHomeWorkNew" , ( body ) => { console . log ( "禁止弹窗开启" ) ; return body . replace ( /alert/g , "console.log" ) ; } ) ; } ) ; } param req param regexp param transform export async function requestHook ( req , regexp , transform ) { if ( req . response ( ) ) { return ; } const url = req . url ( ) ; if ( RegExp ( regexp ) . test ( url ) ) { const { data } = await AxiosGet ( url ) ; const transformData = transform ( data ) ; await req . respond ( { status : 200 , body : transformData , } ) ; } else { await req . continue ( ) ; } }