Skip to content

Commit

Permalink
fix(core): 修复智慧树倍速失效的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed May 31, 2022
1 parent 1702aa9 commit 7943442
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@
"path": "./node_modules/cz-conventional-changelog"
}
}
}
}
2 changes: 1 addition & 1 deletion packages/core/src/script/zhs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const ZHSScript = defineScript({
settings.creditStudy = true;
// 智慧树视频学习
logger('info', '开始智慧树学分课视频学习');
await creditStudy(settings);
await creditStudy();
}
},

Expand Down
31 changes: 16 additions & 15 deletions packages/core/src/script/zhs/study.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { domSearch, domSearchAll, sleep } from '../../core/utils';
import { logger } from '../../logger';
import { message } from '../../main';
import { ScriptSettings } from '../../scripts';
import { useContext, useSettings } from '../../store';

let stop = false;

/**
* zhs 视频学习
*/
export async function study(setting?: ScriptSettings['zhs']['video']) {
const { watchTime = 30, restudy = false } = setting || {};
export async function study() {
const { watchTime, restudy } = useSettings().zhs.video;
logger('info', 'zhs 学习任务开始');
/** 查找任务 */
let list: HTMLLIElement[] = Array.from(document.querySelectorAll('li.clearfix.video'));
Expand All @@ -30,7 +29,11 @@ export async function study(setting?: ScriptSettings['zhs']['video']) {
/**
* 实时监测,关闭弹窗测验
*/
setInterval(() => closeTestDialog(), 3000);
setInterval(() => {
const { showProgress } = useSettings().zhs.video;
closeTestDialog();
fixedVideoProgress(showProgress);
}, 3000);

/**
* 到达学习时间后,自动关闭
Expand All @@ -50,7 +53,7 @@ export async function study(setting?: ScriptSettings['zhs']['video']) {
);
item.click();
await sleep(5000);
await watch(setting);
await watch();
}
} catch (e) {
logger('error', e);
Expand All @@ -66,8 +69,9 @@ export async function study(setting?: ScriptSettings['zhs']['video']) {
* @param setting
* @returns
*/
export async function watch(setting?: Pick<ScriptSettings['zhs']['video'], 'playbackRate' | 'volume'>) {
const { volume = 0, playbackRate = 1 } = setting || {};
export async function watch() {
const { volume, playbackRate, creditStudy } = useSettings().zhs.video;

return new Promise<void>((resolve, reject) => {
try {
const video = document.querySelector('video') as HTMLVideoElement;
Expand All @@ -86,8 +90,8 @@ export async function watch(setting?: Pick<ScriptSettings['zhs']['video'], 'play
await sleep(1000);

video.play();

await switchPlaybackRate(playbackRate);
// 设置播放速度
await switchPlaybackRate(creditStudy ? 1 : playbackRate);

video.onpause = function () {
if (!video.ended) {
Expand Down Expand Up @@ -142,8 +146,8 @@ export async function closeTestDialog() {
}

/** 校内学分课 */
export async function creditStudy(setting?: ScriptSettings['zhs']['video']) {
const { restudy = false } = setting || {};
export async function creditStudy() {
const { restudy } = useSettings().zhs.video;

/** 查找任务 */
let list: HTMLLIElement[] = Array.from(document.querySelectorAll('.file-item'));
Expand All @@ -158,10 +162,7 @@ export async function creditStudy(setting?: ScriptSettings['zhs']['video']) {
const item = list[0];
if (item) {
if (item.classList.contains('active')) {
await watch({
volume: setting?.volume || 0,
playbackRate: 1
});
await watch();
/** 下一章 */
if (list[1]) list[1].click();
} else {
Expand Down

0 comments on commit 7943442

Please sign in to comment.