Skip to content

Commit

Permalink
feat(core): 新增超星强制答题功能
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed May 17, 2022
1 parent 64c5578 commit e7c4fc0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
18 changes: 10 additions & 8 deletions packages/core/src/components/cx/StudySettingPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,21 @@ export const StudySettingPanel = defineComponent({
class="input-switch"
type="checkbox"
checked={settings.restudy}
onChange={(e: any) => {
settings.restudy = e.target.checked;
}}
onChange={(e: any) => (settings.restudy = e.target.checked)}
/>
</Tooltip>
</div>

<label>启动任务点</label>
<label>强制答题</label>
<div>
PPT<input type='checkbox' />
音视频<input type='checkbox' />
阅读<input type='checkbox' />
章节测试<input type='checkbox' />
<Tooltip title="当章节测试不是任务点时,强制自动答题。\n(左上角有黄点的代表此小节是任务点)\n(一般来说不是任务点的章节测试是不计分的)">
<input
class="input-switch"
type="checkbox"
checked={settings.forceWork}
onChange={(e: any) => (settings.forceWork = e.target.checked)}
/>
</Tooltip>
</div>
<hr />
<hr />
Expand Down
15 changes: 9 additions & 6 deletions packages/core/src/script/cx/study.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,25 @@ export async function study(setting: ScriptSettings['cx']['video']) {
function searchTask(setting: ScriptSettings['cx']['video']): (() => Promise<void> | undefined)[] {
return searchIFrame(document)
.map((frame) => {
const { media, ppt, chapterTest } = domSearch(
const { media, read, chapterTest } = domSearch(
{
media: 'video,audio',
chapterTest: '.TiMu',
ppt: '#img.imglook'
read: '#img.imglook'
},
frame.contentDocument || document
);

function getJob() {
return media
? mediaTask(setting, media as any, frame)
: ppt
? pptTask(frame)
: read
? readTask(frame)
: chapterTest
? chapterTestTask(store.setting.cx.work, frame)
: undefined;
}
if (media || ppt || chapterTest) {
if (media || read || chapterTest) {
return () => {
// @ts-ignore
let _parent = frame.contentWindow;
Expand All @@ -102,6 +102,9 @@ function searchTask(setting: ScriptSettings['cx']['video']): (() => Promise<void
} else if (attachments[jobIndex]?.job === true) {
logger('debug', jobName, '即将开始。');
return getJob();
} else if (chapterTest && setting.forceWork) {
logger('debug', jobName, '开启强制答题。');
return getJob();
} else {
logger('debug', jobName, '已经完成,即将跳过。');
break;
Expand Down Expand Up @@ -210,7 +213,7 @@ function mediaTask(setting: ScriptSettings['cx']['video'], media: HTMLMediaEleme
/**
* 阅读 ppt
*/
async function pptTask(frame?: HTMLIFrameElement) {
async function readTask(frame?: HTMLIFrameElement) {
// @ts-ignore
const finishJob = frame?.contentWindow?.finishJob;
if (finishJob) finishJob();
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface CXSetting {
playlines: string[]
/** 播放路线 */
line: string
/** 强制答题 */
forceWork: boolean,
}
work: CommonWorkSetting
exam: CommonWorkSetting
Expand Down Expand Up @@ -101,7 +103,8 @@ export const defaultOCSSetting: ScriptSettings = {
volume: 0,
upload: 'close',
playlines: ['公网1', '公网2'],
line: '公网1'
line: '公网1',
forceWork: false
},
work: defaultWorkSetting,
exam: defaultWorkSetting
Expand Down

0 comments on commit e7c4fc0

Please sign in to comment.