DingTalk

这是个可以自动点击钉钉酷学院的脚本。

  1. // ==UserScript==
  2. // @name DingTalk
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description 这是个可以自动点击钉钉酷学院的脚本。
  6. // @author xiaokai
  7. // @match https://pro.coolcollege.cn/*
  8. // @match https://learning.coolcollege.cn/*
  9. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. window.isDOMLoaded = false;
  14. window.isDOMRendered = false;
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. var whiteList = ['course/management', 'course/enterpriseCourse', 'course/watch']
  20. var notMatchList = ['#/landing', '#/index']
  21. var playVideoTimer, onPauseCount = 0
  22. var currentUrl = location.href
  23.  
  24. getCurrentProject(3)
  25.  
  26. window.addEventListener('hashchange', hashchangeHandler)
  27.  
  28. if (currentUrl.indexOf('https://learning.coolcollege.cn') > -1 && currentUrl.indexOf('#/home') > -1) {
  29. location.href = '#/course/management'
  30. }
  31.  
  32. function hashchangeHandler (e) {
  33. var newUrl = e.newURL
  34. if (notMatchList.find(u => newUrl.indexOf(u) > -1)) {
  35. return false
  36. }
  37. if (
  38. !whiteList.find(u => newUrl.indexOf(u) > -1)
  39. ) {
  40. location.href = 'https://learning.coolcollege.cn/#/course/management'
  41. } else if (location.href.indexOf(whiteList[0]) > -1){
  42. getCurrentProject()
  43. }
  44. }
  45.  
  46. function tryPageReady (retryCount = 1000) {
  47. setTimeout(() => {
  48. if (!whiteList.find(u => location.href.indexOf(u) > -1) && retryCount > 0) {
  49. return tryPageReady(retryCount - 1)
  50. } else {
  51. getCurrentProject()
  52. }
  53. }, 1000)
  54. }
  55.  
  56. function nextPage (retryCount = 3) {
  57. var nextBtn = document.querySelector('.ant-pagination-next')
  58. if (nextBtn) {
  59. nextBtn.click()
  60. setTimeout(() => {
  61. getCurrentProject()
  62. }, 3000)
  63. } else if (retryCount > 0) {
  64. setTimeout(function () {
  65. nextPage(retryCount - 1)
  66. }, 2000)
  67. }
  68. }
  69. function getCurrentProject (retryCount = 3) {
  70. setTimeout(() => {
  71. if (location.href.indexOf('course/management') > -1) {
  72. var finished = true
  73. var projectList = document.querySelectorAll('.course-card__cover-box')
  74. if (!projectList && retryCount > 0) {
  75. return getCurrentProject(retryCount - 1)
  76. }
  77. var currentProjectIdx = 0
  78. projectList = [].slice.call(projectList || [])
  79.  
  80. for (var i = 0; i < projectList.length; i++) {
  81. var status = projectList[i].querySelector('.course-card__cover-box__status').innerText
  82. if (status && status.trim() === '已学完') {
  83. continue
  84. } else {
  85. currentProjectIdx = i
  86. finished = false
  87. break
  88. }
  89. }
  90. if (finished) {
  91. return nextPage()
  92. }
  93.  
  94. projectList[currentProjectIdx].click()
  95. toLearning(3)
  96. } else if (location.href.indexOf('course/enterpriseCourse') > -1) {
  97. toLearning()
  98. } else if (location.href.indexOf('course/watch') > -1) {
  99. startPlay()
  100. } else {
  101. console.error('页面地址不对')
  102. }
  103. }, 2000)
  104. }
  105.  
  106. function toLearning (retryCount = 3) {
  107. setTimeout(() => {
  108. var start_btn = document.querySelector('.enterprise-course-top__right__start-btn .ant-btn.ant-btn-primary')
  109.  
  110. if (!start_btn && retryCount > 0) {
  111. return toLearning(retryCount - 1)
  112. }
  113.  
  114. var playList = document.querySelectorAll('.course-ware-list__item')
  115. playList = [].slice.call(playList || [])
  116. var notPlay = []
  117. for (var i = 0; i < playList.length; i++) {
  118. var progressEl = playList[i].querySelector('.ant-progress-bg')
  119. var finished = progressEl.style.width === '100%'
  120. if (!finished) {
  121. notPlay.push(i)
  122. }
  123. }
  124.  
  125. start_btn.click()
  126. startPlay(notPlay)
  127. }, 2000)
  128. }
  129.  
  130. function startPlay (notPlay = [], retryCount = 3) {
  131. setTimeout(() => {
  132. var sourceList = document.querySelectorAll('.new-watch-course-page__right__catalog__item')
  133. var currentIdx = 0
  134. var currentPlayIdx = 0
  135. if (!sourceList && retryCount > 0) {
  136. return startPlay(notPlay, 3)
  137. }
  138. sourceList = [].slice.call(sourceList || [])
  139.  
  140. for (var i = 0; i < sourceList.length; i++) {
  141. /* eslint-disable-next-line */
  142. ;((idx) => {
  143. sourceList[i].addEventListener('click', () => {
  144. currentIdx = idx
  145. notPlay = []
  146. playVideo()
  147. })
  148. })(i)
  149.  
  150. }
  151.  
  152. if (notPlay && notPlay.length) {
  153. currentIdx = notPlay[0]
  154. }
  155.  
  156. function handler (event) {
  157. console.log('ended cb', event)
  158. if (notPlay && notPlay.length && currentPlayIdx < notPlay.length - 1) {
  159. currentIdx = notPlay[++currentPlayIdx]
  160. } else {
  161. currentIdx++
  162. }
  163. if (currentIdx < sourceList.length) {
  164. sourceList[currentIdx].click()
  165. playVideo()
  166. } else {
  167. location.href = '#/course/management'
  168. getCurrentProject(3)
  169. }
  170. }
  171.  
  172. function playVideo (retryCount = 3) {
  173. if (playVideoTimer) {
  174. console.log('has play video timer')
  175. clearTimeout(playVideoTimer)
  176. }
  177. playVideoTimer = setTimeout(() => {
  178. clearTimeout(playVideoTimer)
  179. var video = document.querySelector('video')
  180. console.log('start play video')
  181. video.playbackRate = 5;
  182. console.log("5倍速启动");
  183. if (video) {
  184. console.log('has video')
  185. video.play()
  186. setTimeout(() => {
  187. if (video.paused && retryCount > 0) {
  188. console.log('retry', retryCount)
  189. playVideo(retryCount - 1)
  190. }
  191. }, 5000)
  192. video.onended = null
  193. video.onended = handler
  194. video.onpause - null
  195. video.onpause = function () {
  196. if (onPauseCount > 10) {
  197. clearTimeout(playVideoTimer)
  198. console.log('onpause 陷入死循环 超过10次')
  199. onPauseCount = 0
  200. return handler('手动播放下一个视频')
  201. }
  202. onPauseCount++
  203. console.log('on pause event')
  204. playVideo(3)
  205. }
  206. } else if (retryCount > 0) {
  207. console.log('has not video retry', retryCount)
  208. playVideo(retryCount - 1)
  209. }
  210. }, 2000)
  211. }
  212. sourceList[currentIdx] && sourceList[currentIdx].click()
  213.  
  214. playVideo()
  215. }, 2000)
  216.  
  217. }
  218. })();