形势与政策自动挂机

自动定位章节、看视频、阅读、答题!

  1. // ==UserScript==
  2. // @name 形势与政策自动挂机
  3. // @version 1.0
  4. // @description 自动定位章节、看视频、阅读、答题!
  5. // @author haimage
  6. // @require http://cdn.bootcss.com/jquery/1.8.3/jquery.min.js
  7. // @match https://ua.ulearning.cn/learnCourse/learnCourse.html?courseId=9611*
  8. // @require https://cdn.bootcss.com/clipboard.js/1.5.16/clipboard.min.js
  9. // @supportURL
  10. // @run-at
  11. // @grant
  12. // @namespace undefined
  13. // ==/UserScript==
  14. function init() {
  15. var uLearnUrl = "https://ua.ulearning.cn/learnCourse/learnCourse.html";
  16. if(!(window.location.href.indexOf(uLearnUrl) >= 0)){
  17. console.log("页面地址不对,不能进行挂机...");
  18. //return 0;
  19. }else {
  20. var totalUnit = $('.chapter-name').length;
  21. var i=0;
  22. var t = setInterval(function () {
  23. $(".section-list .section-item .page-list .text .page-icon i[class='iconfont']:eq(0)").trigger('click');
  24. i++;
  25. console.log("正在定位章节中...");
  26. if(i>=totalUnit)
  27. clearInterval(t);
  28. },3000);
  29. //由于上面的定时器代码是异步执行的,所以这里我们也加上相应的延时。
  30. setTimeout(function () {
  31. isExamPage();
  32. },totalUnit*3000+3000);
  33. }
  34. }
  35. //判断是否为考试页面
  36. function isExamPage() {
  37. console.log("判断是否为考试页...");
  38. var timeExam = setTimeout(function () {
  39. if($('.course-title').text().indexOf("习题") >= 0 && $('.question-view').length > 0){
  40. if($('.question-setting-panel .question-setting-list>div:eq(1)>div:eq(0)').text() == "重复答题"){
  41. console.log("当前是考试页面,并允许重复提交,提交默认答案以获得正确答案");
  42. if($('.question-operation-area .btn-submit').length > 0){
  43. setTimeout(function () {
  44. console.log("考试没做,进行提交");
  45. doExam();
  46. },2000);
  47. }else{
  48. console.log("已经做了,重做");
  49. $('.question-operation-area .btn-redo').trigger('click');
  50. doExam();
  51. }
  52. }else{
  53. console.log("是考试页面,自动答题条件不符正在跳过...");
  54. // 考试界面明天再做处理吧,,,,先写个跳过的
  55. $('.next-page-btn').trigger('click');
  56. setTimeout(function () {
  57. $('.modal-operation .btn-hollow').trigger('click');
  58. setTimeout(function () {
  59. $(".btn-hollow span:contains('继续')").trigger('click');
  60. console.log("已跳过测试...");
  61. },1000);
  62. },1000);
  63. isTextPage();
  64. }
  65. }else{
  66. console.log("...");
  67. isTextPage();
  68. }
  69. },2000);
  70. }
  71. function doExam() {
  72. console.log("开始答题");
  73. //所有题目
  74. var questionList = $('.question-element-node-list .question-element-node');
  75. var choiceList = $('.choice-item ');
  76. for(var i=0;i<choiceList.length;i++){
  77. if(i%4==0){
  78. $(".choice-item:eq("+i+")").trigger('click');
  79. }
  80. }
  81. var checkList = $('.checking-type');
  82. for(var i=0;i<checkList.length;i++){
  83. if(i%2==0){
  84. $(".choice-btn:eq("+i+")").trigger('click');
  85. }
  86. }
  87. //提交题目以获取答案
  88. setTimeout(function () {
  89. $('.question-operation-area .btn-submit').trigger('click');
  90. },2000);
  91. //获取答案
  92. var answerList = [];
  93. for(var i=0;i<questionList.length;i++)
  94. answerList.push($('.correct-answer-area:eq('+i+')').text().replace("正确答案:","").replace(/[ \r\n]/g,""));
  95. //重做
  96. setTimeout(function () {
  97. $('.question-operation-area .btn-redo').trigger('click');
  98. },3000);
  99. //多选题初始化(已选择的取消选择)
  100. $('.choice-item .selected').trigger('click');
  101. var position = 0;
  102. var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
  103. for(var i=0;i<questionList.length;i++){
  104. console.log(answerList[i]);
  105. if(answerList[i].length == 1){
  106. //单选题
  107. position = swicthAnswer(answerList[i]);
  108. }else if(reg.test(answerList[i])){
  109. //有汉字 == 判断题
  110. if(answerList[i] == "正确")
  111. position = 0;
  112. else
  113. position = 1;
  114. }else{
  115. //多选题
  116. answerList[i] = answerList[i].replace(/,/g,"");
  117. // console.log(answerList[i]);
  118. for(var j=0;j<answerList[i].length+1;j++){
  119. position = swicthAnswer(answerList[i][j]);
  120. $($(questionList)[i].children[0].children[1].children[0].children[0].children[position]).trigger('click');
  121. console.log(position);
  122. }
  123. }
  124. $($(questionList)[i].children[0].children[1].children[0].children[0].children[position]).trigger('click');
  125. }
  126. //再次提交
  127. setTimeout(function () {
  128. console.log("答题完毕,提交答案");
  129. $('.question-operation-area .btn-submit').trigger('click');
  130. },3000);
  131. setTimeout(function () {
  132. console.log("等待三秒,进入下一步")
  133. },3000);
  134. isTextPage();
  135. }
  136. function swicthAnswer(inChar) {
  137. var position = 0;
  138. if(inChar == "A"){
  139. position = 0;
  140. }else if(inChar == "B"){
  141. position = 1;
  142. }else if(inChar == "C"){
  143. position = 2;
  144. }else if(inChar == "D"){
  145. position = 3;
  146. }else if(inChar == "E"){
  147. position = 4;
  148. }else if(inChar == "F"){
  149. position = 5;
  150. }else if(inChar == "G"){
  151. position = 6;
  152. }else if(inChar == "H"){
  153. position = 7;
  154. }
  155. return position;
  156. }
  157. //判断是否为纯文本页面(并延时加载)
  158. function isTextPage() {
  159. console.log("判断是否为视频节点");
  160. setTimeout(function () {
  161. if($('.page-content .page-element .video-element .jwpreview').length>0){
  162. videoNode();
  163. }else{
  164. textNode();
  165. }
  166. },3000)
  167. }
  168. //纯文本节点,,等待5秒,点击下一页
  169. function textNode(){
  170. console.log("当前是文本页面,5秒后进入下一页")
  171. setTimeout(function () {
  172. nextTime();
  173. },5000)
  174. }
  175.  
  176. //有视频节点,点击播放视频,定时检测是否播放结束 ? 下一页 : 日志
  177. function videoNode() {
  178. console.log("当前是视频页面,开始播放视频");
  179. $('.page-content .page-element .video-element .jwpreview').trigger('click');
  180. var startVideo = setInterval(function () {
  181. if($('.video-progress .text span').text() == "已看完"){
  182. clearInterval(startVideo);
  183. setTimeout(function () {
  184. nextTime();
  185. },3000)
  186. }else{
  187. console.log('还没有看完视频')
  188. }
  189. }, 3000);
  190. }
  191.  
  192. function nextTime() {
  193. $('.next-page-btn').trigger('click');
  194. isExamPage();
  195. }
  196.  
  197. init();

QingJ © 2025

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