上海市大学生安全教育在线 - 自动答题(模拟考试版)

模拟考试的答案在页面里。

目前為 2019-05-22 提交的版本,檢視 最新版本

// ==UserScript==
// @name        上海市大学生安全教育在线 - 自动答题(模拟考试版)
// @description 模拟考试的答案在页面里。
// @version     1
// @namespace   UnKnown
// @author      UnKnown
// @match       http://www.halnedu.com/pcexam/test/start
// @grant       none
// @run-at      document-end
// ==/UserScript==
(() => {

const clickAnswer =
 (question, answer) =>
  question.querySelector('input[value="' + answer + '"]').click();

document.querySelectorAll('#q1 .question, #q2 .question').forEach(
  question => clickAnswer(question, question.getAttribute('as'))
);

const MCQ = document.getElementById('q3');

MCQ.querySelectorAll('li.active').forEach(
  li => {
    li.classList.remove("active");
    li.querySelector(':scope > input').checked = false;
  }
);

MCQ.querySelectorAll('.question').forEach(
  question => question.getAttribute('as').split("").forEach(
    answer => clickAnswer(question, answer)
  )
);

})();

// Show right answer
((onHover = false) => {
  const answerStyle = document.createElement("style");
  answerStyle.textContent =
   (onHover ? '.box .question:hover ' : "") + '.answer {display: block !important}';
  document.head.appendChild(answerStyle);
})();