MCPcopy
hub / github.com/ocsjs/ocsjs / job

Function job

packages/scripts/src/projects/unipus/exploration.ts:193–790  ·  view source on GitHub ↗
(cfg: typeof UnipusExplorationScript.cfg, rp: RemotePage)

Source from the content-addressed store, hash-verified

191});
192
193async function job(cfg: typeof UnipusExplorationScript.cfg, rp: RemotePage) {
194 const wrap = await waitForElement('.question-wrap', { check_period_ms: 3000 });
195 const wrap_content = wrap?.childNodes[0] as HTMLElement;
196 const canRun = () => !!wrap_content?.isConnected;
197 await waitFor(() => state.starting);
198
199 const matches = (...selectors: string[]) => {
200 return selectors.every((selector) => {
201 return !!document.querySelector(selector);
202 });
203 };
204
205 await (async () => {
206 if (!wrap_content) {
207 $msg.error('未找到任务内容区域,跳过该任务');
208 return;
209 }
210
211 if (matches('.unipus-upload-container')) {
212 $msg.info('检测到上传任务,请自行手动完成,即将跳过');
213 return;
214 }
215
216 if (matches('.question-wrap [class*=bgimg] [class*=picture]')) {
217 $msg.info('检测到图片任务,即将跳过');
218 return;
219 }
220
221 // 不支持图片题
222 if (matches('.layout-material-container .component-htmlview img')) {
223 $msg.error('检测到题目中包含图片,暂时无法处理,即将跳过该任务');
224 return;
225 }
226
227 if (matches('.question-wrap .video-box')) {
228 $msg.info('检测到视频任务,即将播放');
229 const media = await waitForMedia();
230 if (!media) {
231 $msg.error('未找到视频,即将跳过该任务');
232 return;
233 }
234 if (!cfg.enable_media) {
235 $msg.warn('视频/音频任务已关闭,即将跳过该任务');
236 return;
237 }
238
239 media.currentTime = 0;
240 media.volume = cfg.volume;
241 media.playbackRate = cfg.playbackRate;
242 return await new Promise<void>((resolve, reject) => {
243 playMedia(() => media.play())
244 .then(() => {
245 state.current_media = media;
246 media.volume = cfg.volume;
247 media.playbackRate = cfg.playbackRate;
248 media.addEventListener('pause', async () => {
249 if (!canRun()) return;
250 // 视频弹窗检测

Callers 1

oncompleteFunction · 0.85

Calls 15

waitForElementFunction · 0.90
waitForMediaFunction · 0.90
playMediaFunction · 0.90
canRunFunction · 0.85
checkUniTestIsDoneFunction · 0.85
doUnderstandingTextFunction · 0.85
doReadingFunction · 0.85
doChoiceFunction · 0.85
doCompletionFunction · 0.85
resoleInputWrapLinesFunction · 0.85
singleQuestionHandleFunction · 0.85
checkOrderFunction · 0.85

Tested by

no test coverage detected