Skip to content

Commit

Permalink
fix(script): 删除清空答案选项
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Apr 4, 2023
1 parent 1ef4b45 commit 06936a5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 32 deletions.
5 changes: 0 additions & 5 deletions packages/scripts/src/projects/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,6 @@ export const CommonProject = Project.create({
},
defaultValue: 3
},
uncheckAllChoice: {
label: '清空答案',
attrs: { type: 'checkbox', title: '在考试开始前,清空所有已经选择过的答案。' },
defaultValue: false
},
thread: {
label: '线程数量(个)',
attrs: {
Expand Down
36 changes: 14 additions & 22 deletions packages/scripts/src/projects/cx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ export const CXProject = Project.create({

export function workOrExam(
type: 'work' | 'exam' = 'work',
{ answererWrappers, period, upload, thread, uncheckAllChoice, stopSecondWhenFinish }: CommonWorkOptions
{ answererWrappers, period, upload, thread, stopSecondWhenFinish }: CommonWorkOptions
) {
$message('info', { content: `开始${type === 'work' ? '作业' : '考试'}` });

Expand Down Expand Up @@ -571,21 +571,21 @@ export function workOrExam(
return await resolver(searchInfos, elements.options, (type, answer, option) => {
// 如果存在已经选择的选项
if (type === 'judgement' || type === 'single' || type === 'multiple') {
if (option.parentElement && $$el('[class*="check_answer"]', option.parentElement).length === 0) {
if (option?.parentElement && $$el('[class*="check_answer"]', option.parentElement).length === 0) {
option.click();
}
} else if (type === 'completion' && answer.trim()) {
const text = option.querySelector('textarea');
const textareaFrame = option.querySelector('iframe');
const text = option?.querySelector('textarea');
const textareaFrame = option?.querySelector('iframe');
if (text) {
text.value = answer;
}
if (textareaFrame?.contentDocument) {
textareaFrame.contentDocument.body.innerHTML = answer;
}
if (option.parentElement) {
if (option?.parentElement) {
/** 如果存在保存按钮则点击 */
$el('[onclick*=saveQuestion]', option.parentElement)?.click();
$el('[onclick*=saveQuestion]', option?.parentElement)?.click();
}
}
});
Expand Down Expand Up @@ -632,14 +632,6 @@ export function workOrExam(
/** 监听答题结果 */
onResolveUpdate(res) {
CommonProject.scripts.workResults.methods.updateWorkState(worker);
},
async onElementSearched(elements) {
if (uncheckAllChoice) {
for (const el of elements.options) {
el.click();
await $.sleep(200);
}
}
}
});

Expand Down Expand Up @@ -1324,21 +1316,21 @@ async function chapterTestTask(

const handler: DefaultWork<any>['handler'] = (type, answer, option, ctx) => {
if (type === 'judgement' || type === 'single' || type === 'multiple') {
if (option.parentElement?.querySelector('label input')?.getAttribute('checked') === 'checked') {
if (option?.parentElement?.querySelector('label input')?.getAttribute('checked') === 'checked') {
// 跳过
} else {
option.click();
option?.click();
}
} else if (type === 'completion' && answer.trim()) {
const text = option.parentElement?.querySelector('textarea');
const textareaFrame = option.parentElement?.querySelector('iframe');
const text = option?.parentElement?.querySelector('textarea');
const textareaFrame = option?.parentElement?.querySelector('iframe');
if (text) {
text.value = answer;
}
if (textareaFrame?.contentDocument) {
textareaFrame.contentDocument.body.innerHTML = answer;
}
if (option.parentElement) {
if (option?.parentElement) {
/** 如果存在保存按钮则点击 */
$el('[onclick*=saveQuestion]', option.parentElement)?.click();
}
Expand Down Expand Up @@ -1394,16 +1386,16 @@ async function chapterTestTask(

const option = options[Math.floor(Math.random() * options.length)];
// @ts-ignore 随机选择选项
option.parentElement?.querySelector('a,label')?.click();
option?.parentElement?.querySelector('a,label')?.click();
} else if (commonSetting['randomWork-complete'] && type === 'completion') {
$console.log('正在随机作答');

// 随机填写答案
for (const option of options) {
const textarea = option.parentElement?.querySelector('textarea');
const textarea = option?.parentElement?.querySelector('textarea');
const completeTexts = commonSetting['randomWork-completeTexts-textarea'].split('\n').filter(Boolean);
const text = completeTexts[Math.floor(Math.random() * completeTexts.length)];
const textareaFrame = option.parentElement?.querySelector('iframe');
const textareaFrame = option?.parentElement?.querySelector('iframe');

if (text) {
if (textarea) {
Expand Down
6 changes: 3 additions & 3 deletions packages/scripts/src/projects/zhs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ export const ZHSProject = Project.create({
'请大家仔细打开视频上方的”学前必读“,查看成绩分布。',
'如果 “平时成绩-学习习惯成绩” 占比多的话,就需要规律学习。',
'每天定时半小时可获得一分习惯分。',
'如果不想要习惯分可忽略。',
'不要最小化浏览器,可能导致脚本暂停。'
]
'如果不想要习惯分可忽略。'
],
'不要最小化浏览器,可能导致脚本暂停。'
]).outerHTML
},
/** 学习记录 [] */
Expand Down
1 change: 0 additions & 1 deletion packages/scripts/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export interface CommonWorkOptions {
period: number;
thread: number;
upload: WorkUploadType;
uncheckAllChoice: boolean;
answererWrappers: AnswererWrapper[];
stopSecondWhenFinish: number;
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if [ "$isRelease" = "y" ]; then
# 发布
npm publish &&
# 提交
git push origin 4.0
git push origin 4.0 --tags
echo "$version 发布成功"
elif [ "$isRelease" = "n" ]; then
echo "取消发布"
Expand Down

0 comments on commit 06936a5

Please sign in to comment.