HTML5 video using VLC plugin

html video player using vlc

  1. // ==UserScript==
  2. // @name HTML5 video using VLC plugin
  3. // @grant none
  4. // @include *
  5. // @version 0.0.1.20210525221320
  6. // @namespace https://greasyfork.org/users/776190
  7. // @description html video player using vlc
  8. // ==/UserScript==
  9. function html5vlc(){
  10. var videos = document.getElementsByTagName("video");
  11. var embeds = new Array(videos.length);
  12. for (var i = 0; i < videos.length; i++) {
  13. var vlc = document.createElement("embed");
  14. vlc.type = "application/x-vlc-plugin";
  15. if (videos[i].autoplay) {
  16. vlc.setAttribute("autoplay", videos[i].autoplay);
  17. } else {
  18. vlc.setAttribute("autoplay", "false");
  19. }
  20. if (videos[i].controls) {
  21. vlc.setAttribute("controls", "true");
  22. }
  23. if (videos[i].width) {
  24. vlc.width = videos[i].width;
  25. }
  26. if (videos[i].height) {
  27. vlc.height = videos[i].height;
  28. }
  29. vlc.setAttribute("target", videos[i].src);
  30. var sources = videos[i].getElementsByTagName("source");
  31. for (var j = 0; j < sources.length; j++) {
  32. vlc.setAttribute("target", sources[j].src);
  33. }
  34. let id = videos[i].getAttribute("id");
  35. if (id) {
  36. vlc.setAttribute("id", id);
  37. }
  38. let clas = videos[i].getAttribute("class");
  39. if (clas) {
  40. vlc.setAttribute("class", clas);
  41. }
  42. embeds[i] = vlc;
  43. }
  44. for (var i = embeds.length-1; i >= 0; i--) {
  45. videos[i].parentNode.replaceChild(embeds[i], videos[i]);
  46. }
  47. }
  48.  
  49. var retry = 0;
  50.  
  51. function wait(){
  52. if(retry++ > 100) //adjust timeout and retry value for instable connection
  53. return;
  54. if(document.getElementsByTagName("video").length == 0 || document.getElementsByTagName("video")[0].src == "")
  55. setTimeout(wait,100);
  56. else html5vlc();
  57. }
  58.  
  59. if(window.location.href.indexOf("youtube.com") > -1)
  60. wait();
  61. else html5vlc();