Greasy Fork is available in English.

青骄第二课堂答题小助手

第二课堂(https://www.2-class.com)答题小助手,安装后进入知识竞赛按Ctrl键弹出答案或开启自动答题功能自动选择正确答案并跳转到下一题。

  1. // ==UserScript==
  2. // @name 青骄第二课堂答题小助手
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @license GPL
  6. // @description 第二课堂(https://www.2-class.com)答题小助手,安装后进入知识竞赛按Ctrl键弹出答案或开启自动答题功能自动选择正确答案并跳转到下一题。
  7. // @author t0ny.t4ng
  8. // @match https://2-class.com/competition
  9. // @match https://www.2-class.com/competition
  10. // @icon https://img.alicdn.com/tfs/TB13RHdl8r0gK0jSZFnXXbRRXXa-32-32.png
  11. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js
  12. // @require https://cdn.bootcdn.net/ajax/libs/toastr.js/latest/js/toastr.min.js
  13. // @require https://greasyfork.org/scripts/435468-lib42class/code/lib42class.js?version=1108850
  14. // @resource css https://cdn.bootcdn.net/ajax/libs/toastr.js/2.1.4/toastr.min.css
  15. // @grant GM_getResourceText
  16. // @grant unsafeWindow
  17. // @grant GM_addStyle
  18. // ==/UserScript==
  19.  
  20. (function () {
  21.  
  22. 'use strict';
  23.  
  24. function sleep(time) {
  25. return new Promise(resolve => {
  26. setTimeout(() => {
  27. resolve();
  28. }, time);
  29. });
  30. }
  31.  
  32. var config ={isAuto:false}
  33.  
  34. //设置toastr参数
  35. toastr.options = {
  36. "closeButton": true,
  37. "debug": false,
  38. "newestOnTop": false,
  39. "progressBar": false,
  40. "positionClass": "toast-bottom-left",
  41. "preventDuplicates": false,
  42. "onclick": null,
  43. "showDuration": "1000",
  44. "hideDuration": "1000",
  45. "timeOut": "1000",
  46. "extendedTimeOut": "1000",
  47. "showEasing": "swing",
  48. "hideEasing": "linear",
  49. "showMethod": "fadeIn",
  50. "hideMethod": "fadeOut"
  51. }
  52.  
  53. const gradesPrimary = {一年级: 1, 二年级: 2, 三年级: 3, 四年级: 4, 五年级: 5, 六年级: 6 }
  54. const choices = {A:0,B:1,C:2,D:3,E:4,F:5,G:6,H:7}
  55.  
  56. //获取当前用户年级
  57. const gradeName = unsafeWindow.__DATA__.userInfo.department.gradeName
  58.  
  59.  
  60. var lib;
  61.  
  62.  
  63. //根据所在年级选择对应题库
  64. if(gradeName in gradesPrimary){
  65. lib = libs.libPrimarySchool
  66. toastr["success"]("已匹配小学组题库")
  67. }else{
  68. lib = libs.libMiddleSchool;
  69. toastr["success"]("已匹配中学组题库")
  70. }
  71.  
  72.  
  73. //引入toastr所需样式css
  74. GM_addStyle(GM_getResourceText('css'))
  75.  
  76.  
  77. document.addEventListener("keydown", event => {
  78. //用event.key替换被弃用的event.keyCode
  79. //if (event.keyCode === 17) {
  80.  
  81. if (event.key === 'Control') {
  82. //当前题号
  83. let questionNum = document.querySelector("#app > div > div.home-container > div > div > div.competiotion-exam-box-all > div.exam-box > div:nth-child(3) > p > span.exam-content-type-text > b").innerText
  84. //如果是第1题,询问是否打开自动答题功能
  85. if(!config.isAuto&&questionNum==='1'){
  86. config.isAuto = confirm("开启自动答题功能吗?")}
  87.  
  88. var q_txt = document.querySelector("#app > div > div.home-container > div > div > div.competiotion-exam-box-all > div.exam-box > div:nth-child(3) > div").innerText
  89. lib.forEach(function (element) {
  90. // 使用正则表达式移除非汉字字符,以方便比较
  91. var qtxt = q_txt.replaceAll(/[^\u4e00-\u9fa5]/g, '');
  92. var ltxt = element.question.replaceAll(/[^\u4e00-\u9fa5]/g, '')
  93. if (qtxt.indexOf(ltxt) === 0) {
  94. //if (q_txt.replaceAll(/[^\u4e00-\u9fa5]/g, '').indexOf(element.question.replaceAll(/[^\u4e00-\u9fa5]/g, ''))>=0) {
  95. //alert("问题:" + q_txt + "\n\n答案:" + element.answer)
  96. //toastr["success"](q_txt, element.answer)
  97. toastr["success"](q_txt, "<h1 style='color:#ffdb01'>" + element.answer + "</h1>")
  98.  
  99. //判断是否启用了“自动答题”功能,未启用不执行后续代码
  100. if (!config.isAuto)
  101. return
  102.  
  103. var options = document.querySelector("#app > div > div.home-container > div > div > div.competiotion-exam-box-all > div.exam-box > div:nth-child(4) > div").children
  104. //单选题
  105. for(var i=0;i<element.answer.length;i++){
  106. let answer = element.answer.toUpperCase().at(i)
  107. let choice = choices[answer]
  108. options[choice].click()
  109.  
  110. }
  111.  
  112. sleep(1000).then(()=>{
  113. let nextButton = document.querySelector("#app > div > div.home-container > div > div > div.competiotion-exam-box-all > div.exam-box > div.competition-sub > button.ant-btn.ant-btn-primary")
  114. nextButton.click()
  115.  
  116. })
  117.  
  118. }
  119. });
  120. }
  121.  
  122. });
  123. })();