MCPcopy
hub / github.com/ocsjs/ocsjs / checkOrder

Function checkOrder

packages/scripts/src/projects/unipus/exploration.ts:675–702  ·  view source on GitHub ↗
(skip_count = 0)

Source from the content-addressed store, hash-verified

673
674 $msg.warn('正在检测连线配对题顺序中...请勿操作');
675 const checkOrder = async (skip_count = 0) => {
676 // 如果发现选项乱序,先摆正顺序
677 const options = queryItems();
678 const option_data: { el: HTMLElement; index: number }[] = [];
679 for (const opt of options) {
680 const text = opt.innerText.trim();
681 const match = text.match(/^([A-Z])\./);
682 if (match) {
683 option_data.push({ el: opt, index: match[1].charCodeAt(0) });
684 }
685 }
686 // 检测顺序是否错误
687 const is_ordered = option_data.every((data, i, arr) => {
688 if (i === 0) return true;
689 return data.index >= arr[i - 1].index;
690 });
691 if (is_ordered) {
692 return;
693 }
694 // 排序,每次移动都会更新dom元素,这里移动一次直接返回 false,知道没有元素可以移动位置
695 // 则代表已经全部排列完成
696 const first = option_data.slice(skip_count).sort((a, b) => b.index - a.index)[0];
697 if (!first) {
698 return;
699 }
700 await moveOption(first.el);
701 await checkOrder(skip_count + 1);
702 };
703 await checkOrder();
704 $msg.info('连线配对题选项已排序完成,开始作答');
705

Callers 1

jobFunction · 0.85

Calls 2

queryItemsFunction · 0.85
moveOptionFunction · 0.85

Tested by

no test coverage detected