MCPcopy
hub / github.com/ocsjs/ocsjs / study

Function study

packages/scripts/src/projects/cx.ts:1287–1450  ·  view source on GitHub ↗
(
	opts: typeof CXProject.scripts.study.cfg & {
		workOptions: CommonWorkOptions;
	}
)

Source from the content-addressed store, hash-verified

1285 * cx 任务学习
1286 */
1287export async function study(
1288 opts: typeof CXProject.scripts.study.cfg & {
1289 workOptions: CommonWorkOptions;
1290 }
1291) {
1292 await $.sleep(3000);
1293
1294 const searchedJobs: Job[] = [];
1295
1296 let searching = true;
1297
1298 let attachmentCount: number = $gm.unsafeWindow.attachments?.length || 0;
1299
1300 const wait_timeout = 3 + attachmentCount * 2;
1301
1302 /** 考虑到网速级慢的同学,所以10秒后如果还没有任务点才停止 */
1303 setTimeout(() => {
1304 searching = false;
1305 }, Math.min(wait_timeout, 10) * 1000);
1306
1307 /**
1308 * 递归运行任务点,一旦有新的任务点被检测到直接开始
1309 * 如果10秒内既没有任务点,也暂停了搜索,则当前则没有任务点
1310 */
1311 const runJobs = async () => {
1312 const job = searchJob(opts, searchedJobs);
1313 // 如果存在任务点
1314 if (job && job.func) {
1315 try {
1316 await job.func();
1317 } catch (e) {
1318 $console.error('未知错误', e);
1319 }
1320
1321 await $.sleep(1000);
1322 await runJobs();
1323 }
1324 // 每次 search 一次,就减少一次文件数量
1325 // 如果不加这个判断,三个任务中,中间的任务不是任务点,则会导致下面的任务全部不执行。
1326 else if (attachmentCount > 0) {
1327 attachmentCount--;
1328 await $.sleep(1000);
1329 await runJobs();
1330 }
1331 // 或者正在搜索
1332 else if (searching) {
1333 await $.sleep(1000);
1334 await runJobs();
1335 }
1336 };
1337
1338 await runJobs();
1339
1340 // @ts-ignore
1341 top._preChapterId = '';
1342
1343 // 下一章
1344 const next = async () => {

Callers 1

onactiveFunction · 0.70

Calls 2

runJobsFunction · 0.85
nextFunction · 0.70

Tested by

no test coverage detected