From df85677ea5cdb56d24a32fb196520bf83a1b4084 Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 27 Jun 2022 20:14:40 +0800 Subject: [PATCH] ui: simplify --- .../ui-default/pages/problem_detail.page.jsx | 48 +++++++------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/packages/ui-default/pages/problem_detail.page.jsx b/packages/ui-default/pages/problem_detail.page.jsx index 34bc18c23..b44829996 100644 --- a/packages/ui-default/pages/problem_detail.page.jsx +++ b/packages/ui-default/pages/problem_detail.page.jsx @@ -176,51 +176,37 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor async function loadObjective() { $('.outer-loader-container').show(); const ans = {}; - let objNum = 0; + let cnt = 0; const reg = /{{ (input|select|multiselect)\(\d+(-\d+)?\) }}/g; $('.problem-content .typo').children().each((i, e) => { if (e.tagName === 'PRE' && !e.children[0].className.includes('#input')) return; - const objQuestions = []; - let objQuestion = reg.exec(e.innerText); - while (objQuestion != null) { - objQuestions.push(objQuestion); - objQuestion = reg.exec(e.innerText); - } - objQuestions.forEach((obj) => { - objNum++; - const [objData, objType] = obj; - const objID = objData.replace(/{{ (input|select|multiselect)\((\d+(-\d+)?)\) }}/, '$2'); - if (objType === 'input') { - $(e).html($(e).html().replace(objData, ` -
- + const questions = []; + let q; + while (q = reg.exec(e.innerText)) questions.push(q); // eslint-disable-line no-cond-assign + for (const [info, type] of questions) { + cnt++; + const id = info.replace(/{{ (input|select|multiselect)\((\d+(-\d+)?)\) }}/, '$2'); + if (type === 'input') { + $(e).html($(e).html().replace(info, ` +
+
`)); - } else if (objType === 'select') { - $(e).html($(e).html().replace(objData, `Question${objNum}_${objID}:`)); + } else { + $(e).html($(e).html().replace(info, '')); $(e).next('ul').children().each((j, ele) => { $(ele).after(` -
- - ${String.fromCharCode(65 + j)}. ${ele.innerHTML} -
`); - $(ele).remove(); - }); - } else if (objType === 'multiselect') { - $(e).html($(e).html().replace(objData, `Question${objNum}_${objID}:`)); - $(e).next('ul').children().each((j, ele) => { - $(ele).after(` -
- +
+ ${String.fromCharCode(65 + j)}. ${ele.innerHTML}
`); $(ele).remove(); }); } - }); + } }); - if (objNum) { + if (cnt) { $('.problem-content .typo').append(document.getElementsByClassName('nav__item--round').length ? '' : '');