All comments indicating // need modify need to be changed.
hint: You can use LLM to get answer and then use this script to answer questions automaticly.>_<
json format example :
[
{
"title": "this is question A",
"answer": "false"
},
{
"title": "this is question B",
"answer": "A"
}
]
// ==UserScript==
// @name Automatic_answer_Tampermonkey_script
// @namespace http://tampermonkey.net/
// @version 0.1
// @description read JSON file,Automatic_answer
// @author you
// @match https://example.com/* // need modify
// @grant none
// ==/UserScript==
(function() {
'use strict';
function addControlPanel() {
const panel = document.createElement('div');
panel.style.position = 'fixed';
panel.style.top = '10px';
panel.style.right = '10px';
panel.style.zIndex = '999999';
panel.style.background = 'rgba(0,0,0,0.7)';
panel.style.color = '#fff';
panel.style.padding = '10px';
panel.style.borderRadius = '6px';
panel.style.fontSize = '12px';
const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = 'application/json';
fileInput.style.marginBottom = '5px';
fileInput.style.display = 'block';
const btn = document.createElement('button');
btn.textContent = 'Automatic answer';
btn.style.display = 'block';
btn.style.width = '100%';
btn.style.cursor = 'pointer';
panel.appendChild(fileInput);
panel.appendChild(btn);
document.body.appendChild(panel);
let qaList = null;
// Read JSON
fileInput.addEventListener('change', function(e) {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function() {
try {
qaList = JSON.parse(reader.result);
alert('The answer JSON was loaded successfully, totaling ' + qaList.length + ' questions.');
} catch (err) {
console.error(err);
alert('JSON parsing failed. Please check if the format is [ {"title":..., "answer":...}, ... ');
}
};
reader.readAsText(file, 'utf-8');
});
// Click on [Auto Answer]
btn.addEventListener('click', function() {
if (!qaList) {
alert('Please select a JSON file first!');
return;
}
autoAnswer(qaList);
});
}
function autoAnswer(qaList) {
const questionNodes = document.querySelectorAll('.m-item');
let matchedCount = 0;
qaList.forEach(item => {
const titleKeyword = String(item.title || '').trim();
const answerKeyword = String(item.answer || '').trim();
if (!titleKeyword || !answerKeyword) return;
questionNodes.forEach(qNode => {
// The question stem is in .subject-title.examTitle
const titleNode = qNode.querySelector('.subject-title.examTitle'); // need modify
if (!titleNode) return;
const titleText = titleNode.innerText.trim();
// Use "contains" to match questions (not requiring exact consistency, so you can fill in only a part).
if (!titleText.includes(titleKeyword)) return;
// Options: under .select-box, label .ivu-radio-wrapper
const optionLabels = qNode.querySelectorAll('.select-box .ivu-radio-wrapper'); // need modify
let clicked = false;
optionLabels.forEach(label => {
if (clicked) return;
const optionText = label.innerText.trim();
const input = label.querySelector('input.ivu-radio-input'); // need modify
if (!input) return;
// Matching method:
// 1. Option text contains answer keywords (e.g., "True" or "False")
// 2. Compatible with A./A format
if (
optionText.includes(answerKeyword) || // Content contains
optionText.startsWith(answerKeyword + '.') || // A. xxx
optionText.startsWith(answerKeyword + '、') || // A、xxx
optionText.startsWith(answerKeyword + ' ') // A xxx
) {
// Prioritize input fields for compatibility with some framework events
input.click();
// Click the label again for backup
label.click();
clicked = true;
matchedCount++;
console.log('The title [' + titleKeyword + '] has been selected:' + optionText);
}
});
});
});
alert('The system will automatically click "Complete," successfully matching and selecting approximately '+ matchedCount+' options.');
}
window.addEventListener('load', function() {
// Sometimes the questions are rendered asynchronously, so you can wait a little while.
setTimeout(addControlPanel, 1500);
});
})();