From 6488411f1d3cc7d2b7a0b863db69d19b329abf2c Mon Sep 17 00:00:00 2001 From: Dreamail Date: Sat, 26 Oct 2024 17:24:22 +0800 Subject: [PATCH] fix autoRefresh --- src/index.tsx | 4 +++- src/projects/welearn/exam/initial.ts | 18 ++++++++------- src/projects/welearn/exercise/initial.ts | 28 +++++++++++++----------- src/projects/welearn/initial.ts | 13 +++++++---- src/projects/welearn/time/initial.ts | 16 ++++++++------ 5 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 4e0f381..fcdcb7d 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,4 +1,4 @@ -import "@src/projects/welearn/initial"; +import { initialWELearn } from "@src/projects/welearn/initial"; import "@icon-park/react/styles/index.css"; import React from "react"; @@ -56,4 +56,6 @@ function initialize() { (async function () { await initialUserSettings(); initialize(); + + initialWELearn(); })(); diff --git a/src/projects/welearn/exam/initial.ts b/src/projects/welearn/exam/initial.ts index afd8cdd..52ed0bc 100644 --- a/src/projects/welearn/exam/initial.ts +++ b/src/projects/welearn/exam/initial.ts @@ -72,13 +72,15 @@ function notify() { } } -if (location.href.includes(".sflep.com/test/") || location.href.includes("wetest.sflep.com/Test")) { - // iife不允许顶层await - (async () => { - await watcher(); - })(); -} +export async function initialExam() { + if (location.href.includes(".sflep.com/test/") || location.href.includes("wetest.sflep.com/Test")) { + // iife不允许顶层await + (async () => { + await watcher(); + })(); + } -if (location.href.includes(".sflep.com/student/course_info.aspx?")) { - WELearnAPI.upload(); + if (location.href.includes(".sflep.com/student/course_info.aspx?")) { + WELearnAPI.upload(); + } } diff --git a/src/projects/welearn/exercise/initial.ts b/src/projects/welearn/exercise/initial.ts index 4bcbb39..c6a9bee 100644 --- a/src/projects/welearn/exercise/initial.ts +++ b/src/projects/welearn/exercise/initial.ts @@ -2,21 +2,23 @@ import logger from "@/src/utils/logger"; import { store } from "@store"; import { determineCourseType, initialCourseCatalog } from "./main"; -if (location.href.includes("centercourseware.sflep.com")) { - let bufferUrl = ""; +export async function initialExercise() { + if (location.href.includes("centercourseware.sflep.com")) { + let bufferUrl = ""; - function watcher() { - let currentUrl = location.href; - logger.debug(currentUrl); + function watcher() { + let currentUrl = location.href; + logger.debug(currentUrl); - if (currentUrl != bufferUrl) { - store.clearLogs(); - determineCourseType(currentUrl); + if (currentUrl != bufferUrl) { + store.clearLogs(); + determineCourseType(currentUrl); + } + bufferUrl = currentUrl; } - bufferUrl = currentUrl; - } - // 页面刷新时,会自动销毁,所以这里不主动处理也没啥问题 - setInterval(watcher, 200); - initialCourseCatalog(); + // 页面刷新时,会自动销毁,所以这里不主动处理也没啥问题 + setInterval(watcher, 200); + initialCourseCatalog(); + } } diff --git a/src/projects/welearn/initial.ts b/src/projects/welearn/initial.ts index 10a5229..eb89e28 100644 --- a/src/projects/welearn/initial.ts +++ b/src/projects/welearn/initial.ts @@ -1,8 +1,13 @@ // 在此处注册(直接调用)各个插件中,app初始化时要执行的函数 -import "./exam/initial"; -import "./exercise/initial"; -import "./time/initial"; +import { initialExam } from "./exam/initial"; +import { initialExercise } from "./exercise/initial"; +import { initialTime } from "./time/initial"; import { WELearnAPI } from "@/src/api/welearn"; -WELearnAPI.checkVersion(); +export async function initialWELearn() { + WELearnAPI.checkVersion(); + initialExam(); + initialExercise(); + initialTime(); +} \ No newline at end of file diff --git a/src/projects/welearn/time/initial.ts b/src/projects/welearn/time/initial.ts index 1f09a11..b612545 100644 --- a/src/projects/welearn/time/initial.ts +++ b/src/projects/welearn/time/initial.ts @@ -1,9 +1,11 @@ import { autoRefresh } from "./main"; -//切换页面的按钮在外部,而不是在iframe内 -if ( - location.href.includes(".sflep.com/student/StudyCourse.aspx?") || - location.href.includes(".sflep.com/Course/TryCourse.aspx?") -) { - autoRefresh(); -} +export async function initialTime() { + //切换页面的按钮在外部,而不是在iframe内 + if ( + location.href.includes(".sflep.com/student/StudyCourse.aspx?") || + location.href.includes(".sflep.com/Course/TryCourse.aspx?") + ) { + autoRefresh(); + } +} \ No newline at end of file