({ answererWrappers, period, thread, answerSeparators }: CommonWorkOptions)
| 945 | } |
| 946 | |
| 947 | function aiWork({ answererWrappers, period, thread, answerSeparators }: CommonWorkOptions) { |
| 948 | $message.info('开始作业'); |
| 949 | CommonProject.scripts.workResults.methods.init(); |
| 950 | |
| 951 | console.log({ answererWrappers, period, thread }); |
| 952 | |
| 953 | const titleTransform = (titles: (HTMLElement | undefined)[]) => { |
| 954 | return titles |
| 955 | .filter((t) => t?.innerText || t?.querySelector('img')) |
| 956 | .map((t) => { |
| 957 | if (t) { |
| 958 | const el = optimizationElementWithImage(t, true); |
| 959 | // 使用 textContent 而非 innerText,因为 innerText 受 CSS 影响, |
| 960 | // fontSize: 0px 的隐藏 span 中的图片 URL 不会被 innerText 获取 |
| 961 | return (el.textContent || '').replace(/\s+/g, ' ').trim() || ''; |
| 962 | } |
| 963 | return ''; |
| 964 | }) |
| 965 | .join(','); |
| 966 | }; |
| 967 | |
| 968 | const workResults: SimplifyWorkResult[] = []; |
| 969 | let totalQuestionCount = 0; |
| 970 | let requestedCount = 0; |
| 971 | let resolvedCount = 0; |
| 972 | |
| 973 | function getType(options: HTMLElement[]) { |
| 974 | const radio_len = options |
| 975 | .map((o) => o.querySelector('[type="radio"]')) |
| 976 | .reduce((a, b) => { |
| 977 | return a + (b ? 1 : 0); |
| 978 | }, 0); |
| 979 | |
| 980 | return radio_len > 0 |
| 981 | ? radio_len === 2 |
| 982 | ? 'judgement' |
| 983 | : 'single' |
| 984 | : options.some((o) => o.querySelector('[type="checkbox"]')) |
| 985 | ? 'multiple' |
| 986 | : options.some((o) => o.querySelector('textarea')) || options.some((o) => o.classList.contains('ivu-input')) |
| 987 | ? 'completion' |
| 988 | : options.some((o) => o.querySelector('.fillblank_input input')) |
| 989 | ? 'fill-blank' |
| 990 | : undefined; |
| 991 | } |
| 992 | |
| 993 | const worker = new OCSWorker({ |
| 994 | root: '.content-item', |
| 995 | elements: { |
| 996 | title: '.questions-content [class*=title-content]', |
| 997 | options: 'label[class*=group-item],.ivu-input-wrapper input' |
| 998 | }, |
| 999 | thread: thread ?? 1, |
| 1000 | answerSeparators: answerSeparators.split(',').map((s) => s.trim()), |
| 1001 | /** 默认搜题方法构造器 */ |
| 1002 | answerer: (elements, ctx) => { |
| 1003 | const title = titleTransform(elements.title); |
| 1004 | if (title) { |
nothing calls this directly
no test coverage detected