🏠 Home 

🧰蓝墨云工具箱 Mosoteach Toolkit

让蓝墨云更加强大、易用!Make Mosoteach more powerful & user-friendly !


安装此脚本?
  1. // ==UserScript==
  2. // @name 🧰蓝墨云工具箱 Mosoteach Toolkit
  3. // @namespace https://blog.younnt.one
  4. // @version 1.4.6
  5. // @license MIT
  6. // @description 让蓝墨云更加强大、易用!Make Mosoteach more powerful & user-friendly !
  7. // @author Younntone
  8. // @match https://www.mosoteach.cn/web/index.php?c=interaction_quiz&m=person_quiz_r###lt&clazz_course_id=*&id=*&order_item=group&user_id=*
  9. // @match https://www.mosoteach.cn/web/index.php?c=interaction_quiz&m=person_quiz_r###lt&clazz_course_id=*&id=*&order_item=group
  10. // @match https://www.mosoteach.cn/web/index.php?c=interaction_quiz&m=reply&clazz_course_id=*&id=*&order_item=group
  11. // @match https://www.mosoteach.cn/web/index.php?c=*&m=index&clazz_course_id=*
  12. // @match https://www.mosoteach.cn/web/index.php?c=res&m=index&clazz_course_id=*
  13. // @grant none
  14. // ==/UserScript==
  15. (function () {
  16. 'use strict';
  17. // 获取 当前页面
  18. const a = $('<a>', { href: window.location.search });
  19. const c = a.prop('search').split('?c=')[1].split('&')[0];
  20. const m = a.prop('search').split('&m=')[1].split('&')[0];
  21. if (m == 'index') {
  22. let classes = $('.cc-name')[0].children[0].innerText;
  23. $('.cc-name')[0].children[0].innerText = $(
  24. '.cc-name'
  25. )[0].children[2].innerText;
  26. $('.cc-name')[0].children[2].innerText = classes;
  27. }
  28. // 获取 课程 id
  29. let clazzCourseId = a
  30. .prop('search')
  31. .split('&clazz_course_id=')[1]
  32. .split('&')[0];
  33. // 判断 当前页面
  34. switch (c) {
  35. case 'interaction':
  36. /**
  37. * *---------------------------------------*
  38. * * 为 已结束 的 测试活动 添加直接查看分析的按钮 *
  39. * *---------------------------------------*
  40. */
  41. // 获取 活动节点集合
  42. let activities = $('.interaction-row');
  43. // 遍历所有活动
  44. for (let index = 0; index < activities.length; index++) {
  45. const activity = activities[index];
  46. const activityType = activity.getAttribute('data-type');
  47. const quizStatus =
  48. activity.children[1].children[0].children[0].className;
  49. // 判断 每个活动节点是否为测试
  50. if (activityType === 'QUIZ') {
  51. let id = activity.getAttribute('data-id');
  52. // 如果 是测试并且已经结束
  53. if (quizStatus === 'interaction-status end') {
  54. // 添加 直接打开分析页面的按钮
  55. let url = `https://www.mosoteach.cn/web/index.php?c=interaction_quiz&m=person_quiz_r###lt&clazz_course_id=${clazzCourseId}&id=${id}&order_item=group`;
  56. let button = document.createElement('div');
  57. button.className = 'interaction-status processing';
  58. button.innerText = '习题分析';
  59. button.addEventListener('click', () => {
  60. window.open(url);
  61. event.stopPropagation();
  62. });
  63. activity.children[1].children[0].appendChild(button);
  64. }
  65. // 如果 是测试并且本地有答案
  66. if (JSON.parse(window.localStorage.getItem(id))) {
  67. let button = document.createElement('div');
  68. button.className = 'interaction-status processing';
  69. button.innerText = '有答案';
  70. activity.children[1].children[0].appendChild(button);
  71. }
  72. }
  73. }
  74. break;
  75. case 'interaction_quiz':
  76. /**
  77. * *-------------------------------------*
  78. * * 为 测试分析 添加导出全部题目到粘贴板的按钮 *
  79. * *-------------------------------------*
  80. */
  81. const id = a.prop('search').split('&id=')[1].split('&')[0];
  82. if (m === 'reply') {
  83. $('[style="text-align:center;"]').attr(
  84. 'style',
  85. 'position: sticky;text-align:center;bottom: 100px;'
  86. );
  87. let _answersList = JSON.parse(window.localStorage.getItem(id));
  88. let quizList = $('.student-topic-row');
  89. // 创建标示
  90. var copyButton = document.createElement('button');
  91. if (_answersList) {
  92. copyButton.innerHTML = '该测试有答案';
  93. copyButton.style =
  94. 'width: 100px;height: 50px;position: fixed;top: 400px;left: 30px;background-color: green;';
  95. copyButton.addEventListener('click', function () {
  96. for (const key in _answersList) {
  97. if (_answersList.hasOwnProperty(key)) {
  98. const answers = _answersList[key];
  99. for (let i = 0; i < quizList.length; i++) {
  100. const quiz = quizList[i];
  101. if (
  102. quiz.children[0].children[1].children[1].innerText.indexOf(
  103. key
  104. ) === 0
  105. ) {
  106. for (let j = 0; j < answers.length; j++) {
  107. const answer = answers[j];
  108. switch (answer) {
  109. case 'A':
  110. quizList[i].children[2].click();
  111. break;
  112. case 'B':
  113. quizList[i].children[3].click();
  114. break;
  115. case 'C':
  116. quizList[i].children[4].click();
  117. break;
  118. case 'D':
  119. quizList[i].children[5].click();
  120. break;
  121. case 'E':
  122. quizList[i].children[6].click();
  123. break;
  124. case 'F':
  125. quizList[i].children[7].click();
  126. break;
  127. case 'G':
  128. quizList[i].children[8].click();
  129. break;
  130. case 'H':
  131. quizList[i].children[9].click();
  132. break;
  133. case 'I':
  134. quizList[i].children[10].click();
  135. break;
  136. case 'J':
  137. quizList[i].children[11].click();
  138. break;
  139. case 'K':
  140. quizList[i].children[12].click();
  141. break;
  142. case 'L':
  143. quizList[i].children[13].click();
  144. break;
  145. case 'M':
  146. quizList[i].children[14].click();
  147. break;
  148. default:
  149. break;
  150. }
  151. }
  152. }
  153. }
  154. }
  155. }
  156. });
  157. } else {
  158. copyButton.innerHTML = '该测试无答案';
  159. copyButton.style =
  160. 'width: 100px;height: 50px;position: fixed;top: 400px;left: 30px;background-color: red;';
  161. }
  162. // 挂载 按钮节点
  163. document.body.appendChild(copyButton);
  164. } else {
  165. let _answersList = JSON.parse(window.localStorage.getItem(id));
  166. // 创建 按钮节点
  167. var copyButton = document.createElement('button');
  168. if (_answersList) {
  169. copyButton.innerHTML = '该测试已有答案,导出试题';
  170. copyButton.style =
  171. 'width: fit-content;padding: 30px;height: 50px;position: fixed;top: 400px;left: 30px;background-color: green;';
  172. } else {
  173. copyButton.innerHTML = '该试题无答案,点击导出试题并保存答案';
  174. copyButton.style =
  175. 'width: fit-content;padding: 30px;height: 50px;position: fixed;top: 400px;left: 30px;background-color: red;';
  176. }
  177. copyButton.addEventListener('click', function () {
  178. getQuiz(id);
  179. });
  180. // 挂载 按钮节点
  181. document.body.appendChild(copyButton);
  182. }
  183. break;
  184. case 'res':
  185. /**
  186. * *-------------------------------------*
  187. * * 为 资源 添加是否可拖动进度条开关 *
  188. * *-------------------------------------*
  189. */
  190. const dragSwitch = $(
  191. '<i class="icon-ok-circle" id="dragable" style="margin-left: 10px;"></i><span>视频进度可拖拽</span>'
  192. );
  193. $('div[data-mime=video]').attr('data-drag', 'Y');
  194. dragSwitch.click(() => {
  195. if ($('#dragable').attr('class') == 'icon-circle-blank') {
  196. $('#dragable').attr('class', 'icon-ok-circle');
  197. $('div[data-mime=video]').attr('data-drag', 'Y');
  198. } else {
  199. $('#dragable').attr('class', 'icon-circle-blank');
  200. $('div[data-mime=video]').attr('data-drag', 'N');
  201. }
  202. });
  203. $("div[style='display:inline-block;']").after(dragSwitch);
  204. /**
  205. * *-------------------------------------*
  206. * * 点开视频再关闭即可实现看完 *
  207. * *-------------------------------------*
  208. */
  209. $.ajaxSetup({
  210. beforeSend: function () {
  211. console.log(arguments[1].data);
  212. let data = arguments[1].data;
  213. let encodedData = '';
  214. for (const key in data) {
  215. if (data.hasOwnProperty(key)) {
  216. let value = data[key];
  217. if (key.includes('watch_to')) {
  218. value = data.duration;
  219. }
  220. encodedData = encodedData.concat(`&${key}=${value}`);
  221. }
  222. }
  223. arguments[1].data = encodedData.substring(1, encodedData.length);
  224. },
  225. processData: false,
  226. });
  227. break;
  228. default:
  229. break;
  230. }
  231. const getQuiz = (id) => {
  232. const quizTitle = $('.info-con')[0].children[0].innerText;
  233. const quizCollection = $('.topic-item');
  234. const quizAnswerCollection = $('.answer-l');
  235. let quizList = [];
  236. let answerList = {};
  237. // 获取 所有题目
  238. for (let quizIndex = 0; quizIndex < quizCollection.length; quizIndex++) {
  239. const quiz = quizCollection[quizIndex];
  240. const num = quiz.children[0].children[0].innerHTML;
  241. const question =
  242. quiz.children[0].children[1].children[1].children[0].innerText;
  243. const optionCount =
  244. quiz.children[0].children[1].children[2].childElementCount;
  245. let options = [];
  246. // 获取 该题所有选项
  247. for (let optionIndex = 0; optionIndex < optionCount; optionIndex++) {
  248. const optionMark =
  249. quiz.children[0].children[1].children[2].children[optionIndex]
  250. .children[0].innerText;
  251. const option =
  252. quiz.children[0].children[1].children[2].children[optionIndex]
  253. .children[1].innerText;
  254. options.push(`
  255. ${optionMark} ${option}`);
  256. }
  257. // 获取 答案
  258. let answer = quizAnswerCollection[quizIndex].children[0].innerHTML;
  259. quizList.push(`
  260. ${num}. ${question} ${answer}
  261. ${options}`);
  262. answerList[question] = answer;
  263. }
  264. // 整理内容
  265. var detail = `题目标题: ${quizTitle}
  266. 题目总数: ${quizCollection.length}
  267. 题目: ${quizList}
  268. `;
  269. var oInput = document.createElement('textarea');
  270. oInput.value = detail;
  271. document.body.appendChild(oInput);
  272. oInput.select();
  273. document.execCommand('Copy');
  274. oInput.className = 'oInput';
  275. oInput.style.display = 'none';
  276. alert('已复制到粘贴板');
  277. window.localStorage.setItem(id, JSON.stringify(answerList));
  278. copyButton.style =
  279. 'width: fit-content;padding: 30px;height: 50px;position: fixed;top: 400px;left: 30px;background-color: green;';
  280. };
  281. })();