Disable HTML5 Videos autoplay/preload

Prevent webbrowser from automatically playing/downloading HTML5 videos

当前为 2016-03-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Disable HTML5 Videos autoplay/preload
  3. // @description Prevent webbrowser from automatically playing/downloading HTML5 videos
  4. // @namespace default
  5. // @include *
  6. // @exclude http*://www.youtube.com/*
  7. // @version 1.1
  8. // @grant none
  9. // @author Ramast Magdy (ramast dot com at gmail dot com)
  10. // ==/UserScript==
  11.  
  12. void(function() {
  13. var prevent_autoplay = function() {
  14. var videos = document.getElementsByTagName("video");
  15. var video;
  16. for (var i=0; i < videos.length; i++) {
  17. video = videos[i];
  18. video.removeAttribute("autoplay");
  19. video.removeAttribute("autobuffer");
  20. video.setAttribute("preload", "metadata");
  21. video.pause();
  22. }
  23. };
  24. // after 0.3, 1, 2 and 4 seconds
  25. // This is because sometimes video is loaded through some JS code
  26. setTimeout(prevent_autoplay, 300);
  27. setTimeout(prevent_autoplay, 1000);
  28. setTimeout(prevent_autoplay, 2000);
  29. setTimeout(prevent_autoplay, 4000);
  30. }());