Greasy Fork is available in English.
RM2024 裁判系统测评助手,根据题库自动填充答案。Github: https://github.com/ShiratsuYudachi/RM_RefereeTest_Killer
当前为
// ==UserScript==
// @name RM_RefereeTest_Killer
// @namespace http://tampermonkey.net/
// @version 1.6.1
// @description RM2024 裁判系统测评助手,根据题库自动填充答案。Github: https://github.com/ShiratsuYudachi/RM_RefereeTest_Killer
// @author Nico & baoqi
// @match https://djistore.wjx.cn/*
// @grant none
// @license MIT
// ==/UserScript==
fetch("https://djistore.wjx.cn/joinnew/processjq.ashx?shortid=tDYWP6v&starttime=2024%2F12%2F2%2023%3A17%3A05&cst=1733152686132&vpsiu=1&nc_csessionid=01LJSzokXSI0pTRXrm3NoFzFa4H8OvYJtg0WSJqdfxTbzv58TWWF4jEnqJGzenthf65AEwKT0_q1Vg0kiVq9Q1lN3T1LtSyFSbZVnNwRpV7hsrSItNZiC_hTUsZjh_hUZL&nc_sig=05a1C7nT4bR5hcbZlAujcdyZAUgkgHJPsZ2HO1Qnfv-YpShZo0e_7c-Du0Wwth_f2D75FC80f83So--3urP8DmIisGRJv8I-0z11dNFGsOPH-UMKV0x5Uk-kGyb6lYpXltM0naHm4eIa7x8NevrhgFdqtZPYdIDGUY_hKiMrKsEgWBc7jKllbl4JQE8SEkuoW1tYNY974UVGAUF6C03i6u4ewmytmrPmP8o5V7jLrnolELU6Mqtho3hV59u1YGZA-Y3-3zIdIbuA3jrJq4fkGjCzZIkw8W48JEGJYMea7H_fhr9CMfE4N1v1X_bcpOqxwSGcNsTSUyrXn6_KxiKKSe2ro_69GQ1MceaNeJwpSqXJw&nc_token=1733152625716%3A0.47582499972760917&nc_scene=ic_activity&submittype=1&ktimes=1046&hlv=1&rn=2406462562.36919065&jcn=7&t=1733152686132&wxfs=100&jqnonce=bbc75e80-aa4a-4b67-a340-bf620ecb8494&jqsign=dde13c%3E6%2Bgg2g%2B2d01%2Bg526%2Bd%60046ced%3E2%3F2", {
"headers": {
"accept": "text/plain, */*; q=0.01",
"accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,zh-TW;q=0.6",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"priority": "u=1, i",
"sec-ch-ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-requested-with": "XMLHttpRequest"
},
"referrer": "https://djistore.wjx.cn/vm/tDYWP6v.aspx",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": "submitdata=1%241%7D2%241%7D3%243%7D4%241%7D5%244%7D6%244%7D9%244%7D12%241%7D14%243%7D16%241%7D17%241%7D20%241%7D23%243%7D31%242%7D33%241%7D35%243%7D36%244%7D38%244%7D39%244%7D41%241%7D42%244%7D47%242%7D49%241%7D50%244%7D51%242%7D54%242%7D59%241%7D60%244%7D63%244%7D64%243%7D66%241%7D67%241%7D68%241%7D69%241%7D70%241%7D72%242%7D73%241%7D75%241%7D76%244%7D78%243%7D80%243%7D81%242%7D82%241%7D83%244%7D84%244%7D85%242%7D87%243%7D88%241%7D89%241%7D91%244%7D92%242%7D94%241%7D95%241%7D96%243%7D98%243%7D99%243%7D101%244%7D104%244%7D106%244%7D107%243%7D111%243%7D112%244%7D113%243%7D119%244%7D121%242%7D122%244%7D126%241%7D128%241%7D129%243%7D130%243%7D131%242%7D134%243%7D135%244%7D137%243%7D139%242%7D142%242%7D144%243%7D145%242%7D146%244%7D147%244%7D149%243%7D150%244%7D151%242%7D153%243%7D154%241%7D155%243%7D156%242%7D158%244%7D159%243%7D161%242%7D164%244%7D167%244%7D170%241%7D173%244%7D175%242%7D177%243%7D178%244%7D179%244%7D183%244%7D184%243%7D186%244%7D187%244",
"method": "POST",
"mode": "cors",
"credentials": "include"
});
(function() {
'use strict';
var questions = JSON.parse(localStorage.getItem("questions") || "[]");
// 如果localStorage中没有数据,则从URL获取JSON文件
if (questions.length === 0) {
var jsonUrl = "https://raw.githubusercontent.com/ShiratsuYudachi/RM_RefereeTest_Killer/main/answers2025.json"; // 替换为您的JSON文件URL
fetch(jsonUrl)
.then(response => response.json())
.then(data => {
questions = data; // 将获取的JSON数据赋值给questions数组
localStorage.setItem("questions", JSON.stringify(questions)); // 将数据存储到localStorage中
addAnswerButtons(); // 添加按钮
})
.catch(error => {
console.error("Error fetching JSON:", error);
});
} else {
addAnswerButtons(); // 如果已经有questions数据,则直接添加按钮
}
/*
function cosineSimilarity(str1, str2) {
// 将字符串分割成单词数组
const words1 = str1.toLowerCase().split(/\s+/);
const words2 = str2.toLowerCase().split(/\s+/);
// 创建词频向量
const vector1 = {};
const vector2 = {};
// 填充词频向量
words1.forEach(word => {
vector1[word] = (vector1[word] || 0) + 1;
});
words2.forEach(word => {
vector2[word] = (vector2[word] || 0) + 1;
});
// 计算点积
let dotProduct = 0;
for (const word in vector1) {
if (vector2.hasOwnProperty(word)) {
dotProduct += vector1[word] * vector2[word];
}
}
// 计算模长
const magnitude1 = Math.sqrt(Object.values(vector1).reduce((acc, val) => acc + val * val, 0));
const magnitude2 = Math.sqrt(Object.values(vector2).reduce((acc, val) => acc + val * val, 0));
// 计算余弦相似度
const similarity = dotProduct / (magnitude1 * magnitude2);
// 转换为百分比
const percentageSimilarity = (similarity * 100).toFixed(2);
return percentageSimilarity;
}
*/
// 添加按钮到页面
function addButton() {
var buttonCollect = document.createElement("button");
buttonCollect.innerHTML = "收集题目";
buttonCollect.style.position = "absolute";
buttonCollect.style.top = "20px";
buttonCollect.style.right = "20px";
buttonCollect.style.width = "200px";
buttonCollect.style.height = "50px";
buttonCollect.addEventListener("click", collectQuestions);
document.body.appendChild(buttonCollect);
var buttonDownload = document.createElement("button");
buttonDownload.innerHTML = "下载题目缓存 (题目数=" + questions.length + ",该长度不会自动刷新)";
buttonDownload.style.position = "absolute";
buttonDownload.style.top = "80px";
buttonDownload.style.right = "20px";
buttonDownload.style.width = "200px";
buttonDownload.style.height = "50px";
buttonDownload.addEventListener("click", downloadJSON);
document.body.appendChild(buttonDownload);
var buttonClear = document.createElement("button");
buttonClear.innerHTML = "清除数据";
buttonClear.style.position = "absolute";
buttonClear.style.top = "140px";
buttonClear.style.right = "20px";
buttonClear.style.width = "200px";
buttonClear.style.height = "50px";
buttonClear.addEventListener("click", clearQuestions);
document.body.appendChild(buttonClear);
// 添加导入按钮
var buttonImport = document.createElement("button");
buttonImport.innerHTML = "导入数据(建议导入后刷新)";
buttonImport.style.position = "absolute";
buttonImport.style.top = "200px";
buttonImport.style.right = "20px";
buttonImport.style.width = "200px";
buttonImport.style.height = "50px";
buttonImport.addEventListener("click", importQuestions);
document.body.appendChild(buttonImport);
}
function clearQuestions() {
questions = [];
localStorage.removeItem("questions");
updateDownloadButtonText();
}
function importQuestions() {
clearQuestions()
var fileInput = document.createElement("input");
fileInput.type = "file";
fileInput.accept = ".json";
fileInput.onchange = e => {
var file = e.target.files[0];
if (file) {
var reader = new FileReader();
reader.onload = function(event) {
try {
questions = JSON.parse(event.target.result);
localStorage.setItem("questions", JSON.stringify(questions));
updateDownloadButtonText();
} catch (error) {
alert("文件解析错误");
}
};
reader.readAsText(file);
}
};
fileInput.click();
}
// 更新下载按钮文本
function updateDownloadButtonText() {
var buttonDownload = document.body.querySelector("button:nth-of-type(2)");
buttonDownload.innerHTML = "下载题目 (" + questions.length + ")";
}
// 收集问题
function collectQuestions() {
var fields = document.querySelectorAll(".field.ui-field-contain");
fields.forEach(function(field) {
var questionParts = Array.from(field.querySelectorAll(".topichtml > div")).map(div => div.innerText.trim());
var questionText = field.querySelector(".topichtml").childNodes[0].nodeValue.trim() + questionParts.join(" ");
var options = Array.from(field.querySelectorAll(".label")).map(el => el.innerText.trim());
var questionObj = {
questionText: questionText,
options: options,
answer: "U" // 默认答案为"U"
};
// 检查问题是否已经存在于数组中
if (!questions.some(q => q.questionText === questionText)) {
questions.push(questionObj);
// 更新localStorage中的数据
localStorage.setItem("questions", JSON.stringify(questions));
}
});
// 更新下载按钮文本
var buttonDownload = document.body.querySelector("button:nth-of-type(2)");
buttonDownload.innerHTML = "下载题目 (" + questions.length + ")";
}
// 生成并下载JSON
function downloadJSON() {
var jsonContent = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(questions, null, 4));
var link = document.createElement("a");
link.setAttribute("href", jsonContent);
link.setAttribute("download", "questions.json");
document.body.appendChild(link);
link.click();
}
addButton();
function chooseAnswer(questionElement, answer) {
if (answer === 'U' || answer === 'N') return; // 如果答案为'U',则不执行任何操作
// 获取选项文本
var optionLabels = Array.from(questionElement.querySelectorAll('.label')).map(el => el.innerText.trim());
// 获取问题对应的JSON数据
var questionParts = Array.from(questionElement.querySelectorAll(".topichtml > div")).map(div => div.innerText.trim());
var questionText = questionElement.querySelector(".topichtml").childNodes[0].nodeValue.trim() + questionParts.join(" ");
var matchingQuestion = questions.find(q => q.questionText === questionText);
if (matchingQuestion) {
// 找到对应答案的选项索引
var answerIndex = matchingQuestion.options.findIndex(option => option === optionLabels[answer.charCodeAt(0) - 'A'.charCodeAt(0)]);
// add lines here
// 1. 获取正确答案的文本
var correctAnswerText = matchingQuestion.options[answer.charCodeAt(0) - 'A'.charCodeAt(0)];
// 2. 在当前选项中查找与正确答案文本完全匹配的选项索引
answerIndex = optionLabels.findIndex(option => option === correctAnswerText);
// 3. 可选:处理未找到匹配的情况(例如,记录日志或提示)
if (answerIndex === -1) {
console.warn("未找到匹配的答案选项: " + correctAnswerText+"\n"+"questionText: "+questionText);
}
// end add lines here
if (answerIndex !== -1) {
// 点击对应的单选按钮
var radios = questionElement.querySelectorAll('.ui-radio');
radios[answerIndex].click();
}
}else{
console.warn("未找到匹配的答案: " + questionText);
}
}
// 添加选择答案的按钮
function addAnswerButtons() {
var questionElements = document.querySelectorAll('.field.ui-field-contain');
questionElements.forEach(function(questionElement) {
var textDiv = document.createElement('div');
textDiv.innerHTML = ''
// 获取问题文本
var questionParts = Array.from(questionElement.querySelectorAll(".topichtml > div")).map(div => div.innerText.trim());
var questionText = questionElement.querySelector(".topichtml").childNodes[0].nodeValue.trim() + questionParts.join(" ");
//console.log(questionText);
// 在questions数组中查找问题
var matchingQuestion = questions.find(function(q) {
// TODO: handle 正确/错误
//return cosineSimilarity(q.questionText, questionText) >= 0.8;
return q.questionText === questionText;
});
// 设置提示文本和答案
if (matchingQuestion) {
// textDiv.innerHTML = '题库内答案(注意这个不是该选项答案!选项是随机打乱的!):' + matchingQuestion.answer;
chooseAnswer(questionElement, matchingQuestion.answer);
} else {
textDiv.innerHTML = '未匹配到该问题';
}
textDiv.style.marginLeft = '10px';
textDiv.style.color = '#666';
textDiv.style.fontSize = '14px';
textDiv.style.padding = '5px';
questionElement.appendChild(textDiv);
});
}
function expandPage() {
// 检查是否存在分页并展开
$('.fieldset').css('display', 'block');
$('#divSubmit').css('display', 'block');
$('#divMultiPage').css('display', 'none');
}
function checkForPagination() {
var hasPagination = $('#divMultiPage').length > 0;
if (hasPagination) {
expandPage();
createNotification(); // 创建提示框
}
}
window.addEventListener('load', function() {
checkForPagination();
addAnswerButtons();
});
})();