高校邦一键完成,自动答题静音播放

高校邦自动静音播放,自动答题,一键完成视频

  1. // ==UserScript==
  2. // @name 高校邦一键完成,自动答题静音播放
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 高校邦自动静音播放,自动答题,一键完成视频
  6. // @author Xisney
  7. // @match https://*.class.gaoxiaobang.com/class/*/unit/*/chapter/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. ;(function () {
  12. 'use strict'
  13. const executeUntilSuccess = (target, span = 500, count = 0) => {
  14. if (typeof target !== 'function' || count > 9) return
  15.  
  16. try {
  17. target()
  18. } catch (e) {
  19. setTimeout(() => {
  20. executeUntilSuccess(target, span, count + 1)
  21. }, span)
  22. }
  23. }
  24.  
  25. const listen = window.addEventListener
  26. window.addEventListener = (name, callback, options) => {
  27. if (name === 'blur') return
  28. listen(name, callback, options)
  29. }
  30.  
  31. const finishByClick = () => {
  32. if (typeof jQuery !== 'funtion') {
  33. console.error('no jquery')
  34. }
  35. const video = $('#video_player_html5_api')[0]
  36. const duration = parseInt(video.duration)
  37.  
  38. const pathArr = location.pathname.split('/')
  39. const classId = pathArr[2]
  40. const chapterId = pathArr[6]
  41.  
  42. const ct = new Date().getTime()
  43. const infoUrl = `https://cqupt.class.gaoxiaobang.com/class/${classId}/chapter/${chapterId}/api?${ct}`
  44.  
  45. $.post(infoUrl, res => {
  46. const mh = res.userRecord.maxViewTime ? res.userRecord.maxViewTime : 0
  47. const logUrl = `https://cqupt.class.gaoxiaobang.com/log/video/${chapterId}/${classId}/api?${new Date().getTime()}`
  48. $.post(
  49. logUrl,
  50. {
  51. rl: location.href,
  52. data: JSON.stringify([
  53. {
  54. state: 'listening',
  55. level: 2,
  56. ch: duration,
  57. mh,
  58. ct,
  59. },
  60. ]),
  61. },
  62. res => {
  63. if (res === 'success') {
  64. location.reload()
  65. }
  66. }
  67. )
  68. })
  69. }
  70.  
  71. const inVideoPage = () => {
  72. if (location.host.startsWith('imooc')) return
  73.  
  74. if (typeof jQuery !== 'function') {
  75. console.error('no jquery')
  76. }
  77.  
  78. const video = $('#video_player_html5_api')[0]
  79. video.volume = 0
  80. video.play()
  81.  
  82. answerQuestions()
  83.  
  84. const btn = document.createElement('button')
  85. $(btn).css({
  86. position: 'fixed',
  87. right: '50px',
  88. top: '200px',
  89. transform: 'translateY(-50%)',
  90. 'z-index': '10',
  91. })
  92. btn.innerHTML = '一键完成'
  93. btn.addEventListener('click', finishByClick)
  94. $('body').append(btn)
  95. }
  96.  
  97. const answerQuestions = () => {
  98. const observer = new MutationObserver(records => {
  99. for (let r of records) {
  100. if (r.type === 'childList') {
  101. const quizItems = $('.gxb-video-quiz-body .question-item')
  102.  
  103. if (quizItems.length === 0) return
  104.  
  105. quizItems.each(function (i) {
  106. const res = $(this)
  107. .children('.correctAnswer')[0]
  108. .getAttribute('data')
  109. .split('')
  110. .map(char => {
  111. switch (char) {
  112. case '对':
  113. return 0
  114. case '错':
  115. return 1
  116. default:
  117. return char.codePointAt(0) - 'A'.codePointAt(0)
  118. }
  119. })
  120.  
  121. const answers = $(this)
  122. .find('.answer-wap .answer')
  123. .children('i[answer_id]')
  124. res.forEach(value => {
  125. answers[value].click()
  126. })
  127.  
  128. if (i !== quizItems.length - 1) {
  129. $('.gxb-video-quiz .gxb-icon-next').click()
  130. console.log('cccsfa')
  131. }
  132. })
  133.  
  134. $('.gxb-video-quiz-footer .gxb-btn_.submit').click()
  135. setTimeout(() => {
  136. // 使得用户可感知答题结果,也确保dom更新完成
  137. $('.gxb-video-quiz-footer .gxb-btn_.player').click()
  138. }, 1000)
  139. }
  140. }
  141. })
  142.  
  143. const target = $('.player-video')[0]
  144. observer.observe(target, {
  145. childList: true,
  146. })
  147. }
  148.  
  149. executeUntilSuccess(() => {
  150. inVideoPage()
  151. })
  152. })()

QingJ © 2025

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