Disable coursera video play when clicking transscript

Avoid paused coursera video being played when clicking transscript.

  1. // ==UserScript==
  2. // @name Disable coursera video play when clicking transscript
  3. // @description Avoid paused coursera video being played when clicking transscript.
  4. // @version 20220506
  5. // @match https://www.coursera.org/learn/*
  6. // @grant none
  7. // @author -
  8. // @run-at document-idle
  9. // @supportURL https://github.com/whtsky/userscripts/issues
  10. // @namespace https://gf.qytechs.cn/users/164794
  11. // ==/UserScript==
  12.  
  13. const noop = () => {}
  14.  
  15. const preventVideoPlay = () => {
  16. const video = document.querySelector('video')
  17. const oldVideoPlay = video.play
  18. video.play = noop
  19. video.oldPlay = oldVideoPlay
  20. }
  21.  
  22. const resumeVideoPlay = () => {
  23. const video = document.querySelector('video')
  24. video.play = video.oldPlay ?? video.play
  25. }
  26.  
  27. const check = (changes, observer) => {
  28. const transscriptDiv = document.querySelector('.rc-TranscriptHighlighter')
  29. if (transscriptDiv) {
  30. transscriptDiv.addEventListener('mouseenter', preventVideoPlay)
  31. transscriptDiv.addEventListener('mouseleave', resumeVideoPlay)
  32. }
  33. }
  34.  
  35. new MutationObserver(check).observe(document, { childList: true, subtree: true })

QingJ © 2025

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