HTML5 stop autoplay

Prevent HTML5 videos or music from autoplaying. Move mouse over player to start playing.

  1. // ==UserScript==
  2. // @name HTML5 stop autoplay
  3. // @namespace https://infovikol.ch/
  4. // @version 0.1
  5. // @description Prevent HTML5 videos or music from autoplaying. Move mouse over player to start playing.
  6. // @author Alex
  7. // @match http*://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. function stop() {
  12. this.pause();
  13. //this.currentTime=0;
  14. this.removeEventListener("timeupdate", stop, false);
  15. }
  16.  
  17. function mv() {
  18. this.removeEventListener("timeupdate", stop, false);
  19. this.removeEventListener("mouseover", mv,true);
  20. this.play();
  21. }
  22.  
  23. function loop() {
  24. tag = document.querySelectorAll('video,audio');
  25. for(i = 0; i < tag.length; i++){
  26. if(tag[i].getAttribute("paused")!=1){
  27. tag[i].autoplay=false;
  28. tag[i].controls=true;
  29. tag[i].addEventListener("timeupdate", stop, false);
  30. tag[i].addEventListener("mouseover", mv,true);
  31. tag[i].setAttribute("paused",1);
  32. }
  33. }
  34. setTimeout(function(){
  35. loop();
  36. }, 1000);
  37. }
  38.  
  39. loop();

QingJ © 2025

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