🎉【U校园、Unipus网课答案显示】支持视听说新视野读写答案显示 增加了序号和复制答案按钮

U校园题目答案显示;支持视听说、新视野;不支持单元测试

  1. // ==UserScript==
  2. // @name 🎉【U校园、Unipus网课答案显示】支持视听说新视野读写答案显示 增加了序号和复制答案按钮
  3. // @namespace gongchen,daonali
  4. // @version 3.1
  5. // @description U校园题目答案显示;支持视听说、新视野;不支持单元测试
  6. // @author gongchen,daonali
  7. // @match *://ucontent.unipus.cn/_pc_default/pc.html?*
  8. // @connect *://ucontent.unipus.cn/*
  9. // @connect unipus.cn
  10. // @grant GM_xmlhttpRequest
  11. // @run-at document-end
  12. // @require https://lib.baomitu.com/jquery/3.6.0/jquery.min.js
  13. // @require https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js
  14. // @antifeature ads 单元测试答案在app
  15. // @license MIT
  16. // ==/UserScript==
  17.  
  18. $('head').append('<link href="https://lib.baomitu.com/layui/2.6.8/css/layui.css" rel="stylesheet" type="text/css" />');
  19. $.getScript("https://lib.baomitu.com/layui/2.6.8/layui.js", function(data, status, jqxhr) {
  20. layui.use('element', function(){
  21. var element = layui.element;
  22. });
  23. layer.closeAll();
  24. show();
  25. showanswer();
  26. });
  27.  
  28. // 感谢ssmjae提供的解密代码
  29. function decryptContent(json) {
  30. if (json) {
  31. let r = json.content.slice(7)
  32. , o = CryptoJS.enc.Utf8.parse("1a2b3c4d" + json.k)
  33. , i = CryptoJS.enc.Hex.parse(r)
  34. , a = CryptoJS.enc.Base64.stringify(i)
  35. , contentJson = JSON.parse(CryptoJS.AES.decrypt(a, o, {
  36. mode: CryptoJS.mode.ECB,
  37. padding: CryptoJS.pad.ZeroPadding
  38. }).toString(CryptoJS.enc.Utf8));
  39. json = contentJson;
  40. console.log(json);
  41. }
  42. return json;
  43. }
  44.  
  45. var show = ()=>{
  46. layer.open({
  47. type: 1,
  48. area: ['500px', '600px'],
  49. offset: 'l',
  50. id: 'msgt',
  51. closeBtn: 1,
  52. title: "U校园网课助手(答案显示,支持单选、多选、填空、简答、问答)",
  53. shade: 0,
  54. maxmin: true,
  55. anim: 2,
  56. content:'<div class="layui-collapse"><div class="layui-colla-item"><h2 class="layui-colla-title">公告</h2><div class="layui-colla-content layui-show">脚本已修复普通测试答案获取,单元测试的相关答案已录入app<img src="https://d2.ananas.chaoxing.com/download/feac612889547d337f651b219c7fb219?at_=1731486793172&ak_=348c90275cd7177a97ae69b0cb0376a6&ad_=3a92768cb747ef62b8b80b1ac716fca1" width="300px" /></div>'+
  57. '</div></div>'+
  58. '<div id="content"><ul></ul><table class="layui-table"> <colgroup> <col width="100"> <col> <col> </colgroup> <thead> <tr> </tr> </thead> <tbody> </tbody> </table></div></div></div>'
  59. });
  60. }
  61.  
  62. let isShow = true
  63. var showanswer = () => {
  64. if (isShow) {
  65. let url = location.href;
  66. let arr = url.split("/");
  67. let book = arr[arr.length - 7];
  68. let unit = arr[arr.length - 2];
  69. let answer = [];
  70. GM_xmlhttpRequest({
  71. method: 'GET',
  72. url: 'https://ucontentapi.unipus.cn/course/api/content/' + book + '/' + unit + '/default/',
  73. headers: {
  74. 'X-ANNOTATOR-AUTH-TOKEN': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJvcGVuX2lkIjoidHV4NkNCQVc4aGRrcnFZdzc5SEpEWDF2aTR5Z2ptcDUiLCJuYW1lIjoiIiwiZW1haWwiOiIiLCJhZG1pbmlzdHJhdG9yIjoiZmFsc2UiLCJleHAiOjE5MDI5NzAxNTcwMDAsImlzcyI6IlI0aG03RmxQOFdvS0xaMUNmTkllIiwiYXVkIjoiZWR4LnVuaXB1cy5jbiJ9.CwuQmnSmIuts3hHAMf9lT954rKHXUNkps-PfRJp0KnU'
  75. },
  76. timeout: 5000,
  77. onload: function(xhr) {
  78. if (xhr.status == 200) {
  79. let el = '<tr class="layui-bg">' + '</td></tr>';
  80. console.log('https://ucontentapi.unipus.cn/course/api/content/' + book + '/' + unit + '/default/');
  81. console.log(xhr.responseText);
  82. let obj = JSON.parse(xhr.responseText) || {};
  83. let deObj = decryptContent(obj);
  84. let keyList = Object.keys(deObj);
  85. console.log(keyList);
  86. Array.prototype.contains = function(obj) {
  87. var index = this.length;
  88. while (index--) {
  89. if (this[index] === obj) {
  90. return true;
  91. }
  92. }
  93. return false;
  94. };
  95.  
  96. let questionNumber = 1; // 用于题目序号
  97.  
  98. // 选择题
  99. if (keyList.contains('questions:questions')) {
  100. let questionList = deObj['questions:questions'].questions;
  101. for (let question of questionList) {
  102. let result = '';
  103. if (question.answers) {
  104. result += question.answers.join(' ');
  105. }
  106. el += '<td>' + questionNumber + '. ' + result + question.analysis.html +
  107. ' <button class="copyBtn" data-answer="' + result + '">复制答案</button></td></td></tr>';
  108. questionNumber++;
  109. }
  110. }
  111. // 简答题
  112. if (keyList.contains('shortanswer:shortanswer')) {
  113. let questionList = deObj['shortanswer:shortanswer'].questions;
  114. for (let question of questionList) {
  115. let content = question.content.html;
  116. el += '<td>' + questionNumber + '. ' + deObj['shortanswer:shortanswer'].analysis.html + content + question.analysis.html +
  117. ' <button class="copyBtn" data-answer="' + content + '">复制答案</button></td></td></tr>';
  118. questionNumber++;
  119. }
  120. }
  121. // 填空题
  122. if (keyList.contains('questions:scoopquestions')) {
  123. let questionList = deObj['questions:scoopquestions'].questions;
  124. for (let question of questionList) {
  125. let result = '';
  126. if (question.answers) {
  127. result += question.answers.join(' ');
  128. }
  129. el += '<td>' + questionNumber + '. ' + result + question.analysis.html +
  130. ' <button class="copyBtn" data-answer="' + result + '">复制答案</button></td></td></tr>';
  131. questionNumber++;
  132. console.log(el);
  133. }
  134. }
  135. // 短回答题
  136. if (keyList.contains('questions:shortanswer')) {
  137. let questionList = deObj['questions:shortanswer'].questions;
  138. for (let question of questionList) {
  139. let result = '';
  140. if (question.answers) {
  141. result += question.answers.join(' ');
  142. }
  143. el += '<td>' + questionNumber + '. ' + result + question.analysis.html +
  144. ' <button class="copyBtn" data-answer="' + result + '">复制答案</button></td></td></tr>';
  145. questionNumber++;
  146. }
  147. }
  148. el += '<td>答案结束,没答案就是没适配,请使用app</td></td></tr>';
  149.  
  150. $("#content>table>tbody").append($(el));
  151.  
  152. // 绑定复制按钮事件
  153. $('.copyBtn').on('click', function() {
  154. let answerToCopy = $(this).data('answer');
  155. navigator.clipboard.writeText(answerToCopy).catch(() => {
  156. alert('复制失败,请手动复制');
  157. });
  158. });
  159. }
  160. }
  161. });
  162. }
  163. isShow = !isShow;
  164. }
  165.  
  166.  
  167.  
  168. window.onhashchange=()=>{
  169. $("#content>table>tbody").empty();
  170. showanswer();
  171. }

QingJ © 2025

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