YouTube | Stop Autoplay

Disabled automatic playback ("Autoplay") of YouTube videos.

目前为 2018-07-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube | Stop Autoplay
  3. // @namespace de.sidneys.userscripts
  4. // @homepage https://gist.githubusercontent.com/sidneys/0a5bea36f989d445cdfbd776023a94ca/raw/
  5. // @version 1.0.0
  6. // @description Disabled automatic playback ("Autoplay") of YouTube videos.
  7. // @author sidneys
  8. // @icon https://www.youtube.com/favicon.ico
  9. // @include http*://www.youtube.com/*
  10. // @require https://greasyfork.org/scripts/38888-greasemonkey-color-log/code/Greasemonkey%20%7C%20Color%20Log.js
  11. // @run-at document-end
  12. // ==/UserScript==
  13.  
  14. /**
  15. * @external
  16. */
  17. /* global DEBUG */
  18.  
  19. /**
  20. * @default
  21. * @constant
  22. */
  23. DEBUG = false
  24.  
  25.  
  26. /**
  27. * @default
  28. * @constant
  29. */
  30. const urlPath = '/watch'
  31.  
  32.  
  33. /**
  34. * Stop YouTube Video Player
  35. * @param {Element} element - YouTube Video Player
  36. */
  37. let stopPlayback = () => {
  38. console.debug('stopPlayback')
  39.  
  40. const player = document.querySelector('.html5-video-player')
  41.  
  42. player.stopVideo()
  43. player.showControls()
  44.  
  45. // DEBUG
  46. console.debug('playerState:', player.getPlayerState())
  47. console.debug('videoTitle:', player.getVideoData().title)
  48. }
  49.  
  50.  
  51. /**
  52. * Init
  53. */
  54. let init = () => {
  55. console.info('init')
  56.  
  57. // Check URL
  58. if (!location.pathname.startsWith(urlPath)) { return }
  59.  
  60. stopPlayback()
  61. }
  62.  
  63.  
  64. /**
  65. * @listens window:Event#load
  66. */
  67. window.addEventListener('load', () => {
  68. console.debug('window#load')
  69.  
  70. init()
  71. })
  72.  
  73. /**
  74. * @listens window:Event#spfdone
  75. */
  76. window.addEventListener('spfdone', () => {
  77. console.debug('window#spfdone')
  78.  
  79. init()
  80. })