福大雨课堂刷课-数研院

a script for automating video play for 雨课堂

  1. // ==UserScript==
  2. // @name 福大雨课堂刷课-数研院
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4.2
  5. // @license MIT
  6. // @description a script for automating video play for 雨课堂
  7. // @author camerayuhang or 风刮的唉 from FZU
  8. // @match https://changjiang.yuketang.cn/v2/web/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=yuketang.cn
  10. // @grant none
  11. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. // user can change the default config manually
  16. let timeInterval = 4000; // interval for jumping to the next page
  17. let showInfoInterval = 6000; // interval for showing info on page
  18. let showInfoOnPage = true; // Whether to show the information on the page
  19.  
  20. if (showInfoOnPage) {
  21. $("body").prepend('<div class="myinfo"></div>')
  22. $(".myinfo")
  23. .css(
  24. {
  25. "border-radius": '10px',
  26. "box-sizing": 'border-box',
  27. "position": 'absolute',
  28. "right": '10px',
  29. "top": '10px',
  30. "width": '250px',
  31. "background-color": '#fff',
  32. "border": '1px solid #ccc',
  33. "padding": '10px 10px',
  34. "z-index": '99999',
  35. "overflow": "scroll",
  36. "height": "150px",
  37. "opacity": "0.5"
  38. }
  39. )
  40. }
  41. let stopInterval = (id) => {
  42. window.clearInterval(id);
  43. id = null;
  44. };
  45.  
  46. let printInfo = (str, show = true) => {
  47. if (showInfoOnPage) {
  48. if (show) {
  49. $(".myinfo").append(`<p>${str}</p>`);
  50. }
  51. }
  52. console.log(str);
  53. }
  54.  
  55.  
  56. // keep looking for scrollDown button every a few seconds until finds it
  57. let intervalForScrollDown;
  58. intervalForScrollDown = window.setInterval(() => {
  59. let btn = $("span.blue.ml20").eq(0);
  60. if (btn.length !== 0) {
  61. stopInterval(intervalForScrollDown);
  62. if (btn.text().trim() === "展开") {
  63. printInfo("展开 button will be click automatically");
  64. btn.click();
  65. }
  66.  
  67. let currentURL = window.location.href;
  68.  
  69. // look for all videoNodes
  70. let intervalForAllVideoNodes;
  71. intervalForAllVideoNodes = window.setInterval(() => {
  72. let sectionVideoNodes = $("#pane--1 .activity-info.el-tooltip use[*|href='#icon-shipin']").parent().parent().parent().parent();
  73. if (sectionVideoNodes.length >= 0) {
  74. stopInterval(intervalForAllVideoNodes);
  75.  
  76. // traverse each video nodes and check whether it is finished
  77. let done = true;
  78. for (let i = 0; i < sectionVideoNodes.length; i++) {
  79. const ele = sectionVideoNodes[i];
  80. let flagText = $(ele).children(".statistics-box").children(".aside").children().eq(1);
  81. printInfo(`the state of the ${i + 1}th video: ${flagText.text()}`);
  82. if (flagText.text() !== "已完成") {
  83. printInfo(`you have watched ${i} videos`);
  84. printInfo(`start to watch the ${i + 1}th video`);
  85. done = false;
  86. flagText.click();
  87. break;
  88. }
  89. }
  90. if (done) {
  91. window.alert("Congratulation! you've already finished all videos of this course.Please switch to another unfinished course to go on your journey!")
  92. }
  93. else {
  94. // look for video node
  95. let intervalForVideo;
  96. intervalForVideo = window.setInterval(() => {
  97. let video = $(".xt_video_player");
  98. if (video.length === 1) {
  99. stopInterval(intervalForVideo);
  100. let videoTitle = $("div.title-fl span")[0].innerText; // title
  101. let pause_btn = $("xt-bigbutton.pause_show"); // pause button
  102. if (pause_btn.length == 1) { // determine whether the button is shown
  103. pause_btn.click();
  104. }
  105. // lisen the video process
  106. let listenVideoProcess;
  107. let videoNode = video[0];
  108. listenVideoProcess = window.setInterval(() => {
  109. let w = $("span.text:eq(1)")[0]; // element for process
  110. printInfo(videoTitle + '---' + w.innerText);
  111. $(".myinfo").scrollTop($(".myinfo")[0].scrollHeight);
  112. if (w.innerText == "完成度:100%" || videoNode.ended == true) {
  113. stopInterval(listenVideoProcess);
  114. printInfo("close the interval");
  115. window.location.replace(currentURL);
  116. }
  117. }, showInfoInterval)
  118. }
  119. }, timeInterval);
  120. }
  121. }
  122. }, timeInterval);
  123. }
  124. }, timeInterval);
  125. })();

QingJ © 2025

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