学堂云答题助手

学堂云4.0答案查询

  1. // ==UserScript==
  2. // @name 学堂云答题助手
  3. // @namespace Violentmonkey Scripts
  4. // @match scut.yuketang.cn/pro/lms/*
  5. // @version 0.7
  6. // @author cat1007
  7. // @grant GM_xmlhttpRequest
  8. // @require https://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js
  9. // @require https://unpkg.com/axios/dist/axios.min.js
  10. // @description 学堂云4.0答案查询
  11. // ==/UserScript==
  12.  
  13. var url
  14. var paraList
  15. var sign
  16. var classroomId
  17. var id
  18.  
  19. var probs = []
  20. var ans = []
  21. var lid
  22.  
  23. function showPlane() {
  24. var area = $('<div id="area" style="position: fixed;right: 20px;top: 70px;width: 300px;background-color: #ffffff; padding: 10px;box-shadow: 0 1px 4px rgba(0,0,0,.1);border-radius: 4px;z-index: 100;"><button id="launch" style="padding: 10px 20px;background: #5096f5;font-size: 14px;color: #fff;border-radius: 4px;margin-right: 10px;display: block;">答题界面点击拉取答案</button><button id="speed" style="padding: 10px 20px;background: #5096f5;font-size: 14px;color: #fff;border-radius: 4px;margin-top: 10px;display: block;">速度加快速度加快<br\>(看完后刷新一下同步进度)</button><div id="plane"></div></div>')
  25. $("body").append(area)
  26. $("#launch").on("click", get)
  27. $("#speed").on("click", speedUp)
  28. }
  29.  
  30. function launch(ans) {
  31. var ul = $('<ul id="ansList"></ul>')
  32. for (let i = 0; i < ans.length; i++) {
  33. let str = "题目"+ ans[i].index + ": "
  34. for (let k = 0;k<ans[i].ansContent.length;k++) {
  35. str = str + ' ' + ans[i].ansContent[k]
  36. }
  37.  
  38. let li = $('<li style="padding: 10px 20px;font-size: 14px;"></li>').text(str)
  39. ul.append(li)
  40. }
  41. $("#plane").append(ul)
  42. $("#launch").text("切换章节后重新选择")
  43. }
  44.  
  45. function get() {
  46. url = window.location.href
  47. paraList = url.split("/")
  48.  
  49.  
  50. sign = paraList[5]
  51. classroomId = paraList[6]
  52. id = paraList[8]
  53.  
  54. $("#ansList").remove("#ansList")
  55. $("#launch").text("loading")
  56.  
  57. // 获取叶节点练习id
  58. const idApi = "https://scut.yuketang.cn/mooc-api/v1/lms/learn/leaf_info/" + classroomId + "/" + id + "/?sign=" + sign + "&term=latest&uv_id=2627"
  59.  
  60. var headers = {
  61. 'university-id': '2627',
  62. 'x-csrftoken': 'G9oqKcclwAg8eNrKzdv12EL0PNrufEXE',
  63. 'xtbz': 'cloud'
  64. }
  65.  
  66. axios.get(
  67. idApi,
  68. { headers: headers }
  69. ).then(function (response) {
  70. // 获取叶节点成功
  71. lid = response.data.data.content_info.leaf_type_id
  72. console.log(lid);
  73.  
  74. // 拉取练习列表
  75. const excApi = "https://scut.yuketang.cn/mooc-api/v1/lms/exercise/get_exercise_list/" + lid + "/?term=latest&uv_id=2627"
  76. axios.get(
  77. excApi,
  78. { headers: headers }
  79. ).then(function (response) {
  80. // 获取题目信息
  81. probs = response.data.data.problems
  82. ans = Array()
  83. console.log(probs)
  84. for (let i = 0; i < probs.length; i++) {
  85. ans.push({
  86. index: probs[i].index,
  87. ansContent: probs[i].user.answer
  88. })
  89. }
  90. launch(ans)
  91. })
  92. })
  93. }
  94.  
  95. showPlane()
  96.  
  97. // 倍速播放功能
  98. var playRate = 10
  99. var video = null
  100.  
  101. function speedUp() {
  102. console.log("speed up")
  103.  
  104. video = $(".xt_video_player")[0]
  105. setInterval(function () {
  106. video.playbackRate = playRate
  107. }, 100)
  108. }