hysbeta / 91huayi

91华医 公需课 自动看 考试 下一节
16 stars 8 forks source link

做题页面布局结构变化,导致自动答题失效 #7

Open CianCHEN opened 3 months ago

CianCHEN commented 3 months ago
// 总问题数 防止越界
for (i = 0; i <= document.querySelectorAll(".test > table > tbody").length -1 ; i++) {
    question_text = (document.querySelectorAll(".test > table")[i].querySelector("thead > tr > th > label").textContent.substring(document.querySelectorAll(".test > table")[i].querySelector("thead > tr > th > label").textContent.indexOf("、") + 1));
    console.log("Q:" + question_text)
        if (correct_ans.hasOwnProperty(question_text)) {
                // 答案选项
        for (j = 1; j <= document.querySelectorAll(".test > table")[i].querySelector(" tbody").childElementCount; j++) {
            if (correct_ans[question_text] == document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(" + j + ") > td ").textContent.trim()) {
                document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(" + j + ") > td > label > input").click()
                ans_text = document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(" + j + ") > td ").textContent.trim()
                      sub_ans[question_text] = ans_text;
                console.log("Already have correct answer for this question -> " + ans_text)
                      break;
            }
        }
    } else if (wrong_ans.hasOwnProperty(question_text)) {
        for (j = 1; j <= document.querySelectorAll(".test > table")[i].querySelector(" tbody").childElementCount; j++) {
            if (wrong_ans[question_text].indexOf(document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(" + j + ") > td ").textContent.trim()) == -1) {
                document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(" + j + ") > td > label > input").click()
                ans_text = document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(" + j + ") > td ").textContent.trim()
                      sub_ans[question_text] = ans_text;
                console.log("Only have wrong answer for this question, try -> " + ans_text)
                      break;
            }
        }
    } else {
        document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(1) > td > label > input").click();
        ans_text = document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(1) > td ").textContent.trim()
              sub_ans[question_text] = ans_text;
        console.log("First time meet this question, try -> " + ans_text)
    }
};
CianCHEN commented 3 months ago

考试结果页变化

for (i = 0; i <= document.querySelectorAll('img[src="/images/images_20221112/error_icon.png"] + p[title]').length -1 ;i++){
     // 错题集
     wrong_questions.push(document.querySelectorAll('img[src="/images/images_20221112/error_icon.png"] + p[title]')[i].getAttribute("title"))
}