MCPcopy
hub / github.com/ocsjs/ocsjs / updateState

Function updateState

packages/scripts/src/projects/common.ts:761–840  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

759
760 // 更新题库状态
761 const updateState = async () => {
762 // 清空元素
763 tableContainer.replaceChildren();
764 errorSolveGuide.style.display = 'none';
765 let loadedCount = 0;
766
767 if (this.cfg.answererWrappers.length) {
768 refresh.style.display = 'block';
769 tableContainer.style.display = 'block';
770 refresh.textContent = '🚫正在加载题库状态...';
771 refresh.setAttribute('disabled', 'true');
772
773 const table = h('table');
774 table.style.width = '100%';
775 this.cfg.answererWrappers.forEach(async (item) => {
776 const t = Date.now();
777 let success = false;
778 let error;
779 const isDisabled = this.cfg.disabledAnswererWrapperNames.find((name) => name === item.name);
780
781 const res = isDisabled
782 ? false
783 : await Promise.race([
784 (async () => {
785 try {
786 return await request(new URL(item.url).origin + '/?t=' + t, {
787 type: 'GM_xmlhttpRequest',
788 method: 'head',
789 responseType: 'text'
790 });
791 } catch (err) {
792 error = err;
793 return false;
794 }
795 })(),
796 (async () => {
797 await $.sleep(10 * 1000);
798 return false;
799 })()
800 ]);
801 if (typeof res === 'string') {
802 success = true;
803 } else {
804 success = false;
805 }
806
807 if (error) {
808 errorSolveGuide.style.display = 'block';
809 }
810
811 const body = h('tbody');
812 body.append(h('td', item.name));
813 body.append(
814 h('td', [
815 $ui.tooltip(
816 h(
817 'span',
818 { title: isDisabled ? '题目已经被停用,请在上方题库配置中点击开启。' : '' },

Callers 1

onrenderFunction · 0.85

Calls 1

requestFunction · 0.90

Tested by

no test coverage detected