YouTube - Mute Ads

Automatically mutes VideoAds

当前为 2015-10-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube - Mute Ads
  3. // @name:de YouTube - Mute Ads
  4. // @version 1.0.2
  5. // @description Automatically mutes VideoAds
  6. // @description:de Schaltet Werbung auf YouTube automatisch stumm
  7. // @autor VVind0wM4ker
  8. // @namespace https://github.com/VVind0wM4ker/Userscripts
  9. // @license MIT License
  10. // @grant none
  11. // @include http*://*.youtube.com/watch*
  12. // ==/UserScript==
  13.  
  14.  
  15. var adPlaying = 0;
  16. var interval = 500
  17. var vid = document.getElementsByClassName("video-stream html5-main-video")[0];
  18.  
  19. var timer, adTimeout;
  20.  
  21.  
  22. vid.onplay = function() {startTimer();};
  23. vid.onpause = function() {pauseTimer();};
  24. var muteAds = function () {
  25. //console.log("check for Ads") //for testing
  26. if (document.getElementsByClassName("ad-showing").length > 0) {
  27. adPlaying = 1;
  28. vid.mute();
  29. }
  30. else {
  31. if (adPlaying == 1) {
  32. adPlaying = 0;
  33. vid.unMute();
  34. }
  35. }
  36. };
  37.  
  38.  
  39.  
  40. function pauseTimer () {
  41. clearInterval(timer);
  42. clearTimeout(adTimeout);
  43. }
  44.  
  45. function startTimer () {
  46. clearInterval(timer);
  47. clearTimeout(adTimeout);
  48. timer = setInterval(muteAds, interval);
  49. }