YouTube HTML5 AutoPause

Automatically pause YouTube HTML5 videos on Youtube

  1. // ==UserScript==
  2. // @name YouTube HTML5 AutoPause
  3. // @namespace https://gf.qytechs.cn/en/users/13981-chk1
  4. // @description Automatically pause YouTube HTML5 videos on Youtube
  5. // @include https://*.youtube.com/watch*
  6. // @include http://*.youtube.com/watch*
  7. // @version 0.3
  8. // @grant none
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. var config = {
  13. childList: true,
  14. attributes: true,
  15. subtree: true,
  16. attributeOldValue: true
  17. };
  18.  
  19. var docbody = document.body;
  20. var playBtn;
  21.  
  22. var playBtnObserver = new MutationObserver(function(mutations) {
  23. mutations.forEach(function(mutation) {
  24. if(mutation.type == "attributes"){// && mutation.oldValue == "ytp-play-button ytp-button") {
  25. //console.log(mutation);
  26. //console.log(playBtn);
  27. playBtn.click();
  28. playBtnObserver.disconnect();
  29. }
  30. });
  31. });
  32.  
  33. var bodyObserver = new MutationObserver(function(mutations) {
  34. mutations.forEach(function(mutation) {
  35. if(mutation.type == "childList" && mutation.addedNodes.length >= 1) {
  36. //console.log(mutation);
  37. var _playBtn = document.querySelector('.ytp-play-button');
  38. if(_playBtn){
  39. playBtn = _playBtn;
  40. bodyObserver.disconnect();
  41. playBtnObserver.observe(playBtn, config);
  42. }
  43. }
  44. });
  45. });
  46.  
  47. bodyObserver.observe(docbody, config);

QingJ © 2025

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