MCPcopy
hub / github.com/ocsjs/ocsjs / hikeWork

Function hikeWork

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

Source from the content-addressed store, hash-verified

3325}
3326
3327function hikeWork(
3328 remotePage: RemotePage | undefined,
3329 { answererWrappers, period, thread, answerSeparators }: CommonWorkOptions
3330) {
3331 $message.info({ content: '开始作业' });
3332
3333 CommonProject.scripts.workResults.methods.init({
3334 questionPositionSyncHandlerType: 'zhs-hike'
3335 });
3336
3337 const titleTransform = (titles: (HTMLElement | undefined)[]) => {
3338 return titles
3339 .filter((t) => t?.innerText)
3340 .map((t) => (t ? optimizationElementWithImage(t).innerText : ''))
3341 .join(',');
3342 };
3343
3344 const worker = new OCSWorker({
3345 root: '.q_main',
3346 elements: {
3347 type: '.question_score',
3348 title: '.question-topic',
3349 options: 'label'
3350 },
3351 thread: thread ?? 1,
3352 answerSeparators: answerSeparators.split(',').map((s) => s.trim()),
3353 /** 默认搜题方法构造器 */
3354 answerer: (elements, ctx) => {
3355 const title = titleTransform(elements.title);
3356 if (title) {
3357 return CommonProject.scripts.apps.methods.searchAnswerInCaches(title, async () => {
3358 await $.sleep((period ?? 3) * 1000);
3359 return defaultAnswerWrapperHandler(answererWrappers, {
3360 type: ctx.type || 'unknown',
3361 title,
3362 options: ctx.elements.options.map((o) => o.innerText).join('\n')
3363 });
3364 });
3365 } else {
3366 throw new Error('题目为空,请查看题目是否为空,或者忽略此题');
3367 }
3368 },
3369 work: {
3370 type(ctx) {
3371 const type = ctx.elements.type[0].textContent;
3372 if (type?.includes('单选题')) {
3373 return 'single';
3374 } else if (type?.includes('多选题')) {
3375 return 'multiple';
3376 } else if (type?.includes('判断题')) {
3377 return 'judgement';
3378 } else if (type?.includes('填空题')) {
3379 return 'completion';
3380 } else {
3381 return undefined;
3382 }
3383 },
3384 /** 自定义处理器 */

Callers 1

oncompleteFunction · 0.85

Calls 5

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

Tested by

no test coverage detected