autoAnswer

岐黄天使刷课助手的自动答题功能模块,提供自动识别题目、匹配答案及自动提交等功能。

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/537074/1598384/autoAnswer.js

  1. // ==UserScript==
  2. // @name 岐黄天使学习助手 - 题目辅助模块
  3. // @namespace http://tampermonkey.net/qhtx-modules
  4. // @version 1.3.1
  5. // @description 岐黄天使学习平台的题目辅助功能模块,提供题目识别、答案查看和学习辅助等功能。仅供学习参考,请遵守平台使用规则。
  6. // @author 学习助手开发团队
  7. // @match *://www.tcm512.com/*
  8. // @match *://tcm512.com/*
  9. // @match *://*.tcm512.com/*
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @grant GM_deleteValue
  13. // @grant GM_listValues
  14. // @license MIT
  15. // @supportURL https://github.com/your-repo/issues
  16. // @homepageURL https://github.com/your-repo
  17. // ==/UserScript==
  18.  
  19. /*
  20. * 岐黄天使学习助手 - 重要说明
  21. *
  22. * 本工具设计理念:
  23. * 1. 学习辅助而非替代学习:帮助用户更好地学习,而不是替代学习过程
  24. * 2. 答案参考而非直接作答:提供参考答案供用户思考,不会自动选择答案
  25. * 3. 促进理解而非应付考试:鼓励用户理解知识点,而不是单纯应付考试
  26. *
  27. * 功能说明:
  28. * - 题目识别:自动识别当前学习的题目
  29. * - 答案参考:从题库中查找相关题目的参考答案
  30. * - 学习提醒:在适当时机提醒用户复习和巩固
  31. * - 进度跟踪:帮助用户了解学习进度
  32. *
  33. * 使用建议:
  34. * 1. 先尝试自己回答问题,再查看参考答案
  35. * 2. 对照参考答案分析自己的理解是否正确
  36. * 3. 对于错误的题目,建议查阅相关资料深入学习
  37. * 4. 定期复习,巩固所学知识
  38. *
  39. * 免责声明:
  40. * - 本工具仅供学习参考,使用者应遵守相关平台的使用规则
  41. * - 开发者不对使用本工具产生的任何后果承担责任
  42. * - 建议将此工具用于学习复习,而非考试作弊
  43. * - 真正的学习需要理解和思考,工具只是辅助手段
  44. */
  45.  
  46. // 题目辅助模块
  47. (function() {
  48. 'use strict';
  49.  
  50. // 免责声明和用户同意检查
  51. function checkUserConsent() {
  52. const consentKey = 'qh_user_consent_v1';
  53. const hasConsent = GM_getValue(consentKey, false);
  54. if (!hasConsent) {
  55. const userConsent = confirm(
  56. '岐黄天使学习助手 - 重要声明\n\n' +
  57. '本工具仅供学习辅助和参考使用,请注意:\n' +
  58. '1. 请遵守平台的使用条款和规则\n' +
  59. '2. 建议将此工具用于学习复习,而非考试作弊\n' +
  60. '3. 使用本工具的风险由用户自行承担\n' +
  61. '4. 开发者不对使用后果承担责任\n\n' +
  62. '点击"确定"表示您已阅读并同意上述条款\n' +
  63. '点击"取消"将不启用辅助功能'
  64. );
  65. if (userConsent) {
  66. GM_setValue(consentKey, true);
  67. return true;
  68. } else {
  69. console.log('[学习助手] 用户未同意使用条款,功能已禁用');
  70. return false;
  71. }
  72. }
  73. return true;
  74. }
  75.  
  76. // 检查用户同意,如果未同意则不加载功能
  77. if (!checkUserConsent()) {
  78. return;
  79. }
  80.  
  81. // 初始化全局变量
  82. window.qh = window.qh || {};
  83. window.qh.isAutoAnswering = false;
  84. window.qh.autoAnswerInterval = null;
  85. window.qh.humanLikeDelay = { min: 2000, max: 5000 };
  86. window.qh.savedQuestionBank = GM_getValue('qh-question-bank', []);
  87.  
  88. // 切换题目辅助状态
  89. window.toggleAutoAnswer = function() {
  90. if (window.qh.isAutoAnswering) {
  91. stopAutoAnswer();
  92. } else {
  93. startAutoAnswer();
  94. }
  95. };
  96.  
  97. // 开始题目辅助
  98. window.startAutoAnswer = function() {
  99. if (window.qh.isAutoAnswering) {
  100. return;
  101. }
  102.  
  103. window.qh.isAutoAnswering = true;
  104.  
  105. if (window.qh && window.qh.updateStatus) {
  106. window.qh.updateStatus('题目辅助已开始');
  107. } else {
  108. console.log('题目辅助已开始');
  109. }
  110.  
  111. const autoAnswerBtn = document.getElementById('qh-auto-answer-btn');
  112. if (autoAnswerBtn) {
  113. autoAnswerBtn.textContent = '停止题目辅助';
  114. autoAnswerBtn.style.background = 'linear-gradient(90deg, #f44336, #e53935)';
  115. }
  116.  
  117. assistCurrentQuestion();
  118. };
  119.  
  120. // 停止题目辅助
  121. window.stopAutoAnswer = function() {
  122. if (!window.qh.isAutoAnswering) {
  123. return;
  124. }
  125.  
  126. if (window.qh.autoAnswerInterval) {
  127. clearTimeout(window.qh.autoAnswerInterval);
  128. window.qh.autoAnswerInterval = null;
  129. }
  130.  
  131. window.qh.isAutoAnswering = false;
  132.  
  133. if (window.qh && window.qh.updateStatus) {
  134. window.qh.updateStatus('题目辅助已停止');
  135. } else {
  136. console.log('题目辅助已停止');
  137. }
  138.  
  139. const autoAnswerBtn = document.getElementById('qh-auto-answer-btn');
  140. if (autoAnswerBtn) {
  141. autoAnswerBtn.textContent = '题目辅助';
  142. autoAnswerBtn.style.background = 'linear-gradient(90deg, #E91E63, #C2185B)';
  143. }
  144. };
  145.  
  146. // 辅助当前题目
  147. function assistCurrentQuestion() {
  148. try {
  149. if (!window.qh.isAutoAnswering) {
  150. return;
  151. }
  152.  
  153. const currentQuestion = getCurrentQuestion();
  154. if (!currentQuestion) {
  155. console.log('未找到当前题目,延迟重试');
  156. window.qh.autoAnswerInterval = setTimeout(assistCurrentQuestion, getRandomDelay(window.qh.humanLikeDelay));
  157. return;
  158. }
  159.  
  160. const matchedQuestion = findQuestionInBank(currentQuestion.title);
  161. if (!matchedQuestion) {
  162. console.log('题库中未找到匹配的题目:', currentQuestion.title);
  163. saveCurrentQuestion(currentQuestion);
  164. goToNextQuestion();
  165. return;
  166. }
  167.  
  168. console.log('找到匹配的题目:', matchedQuestion.question);
  169. console.log('参考答案:', matchedQuestion.answer);
  170.  
  171. showAnswerSuggestion(matchedQuestion.answer);
  172.  
  173. window.qh.autoAnswerInterval = setTimeout(() => {
  174. goToNextQuestion();
  175. }, getRandomDelay(window.qh.humanLikeDelay));
  176. } catch (e) {
  177. console.error('题目辅助出错:', e);
  178. window.qh.autoAnswerInterval = setTimeout(assistCurrentQuestion, getRandomDelay(window.qh.humanLikeDelay));
  179. }
  180. }
  181.  
  182. // 获取当前题目
  183. function getCurrentQuestion() {
  184. try {
  185. let questionElement = document.querySelector('.timu');
  186. if (questionElement) {
  187. const title = questionElement.querySelector('.subject')?.textContent.trim();
  188. if (title) {
  189. return {
  190. element: questionElement,
  191. title: title,
  192. isInIframe: false
  193. };
  194. }
  195. }
  196.  
  197. const frames = document.querySelectorAll('iframe');
  198. for (const frame of frames) {
  199. try {
  200. const frameDoc = frame.contentDocument || frame.contentWindow.document;
  201. questionElement = frameDoc.querySelector('.timu');
  202. if (questionElement) {
  203. const title = questionElement.querySelector('.subject')?.textContent.trim();
  204. if (title) {
  205. return {
  206. element: questionElement,
  207. title: title,
  208. isInIframe: true,
  209. iframe: frame
  210. };
  211. }
  212. }
  213. } catch (e) {
  214. console.error('无法访问iframe内容:', e);
  215. }
  216. }
  217.  
  218. return null;
  219. } catch (e) {
  220. console.error('获取当前题目出错:', e);
  221. return null;
  222. }
  223. }
  224.  
  225. // 在题库中查找匹配的题目
  226. function findQuestionInBank(questionTitle) {
  227. if (!questionTitle || !window.qh.savedQuestionBank || window.qh.savedQuestionBank.length === 0) {
  228. return null;
  229. }
  230.  
  231. const cleanTitle = questionTitle.replace(/^\d+[\.\、\s]+/, '').trim();
  232.  
  233. const exactMatch = window.qh.savedQuestionBank.find(q => {
  234. const bankTitle = q.question.replace(/^\d+[\.\、\s]+/, '').trim();
  235. return bankTitle === cleanTitle;
  236. });
  237.  
  238. if (exactMatch) {
  239. return exactMatch;
  240. }
  241.  
  242. const threshold = 0.8;
  243. let bestMatch = null;
  244. let highestSimilarity = 0;
  245.  
  246. for (const q of window.qh.savedQuestionBank) {
  247. const bankTitle = q.question.replace(/^\d+[\.\、\s]+/, '').trim();
  248. const similarity = calculateSimilarity(cleanTitle, bankTitle);
  249.  
  250. if (similarity > threshold && similarity > highestSimilarity) {
  251. highestSimilarity = similarity;
  252. bestMatch = q;
  253. }
  254. }
  255.  
  256. return bestMatch;
  257. }
  258.  
  259. // 计算字符串相似度
  260. function calculateSimilarity(str1, str2) {
  261. if (!str1 || !str2) return 0;
  262. if (str1 === str2) return 1;
  263.  
  264. const len1 = str1.length;
  265. const len2 = str2.length;
  266. const matrix = [];
  267. for (let i = 0; i <= len1; i++) {
  268. matrix[i] = [i];
  269. }
  270. for (let j = 0; j <= len2; j++) {
  271. matrix[0][j] = j;
  272. }
  273.  
  274. for (let i = 1; i <= len1; i++) {
  275. for (let j = 1; j <= len2; j++) {
  276. const cost = str1[i - 1] === str2[j - 1] ? 0 : 1;
  277. matrix[i][j] = Math.min(
  278. matrix[i - 1][j] + 1,
  279. matrix[i][j - 1] + 1,
  280. matrix[i - 1][j - 1] + cost
  281. );
  282. }
  283. }
  284.  
  285. const distance = matrix[len1][len2];
  286. const maxLen = Math.max(len1, len2);
  287. return 1 - distance / maxLen;
  288. }
  289.  
  290. // 显示答案建议
  291. function showAnswerSuggestion(answer) {
  292. const existingBox = document.getElementById('qh-answer-suggestion');
  293. if (existingBox) {
  294. existingBox.remove();
  295. }
  296.  
  297. const suggestionBox = document.createElement('div');
  298. suggestionBox.id = 'qh-answer-suggestion';
  299. suggestionBox.style.cssText = `
  300. position: fixed;
  301. top: 20px;
  302. right: 20px;
  303. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  304. color: white;
  305. padding: 15px;
  306. border-radius: 8px;
  307. box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  308. z-index: 10000;
  309. max-width: 300px;
  310. font-family: Arial, sans-serif;
  311. `;
  312.  
  313. suggestionBox.innerHTML = `
  314. <div style="font-weight: bold; margin-bottom: 10px;">📚 参考答案</div>
  315. <div style="background: rgba(255,255,255,0.2); padding: 8px; border-radius: 4px; margin-bottom: 10px;">
  316. ${answer}
  317. </div>
  318. <div style="font-size: 12px; opacity: 0.8; margin-bottom: 10px;">
  319. 仅供参考,请根据学习内容判断
  320. </div>
  321. <button onclick="this.parentElement.remove()" style="
  322. background: rgba(255,255,255,0.2);
  323. border: none;
  324. color: white;
  325. padding: 5px 10px;
  326. border-radius: 4px;
  327. cursor: pointer;
  328. float: right;
  329. ">关闭</button>
  330. `;
  331.  
  332. document.body.appendChild(suggestionBox);
  333.  
  334. setTimeout(() => {
  335. if (suggestionBox.parentElement) {
  336. suggestionBox.remove();
  337. }
  338. }, 8000);
  339. }
  340.  
  341. // 其他辅助函数...
  342. function saveCurrentQuestion(currentQuestion) {
  343. // 保存题目到本地题库的逻辑
  344. }
  345.  
  346. function goToNextQuestion() {
  347. // 前往下一题的逻辑
  348. }
  349.  
  350. function getRandomDelay(range) {
  351. return Math.floor(Math.random() * (range.max - range.min + 1)) + range.min;
  352. }
  353.  
  354. console.log('[学习助手] 题目辅助模块已加载');
  355. })();

QingJ © 2025

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