Skip to content

Commit

Permalink
feat(script): 修复超星人脸验证时疯狂刷新的问题,新增超星人脸验证通知功能
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Dec 19, 2023
1 parent 4681e93 commit e75786c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/scripts/src/projects/cx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ export const CXProject = Project.create({
},
defaultValue: true
},
notifyWhenHasFaceRecognition: {
label: '当有人脸验证时通知我',
attrs: {
type: 'checkbox'
},
defaultValue: true
},
/**
*
* 开启的任务点
Expand Down Expand Up @@ -1303,6 +1310,7 @@ async function mediaTask(
*/
await new Promise<void>((resolve, reject) => {
const playFunction = async () => {
await waitForFaceRecognition();
if (!media.ended) {
await $.sleep(1000);
media.play();
Expand Down Expand Up @@ -1662,3 +1670,28 @@ async function readerAndFillHandle(searchInfos: SearchInformation[], list: HTMLE

return { finish: false };
}

function waitForFaceRecognition() {
let notified = false;

return new Promise<void>((resolve) => {
const interval = setInterval(() => {
const face = $el('#fcqrimg', top?.document);
if (face) {
if (!notified) {
notified = true;
if (CXProject.scripts.study.cfg.notifyWhenHasFaceRecognition) {
CommonProject.scripts.settings.methods.notificationBySetting(
'检测到人脸识别,请手动进行识别后脚本才会继续运行。',
{ duration: 0 }
);
}
$console.warn('检测到人脸识别,请手动进行识别后脚本才会继续运行。');
}
} else {
clearInterval(interval);
resolve();
}
}, 3000);
});
}

0 comments on commit e75786c

Please sign in to comment.