RM_RefereeTest_Killer

RM2024 裁判系统/规则测评助手,根据题库自动填充答案。Github: https://github.com/ShiratsuYudachi/RM_RefereeTest_Killer

  1. // ==UserScript==
  2. // @name RM_RefereeTest_Killer
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.7.3
  5. // @description RM2024 裁判系统/规则测评助手,根据题库自动填充答案。Github: https://github.com/ShiratsuYudachi/RM_RefereeTest_Killer
  6. // @author Nico & baoqi
  7. // @match https://djistore.wjx.cn/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. var questions = JSON.parse(localStorage.getItem("questions") || "[]");
  17.  
  18. // 如果localStorage中没有数据,则从URL获取JSON文件
  19. if (questions.length === 0) {
  20. var jsonUrl = "https://raw.githubusercontent.com/ShiratsuYudachi/RM_RefereeTest_Killer/main/answers2025_2.json"; // 替换为您的JSON文件URL
  21. fetch(jsonUrl)
  22. .then(response => response.json())
  23. .then(data => {
  24. questions = data; // 将获取的JSON数据赋值给questions数组
  25. localStorage.setItem("questions", JSON.stringify(questions)); // 将数据存储到localStorage中
  26. addAnswerButtons(); // 添加按钮
  27. })
  28. .catch(error => {
  29. console.error("Error fetching JSON:", error);
  30. });
  31. } else {
  32. addAnswerButtons(); // 如果已经有questions数据,则直接添加按钮
  33. }
  34.  
  35. /*
  36. function cosineSimilarity(str1, str2) {
  37. // 将字符串分割成单词数组
  38. const words1 = str1.toLowerCase().split(/\s+/);
  39. const words2 = str2.toLowerCase().split(/\s+/);
  40.  
  41. // 创建词频向量
  42. const vector1 = {};
  43. const vector2 = {};
  44.  
  45. // 填充词频向量
  46. words1.forEach(word => {
  47. vector1[word] = (vector1[word] || 0) + 1;
  48. });
  49.  
  50. words2.forEach(word => {
  51. vector2[word] = (vector2[word] || 0) + 1;
  52. });
  53.  
  54. // 计算点积
  55. let dotProduct = 0;
  56. for (const word in vector1) {
  57. if (vector2.hasOwnProperty(word)) {
  58. dotProduct += vector1[word] * vector2[word];
  59. }
  60. }
  61.  
  62. // 计算模长
  63. const magnitude1 = Math.sqrt(Object.values(vector1).reduce((acc, val) => acc + val * val, 0));
  64. const magnitude2 = Math.sqrt(Object.values(vector2).reduce((acc, val) => acc + val * val, 0));
  65.  
  66. // 计算余弦相似度
  67. const similarity = dotProduct / (magnitude1 * magnitude2);
  68.  
  69. // 转换为百分比
  70. const percentageSimilarity = (similarity * 100).toFixed(2);
  71.  
  72. return percentageSimilarity;
  73. }
  74. */
  75.  
  76.  
  77. // 添加按钮到页面
  78. function addButton() {
  79. var buttonCollect = document.createElement("button");
  80. buttonCollect.innerHTML = "收集题目";
  81. buttonCollect.style.position = "absolute";
  82. buttonCollect.style.top = "20px";
  83. buttonCollect.style.right = "20px";
  84. buttonCollect.style.width = "200px";
  85. buttonCollect.style.height = "50px";
  86. buttonCollect.addEventListener("click", collectQuestions);
  87. document.body.appendChild(buttonCollect);
  88.  
  89. var buttonDownload = document.createElement("button");
  90. buttonDownload.innerHTML = "下载题目缓存 (题目数=" + questions.length + ",该长度不会自动刷新)";
  91. buttonDownload.style.position = "absolute";
  92. buttonDownload.style.top = "80px";
  93. buttonDownload.style.right = "20px";
  94. buttonDownload.style.width = "200px";
  95. buttonDownload.style.height = "50px";
  96. buttonDownload.addEventListener("click", downloadJSON);
  97. document.body.appendChild(buttonDownload);
  98.  
  99.  
  100. var buttonClear = document.createElement("button");
  101. buttonClear.innerHTML = "清除数据(清除后刷新以重新下载题库)";
  102. buttonClear.style.position = "absolute";
  103. buttonClear.style.top = "140px";
  104. buttonClear.style.right = "20px";
  105. buttonClear.style.width = "200px";
  106. buttonClear.style.height = "50px";
  107. buttonClear.addEventListener("click", clearQuestions);
  108. document.body.appendChild(buttonClear);
  109.  
  110. // 添加导入按钮
  111. var buttonImport = document.createElement("button");
  112. buttonImport.innerHTML = "导入数据(建议导入后刷新)";
  113. buttonImport.style.position = "absolute";
  114. buttonImport.style.top = "200px";
  115. buttonImport.style.right = "20px";
  116. buttonImport.style.width = "200px";
  117. buttonImport.style.height = "50px";
  118. buttonImport.addEventListener("click", importQuestions);
  119. document.body.appendChild(buttonImport);
  120. }
  121. function clearQuestions() {
  122. questions = [];
  123. localStorage.removeItem("questions");
  124. updateDownloadButtonText();
  125. }
  126.  
  127. function importQuestions() {
  128. clearQuestions()
  129. var fileInput = document.createElement("input");
  130. fileInput.type = "file";
  131. fileInput.accept = ".json";
  132. fileInput.onchange = e => {
  133. var file = e.target.files[0];
  134. if (file) {
  135. var reader = new FileReader();
  136. reader.onload = function(event) {
  137. try {
  138. questions = JSON.parse(event.target.result);
  139. localStorage.setItem("questions", JSON.stringify(questions));
  140. updateDownloadButtonText();
  141. } catch (error) {
  142. alert("文件解析错误");
  143. }
  144. };
  145. reader.readAsText(file);
  146. }
  147. };
  148. fileInput.click();
  149. }
  150.  
  151. // 更新下载按钮文本
  152. function updateDownloadButtonText() {
  153. var buttonDownload = document.body.querySelector("button:nth-of-type(2)");
  154. buttonDownload.innerHTML = "下载题目 (" + questions.length + ")";
  155. }
  156.  
  157.  
  158. // 收集问题
  159. function collectQuestions() {
  160. var fields = document.querySelectorAll(".field.ui-field-contain");
  161.  
  162. fields.forEach(function(field) {
  163. var questionParts = Array.from(field.querySelectorAll(".topichtml > div")).map(div => div.innerText.trim());
  164. var questionText = field.querySelector(".topichtml").childNodes[0].nodeValue.trim() + questionParts.join(" ");
  165. var options = Array.from(field.querySelectorAll(".label")).map(el => el.innerText.trim());
  166.  
  167. var questionObj = {
  168. questionText: questionText,
  169. options: options,
  170. answer: "U" // 默认答案为"U"
  171. };
  172.  
  173. // 检查问题是否已经存在于数组中
  174. if (!questions.some(q => q.questionText === questionText)) {
  175. questions.push(questionObj);
  176. // 更新localStorage中的数据
  177. localStorage.setItem("questions", JSON.stringify(questions));
  178. }
  179. });
  180.  
  181. // 更新下载按钮文本
  182. var buttonDownload = document.body.querySelector("button:nth-of-type(2)");
  183. buttonDownload.innerHTML = "下载题目 (" + questions.length + ")";
  184. }
  185.  
  186. // 生成并下载JSON
  187. function downloadJSON() {
  188. var jsonContent = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(questions, null, 4));
  189. var link = document.createElement("a");
  190. link.setAttribute("href", jsonContent);
  191. link.setAttribute("download", "questions.json");
  192. document.body.appendChild(link);
  193. link.click();
  194. }
  195.  
  196. addButton();
  197.  
  198. function chooseAnswer(questionElement, answer) {
  199. if (answer === 'U' || answer === 'N') return; // 如果答案为'U',则不执行任何操作
  200.  
  201. // 获取选项文本
  202. var optionLabels = Array.from(questionElement.querySelectorAll('.label')).map(el => el.innerText.trim());
  203.  
  204. // 获取问题对应的JSON数据
  205. var questionParts = Array.from(questionElement.querySelectorAll(".topichtml > div")).map(div => div.innerText.trim());
  206. var questionText = questionElement.querySelector(".topichtml").childNodes[0].nodeValue.trim() + questionParts.join("");
  207.  
  208. var matchingQuestion = questions.find(q => q.questionText === questionText && q.options.includes(optionLabels[0]));
  209.  
  210. if (matchingQuestion) {
  211. // 找到对应答案的选项索引
  212. var answerIndex = matchingQuestion.options.findIndex(option => option === optionLabels[answer.charCodeAt(0) - 'A'.charCodeAt(0)]);
  213.  
  214. // add lines here
  215. // 1. 获取正确答案的文本
  216. var correctAnswerText = matchingQuestion.options[answer.charCodeAt(0) - 'A'.charCodeAt(0)];
  217.  
  218. // 2. 在当前选项中查找与正确答案文本完全匹配的选项索引
  219. answerIndex = optionLabels.findIndex(option => option === correctAnswerText);
  220.  
  221. // 3. 可选:处理未找到匹配的情况(例如,记录日志或提示)
  222. if (answerIndex === -1) {
  223. console.warn("未找到匹配的答案选项: " + correctAnswerText+"\n"+"questionText: "+questionText);
  224. }
  225. // end add lines here
  226.  
  227. if (answerIndex !== -1) {
  228. // 点击对应的单选按钮
  229. var radios = questionElement.querySelectorAll('.ui-radio');
  230. radios[answerIndex].click();
  231. }
  232. }else{
  233. console.warn("未找到匹配的答案: " + questionText);
  234. }
  235. }
  236.  
  237. // 添加选择答案的按钮
  238. function addAnswerButtons() {
  239. var questionElements = document.querySelectorAll('.field.ui-field-contain');
  240.  
  241. questionElements.forEach(function(questionElement) {
  242. var textDiv = document.createElement('div');
  243. textDiv.innerHTML = ''
  244.  
  245. // 获取问题文本
  246. var questionParts = Array.from(questionElement.querySelectorAll(".topichtml > div")).map(div => div.innerText.trim());
  247. var questionText = questionElement.querySelector(".topichtml").childNodes[0].nodeValue.trim() + questionParts.join("");
  248. //console.log(questionText);
  249. // 在questions数组中查找问题
  250. var matchingQuestion = questions.find(function(q) {
  251. return q.questionText === questionText;
  252. });
  253.  
  254. // 设置提示文本和答案
  255. if (matchingQuestion) {
  256. chooseAnswer(questionElement, matchingQuestion.answer);
  257. } else {
  258. textDiv.innerHTML = '未匹配到该问题: '+questionText;
  259. }
  260.  
  261. textDiv.style.marginLeft = '10px';
  262. textDiv.style.color = '#666';
  263. textDiv.style.fontSize = '14px';
  264. textDiv.style.padding = '5px';
  265. questionElement.appendChild(textDiv);
  266. });
  267.  
  268. }
  269. function expandPage() {
  270. // 检查是否存在分页并展开
  271. $('.fieldset').css('display', 'block');
  272. $('#divSubmit').css('display', 'block');
  273. $('#divMultiPage').css('display', 'none');
  274. }
  275. function checkForPagination() {
  276. var hasPagination = $('#divMultiPage').length > 0;
  277. if (hasPagination) {
  278. expandPage();
  279. createNotification(); // 创建提示框
  280. }
  281. }
  282.  
  283.  
  284. window.addEventListener('load', function() {
  285. checkForPagination();
  286. addAnswerButtons();
  287. });
  288. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址