Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -56,4 +56,6 @@ function initialize() {
(async function () {
await initialUserSettings();
initialize();

initialWELearn();
})();
18 changes: 10 additions & 8 deletions src/projects/welearn/exam/initial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
28 changes: 15 additions & 13 deletions src/projects/welearn/exercise/initial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
13 changes: 9 additions & 4 deletions src/projects/welearn/initial.ts
Original file line number Diff line number Diff line change
@@ -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();
}
16 changes: 9 additions & 7 deletions src/projects/welearn/time/initial.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}