import { WaitForScript } from "@pioneerjs/core" ; import { ScriptTask } from "../../../electron/task/script.task" ; import { Course } from "../../../types/script/course" ; import { StoreGet } from "../../../types/setting" ; import { waitForNavigation , waitForClickAndNavigation } from "../utils" ; param script returns export function ZHSScript ( course ) { return ScriptTask . createScript ( { name : "超星刷课任务" , target : function ( { task , script } ) { return new Promise ( async ( resolve , reject ) => { const { page } = script ; const waitFor = new WaitForScript ( script ) ; await waitFor . nextTick ( "requestfinished" ) ; await waitFor . documentReady ( ) ; await page . evaluate ( ( ) => { ( document . querySelector ( ".next-btn" ) as HTMLDivElement ) ?. click ( ) ; ( document . querySelector ( ".next-btn" ) as HTMLDivElement ) ?. click ( ) ; } ) ; if ( course . url ) await waitForNavigation ( script , course . url ) ; else if ( course . selector ) { await waitForClickAndNavigation ( script , course . selector ) ; } else { throw new Error ( "脚本运行失败: 课程链接或课程元素为空，请重新获取课程!" ) ; } await waitFor . nextTick ( "requestfinished" ) ; await page . evaluate ( ( ) => { ( document . querySelector ( ".v-modal" ) as HTMLDivElement ) ?. remove ( ) ; ( Array . from ( document . querySelectorAll ( ".el-dialog__wrapper,.dialog" ) ) as HTMLDivElement [ ] ) . forEach ( ( e ) => { e ?. remove ( ) ; } ) ; } ) ; await waitFor . sleep ( 5000 ) ; const zhsSetting = StoreGet ( "setting" ) . script . script . zhs ; if ( ! zhsSetting . video . enable ) { resolve ( ) ; return ; } else { const li = await page . evaluate ( ( ) => { return Array . from ( document . querySelectorAll ( "li.clearfix.video" ) ) . filter ( ( el ) => el . querySelector ( ".time_icofinish" ) === null ) as HTMLLIElement [ ] ; } ) ; if ( li . length === 0 ) { resolve ( ) ; task . process ( "无任务点，即将跳转下个任务" ) ; return ; } } setTimeout ( ( ) => { resolve ( ) ; task . process ( "定时关闭已完成" ) ; } , zhsSetting . autoStop * 60 * 60 * 1000 ) ; task . process ( "正在自动播放视频" ) ; await page . evaluate ( ( autoStop , playbackRate , mute ) => { return new Promise < void > ( ( resolve , reject ) => { const $ = ( window as any ) . $ ; setTimeout ( function ( ) { window . location . href = "https://onlineweb.zhihuishu.com/" ; resolve ( ) ; } , autoStop * 60 * 60 * 1000 ) ; setTimeout ( ( ) => { start ( "li.clearfix.video" , ".time_icofinish" ) ; } , 3000 ) ; function start ( all_li , with_out ) { console . log ( "开始自动播放视频" , arguments ) ; callback ( ) ; function callback ( ) { let list = getList ( ) ; if ( list . length === 0 ) { resolve ( ) ; return ; } else { list [ 0 ] . click ( ) ; setTimeout ( ( ) => { const v = document . querySelector ( "video" ) ; if ( v ) { Player ( v , callback ) ; } else { callback ( ) ; } } , 3000 ) ; } } function Player ( video , callback ) { video . playbackRate = playbackRate ; video . muted = mute ; video . onpause = function ( ) { if ( ! video . ended ) { video . play ( ) ; } } ; video . onended = function ( ) { callback ( ) ; } ; video . play ( ) ; } function getList ( ) { return Array . from ( document . querySelectorAll ( all_li ) ) . filter ( ( el ) => el . querySelector ( with_out ) === null ) as HTMLLIElement [ ] ; } setInterval ( function ( ) { if ( $ ( ".speedBox" ) . find ( "span" ) . text ( ) == "X 1.0" ) $ ( ".speedTab15" ) . click ( ) ; if ( $ ( ".topic-item" ) . length != 0 ) { setTimeout ( "$('.topic-item').eq(0).click();" , 500 ) ; setTimeout ( "$('div.btn').eq(0).click();" , 1000 ) ; } } , 2000 ) ; } } ) ; } , zhsSetting . autoStop , zhsSetting . video . playbackRate , zhsSetting . video . mute ) ; } ) ; } , } ) ; }