GYB+SYB

针对江西省补贴性线上职业技能培训官网

当前为 2021-07-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GYB+SYB
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.1
  5. // @author tao
  6. // @include https://jiangxi.zhipeizaixian.com/study/*
  7. // @description 针对江西省补贴性线上职业技能培训官网
  8. // @grant none
  9. // ==/UserScript==
  10. function queryRootClassName() {
  11. let regex = /content_wrap.*/;
  12. for (let i of document.querySelectorAll("div")) {
  13. if (regex.test(i.className)) {
  14. return i.className;
  15. }
  16. }
  17. }
  18. const regexUnitId = /unit_id=(\d.*)(&+)/;
  19.  
  20. const waitVideoList = setInterval(() => {
  21. const rootClassName = queryRootClassName();
  22. if (rootClassName == undefined) {
  23. console.log("等待网页加载");
  24. return;
  25. }
  26. const linkTagList = document.querySelectorAll("." + rootClassName + " a");
  27. const lastUnitId =
  28. linkTagList[linkTagList.length - 1].href.match(regexUnitId)[1];
  29. const check = setInterval(() => {
  30. let currentVideo = document.querySelector("video");
  31. const currentUnitId = location.search.match(regexUnitId)[1];
  32. let currnetIndex = 0;
  33. linkTagList.forEach((tag, index) => {
  34. if (
  35. (tag != undefined && tag.href != undefined) ||
  36. tag.href.indexOf("unit_id") != -1
  37. ) {
  38. let unitId = tag.href.match(regexUnitId)[1];
  39. if (unitId == currentUnitId) currnetIndex = index;
  40. }
  41. });
  42. if (currentVideo.readyState === 4) {
  43. currentVideo.play();
  44. const timeout = currentVideo.duration - currentVideo.currentTime;
  45. console.log(
  46. "共有" +
  47. linkTagList.length +
  48. "个视频,当前位于第" +
  49. currnetIndex +
  50. "个, 下一个视频在 " +
  51. timeout +
  52. " 秒后播放"
  53. );
  54. if (timeout == 0) {
  55. if (currentUnitId == lastUnitId) {
  56. console.log("视频观看结束");
  57. clearInterval(check);
  58. } else {
  59. location.href = linkTagList[currnetIndex + 1].href;
  60. }
  61. }
  62. } else {
  63. console.log("等待视频载入");
  64. }
  65. }, 1000);
  66. clearInterval(waitVideoList);
  67. }, 1000);