MCPcopy
hub / github.com/ocsjs/ocsjs / smartExam

Function smartExam

packages/scripts/src/projects/zhs.ts:3042–3204  ·  view source on GitHub ↗
(
	remotePage: RemotePage | undefined,
	{ answererWrappers, period, thread, answerSeparators }: CommonWorkOptions
)

Source from the content-addressed store, hash-verified

3040}
3041
3042function smartExam(
3043 remotePage: RemotePage | undefined,
3044 { answererWrappers, period, thread, answerSeparators }: CommonWorkOptions
3045) {
3046 $message.info({ content: '开始作业' });
3047 $message.warn({
3048 content: '⚠️ 答题中请勿进行任何操作,如需暂停答题,请等待全部题目搜索完成并执行自动保存功能后才能操作。',
3049 duration: 0,
3050 closeable: false
3051 });
3052
3053 CommonProject.scripts.workResults.methods.init();
3054
3055 const titleTransform = (titles: (HTMLElement | undefined)[]) => {
3056 return titles
3057 .filter((t) => t?.innerText)
3058 .map((t) => (t ? optimizationElementWithImage(t).innerText : ''))
3059 .join(',');
3060 };
3061
3062 const workResults: SimplifyWorkResult[] = [];
3063 let totalQuestionCount = 0;
3064 let requestedCount = 0;
3065 let resolvedCount = 0;
3066
3067 const worker = new OCSWorker({
3068 root: '.question-area-content',
3069 elements: {
3070 type: 'div.flex.items-center.mb-\\[16px\\]',
3071 title: 'div.flex-1 .mb-\\[32px\\] .text-mainText.font-medium',
3072 options: 'label.user-select.group,div.real-editor'
3073 },
3074 thread: thread ?? 1,
3075 answerSeparators: answerSeparators.split(',').map((s) => s.trim()),
3076 /** 默认搜题方法构造器 */
3077 answerer: (elements, ctx) => {
3078 const title = titleTransform(elements.title);
3079 if (title) {
3080 return CommonProject.scripts.apps.methods.searchAnswerInCaches(title, async () => {
3081 await $.sleep((period ?? 3) * 1000);
3082 return defaultAnswerWrapperHandler(answererWrappers, {
3083 type: ctx.type || 'unknown',
3084 title,
3085 options: ctx.elements.options.map((o) => o.innerText).join('\n')
3086 });
3087 });
3088 } else {
3089 throw new Error('题目为空,请查看题目是否为空,或者忽略此题');
3090 }
3091 },
3092 work: {
3093 type(ctx) {
3094 const type = ctx.elements.type[0].textContent;
3095 if (type?.includes('单选')) {
3096 return 'single';
3097 } else if (type?.includes('多选题')) {
3098 return 'multiple';
3099 } else if (type?.includes('判断')) {

Callers 1

methodsFunction · 0.85

Calls 5

doWorkMethod · 0.95
titleTransformFunction · 0.70
getNextBtnFunction · 0.70
initMethod · 0.65

Tested by

no test coverage detected