* 共享课的作业和考试
(
workInfo: any,
{ answererWrappers, period, thread, stopSecondWhenFinish, redundanceWordsText, answerSeparators }: CommonWorkOptions
)
| 2591 | * 共享课的作业和考试 |
| 2592 | */ |
| 2593 | function gxkWorkAndExam( |
| 2594 | workInfo: any, |
| 2595 | { answererWrappers, period, thread, stopSecondWhenFinish, redundanceWordsText, answerSeparators }: CommonWorkOptions |
| 2596 | ) { |
| 2597 | CommonProject.scripts.workResults.methods.init({ |
| 2598 | questionPositionSyncHandlerType: 'zhs-gxk' |
| 2599 | }); |
| 2600 | |
| 2601 | /** |
| 2602 | * workExamParts 是个列表 |
| 2603 | * 里面包括一个题目类型的列表,第一个是单选,第二个是多选,第三个是判断 |
| 2604 | * 所以这里直接扁平化数组方便处理 |
| 2605 | */ |
| 2606 | const allExamParts = |
| 2607 | ((workInfo?.rt?.examBase?.workExamParts as any[]) || [])?.map((p) => p.questionDtos).flat() || []; |
| 2608 | |
| 2609 | const titleTransform = (_: any, index: number) => { |
| 2610 | const div = h('div'); |
| 2611 | |
| 2612 | div.innerHTML = allExamParts[index]?.name || '题目读取失败'; |
| 2613 | return removeRedundantWords( |
| 2614 | optimizationElementWithImage(div, true).innerText || '', |
| 2615 | redundanceWordsText.split('\n') |
| 2616 | ); |
| 2617 | }; |
| 2618 | let request_index = 0; |
| 2619 | /** 新建答题器 */ |
| 2620 | const worker = new OCSWorker({ |
| 2621 | root: '.examPaper_subject', |
| 2622 | elements: { |
| 2623 | /** |
| 2624 | * .subject_describe > div: 选择题题目 |
| 2625 | * .smallStem_describe > div:nth-child(2): 阅读理解小题题目 |
| 2626 | */ |
| 2627 | title: '.subject_describe > div,.smallStem_describe > div:nth-child(2)', |
| 2628 | // 选项中图片识别 |
| 2629 | options: (root) => |
| 2630 | $$el('.subject_node .nodeLab', root).map((t) => { |
| 2631 | for (const img of Array.from(t.querySelectorAll<HTMLImageElement>('.node_detail img'))) { |
| 2632 | // zhs选项中如果已显示的图片则不存在 data-src,如果未显示则存在 data-src |
| 2633 | if (img.dataset.src) { |
| 2634 | img.src = img.dataset.src; |
| 2635 | } |
| 2636 | // 不使用 optimizationElementWithImage 是因为zhs的选项按钮也是一个图片 |
| 2637 | createUnVisibleTextOfImage(img); |
| 2638 | } |
| 2639 | return t; |
| 2640 | }) |
| 2641 | }, |
| 2642 | thread: thread ?? 1, |
| 2643 | answerSeparators: answerSeparators.split(',').map((s) => s.trim()), |
| 2644 | /** 默认搜题方法构造器 */ |
| 2645 | answerer: (elements, ctx) => { |
| 2646 | const title = titleTransform(undefined, request_index++); |
| 2647 | if (title) { |
| 2648 | return CommonProject.scripts.apps.methods.searchAnswerInCaches(title, async () => { |
| 2649 | await $.sleep((period ?? 3) * 1000); |
| 2650 | return defaultAnswerWrapperHandler(answererWrappers, { |
no test coverage detected