wsxy_windowToTab

网上学院函数库:弹出窗口改为新标签页

当前为 2020-02-03 提交的版本,查看 最新版本

此脚本不应直接安装,它是供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/395997/769708/wsxy_windowToTab.js

  1. // ==UserScript==
  2. // @name wsxy_windowToTab
  3. // @namespace Vionlentmonkey
  4. // @version 0.4
  5. // @description 网上学院函数库:弹出窗口改为新标签页
  6. // @require https://greasyfork.org/scripts/395748-wsxy-getdata/code/wsxy_getData.js
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. // 快捷键批量打开听课页面所调用函数
  11. const openTrains = () => {
  12. let trains = '';
  13. // 首页 iframe
  14. if (location.pathname.includes('homepage.jsp')) {
  15. trains = document.getElementsByClassName('course');
  16. }
  17. // 培训课程查询 iframe
  18. if (location.pathname.includes('course_query.jsp')) {
  19. trains = document.querySelectorAll('#trainCourseList a[onclick^=bindBeginTrainEvents]');
  20. }
  21. let i = 0;
  22. for (let train of trains) {
  23. let applyPk = '';
  24. // 首页 iframe
  25. if (location.pathname.includes('homepage.jsp')) {
  26. // 报名后不再隐藏
  27. applyPk = train.getElementsByClassName('applyPk')[0].textContent;
  28. }
  29. // 培训课程查询 iframe
  30. if (location.pathname.includes('course_query.jsp')) {
  31. applyPk = train.getAttribute('onclick').split('"')[1];
  32. }
  33. if (applyPk !== '') {
  34. let trainURL =
  35. location.origin +
  36. '/sfxzwsxy/jypxks/modules/train/ware/course_ware_view.jsp?applyPk=' +
  37. applyPk +
  38. '&courseType=1';
  39. GM_openInTab(trainURL, true);
  40. i++;
  41. // 疑似超过 6 个课程同时学习后台不计数
  42. if (i >= GM_config.get('batch')) {
  43. console.log(`已批量打开${i}个课程`);
  44. return;
  45. }
  46. }
  47. }
  48. };
  49.  
  50. /** 最新知识库。
  51. * 年终考试题库在此公布,需要层层打开 iframe 最终获取 swf 地址,然后以 IE 打开,
  52. * 打印所有页,输出 PDF,二次打印输出 PDF,再用 Word 等进行 OCR。
  53. */
  54. const openKnowledge = () => {
  55. const knowledges = document.querySelectorAll('#knowledgeType a[title][href="#"]');
  56. for (let knowledge of knowledges) {
  57. const kURL =
  58. location.origin +
  59. '/sfxzwsxy/jypxks/modules/learn/document/learn/document_learn_text.jsp?fkNodePk=' +
  60. knowledge
  61. .getAttribute('onclick')
  62. .split('(')[1]
  63. .split(')')[0];
  64. //console.log(kURL);
  65. knowledge.href = kURL;
  66. knowledge.onclick = '';
  67. knowledge.target = '_blank';
  68. }
  69. };
  70.  
  71. // 清理两处“参加考试”按钮,使其点击时在新标签页打开考题及答案。
  72. const handelExamList = async exams => {
  73. for (let exam of exams) {
  74. const examURL = location.origin + '/sfxzwsxy/' + exam.getAttribute('onclick').split("'")[1];
  75. exam.href = examURL;
  76. exam.onclick = '';
  77. exam.target = '_blank';
  78. let course_pk = '';
  79. let answerURL = '';
  80. // 在线考试 - 课程考试 iframe
  81. if (examURL.includes('course_pk=')) {
  82. coursePk = examURL.split('course_pk=')[1].split('&')[0];
  83. answerURL =
  84. location.origin +
  85. '/sfxzwsxy//jypxks/modules/train/course/subject_list.jsp?coursePk=' +
  86. coursePk +
  87. '&op=view';
  88. }
  89. // 首页 - 考试提醒 - 课程考试
  90. else if (exam.getAttribute('title')) {
  91. const csDataObj = await getCourseData();
  92. const exam_courses = csDataObj.exam_courses;
  93. const title = exam.getAttribute('title');
  94. for (let e of exam_courses) {
  95. if (e.course_name === title) {
  96. course_pk = String(e.course_pk);
  97. answerURL =
  98. location.origin +
  99. '/sfxzwsxy//jypxks/modules/train/course/subject_list.jsp?coursePk=' +
  100. course_pk +
  101. '&op=view';
  102. }
  103. }
  104. }
  105. exam.addEventListener('click', () => {
  106. GM_openInTab(answerURL, true);
  107. GM_notification('答案已同步在隔壁标签页打开。\n暂请考试结束后手动关闭。');
  108. });
  109. }
  110. };
  111.  
  112. // 培训课程查询 iframe 清理“参加培训”和“查看”链接
  113. const inquireList = () => {
  114. let trains = document.querySelectorAll('#trainCourseList a[onclick^=bindBeginTrainEvents]');
  115. for (let train of trains) {
  116. let applyPk = train.getAttribute('onclick').split('"')[1];
  117. let trainURL =
  118. location.origin +
  119. '/sfxzwsxy/jypxks/modules/train/ware/course_ware_view.jsp?applyPk=' +
  120. applyPk +
  121. '&courseType=1';
  122. train.href = trainURL;
  123. train.onclick = '';
  124. train.target = '_blank';
  125. }
  126. let infos = document.querySelectorAll('#trainCourseList a[onclick^=bindViewCourseInfoEvents]');
  127. for (let info of infos) {
  128. let coursePk = info.getAttribute('onclick').split('"')[1];
  129. let infoURL =
  130. location.origin +
  131. '/sfxzwsxy/jypxks/modules/train/course/course_view.jsp?coursePk=' +
  132. coursePk;
  133. info.href = infoURL;
  134. info.onclick = '';
  135. info.target = '_blank';
  136. }
  137. };
  138.  
  139. // 培训课程查询 - 查看 - 题干 iframe
  140. const viewSubject = () => {
  141. const subjects = document.querySelectorAll('a[onclick^=viewSubject]');
  142. for (let subject of subjects) {
  143. const subjectPk = subject
  144. .getAttribute('onclick')
  145. .split('(')[1]
  146. .split(')')[0];
  147. const subjectURL =
  148. location.origin +
  149. '/sfxzwsxy//jypxks/modules/train/course/subject_view.jsp?subjectPk=' +
  150. subjectPk;
  151. subject.href = subjectURL;
  152. subject.onclick = '';
  153. subject.target = '_blank';
  154. }
  155. };