Skip to content

Instantly share code, notes, and snippets.

@surkin
Forked from tiffany352/gist:7266437
Last active December 2, 2021 20:38
Show Gist options
  • Save surkin/f17e6039c227ffd2d607 to your computer and use it in GitHub Desktop.
Save surkin/f17e6039c227ffd2d607 to your computer and use it in GitHub Desktop.
user script to replace HTML5 video player with VLC plugin
// ==UserScript==
// @name HTML5 video using VLC plugin
// @grant none
// @include *
// ==/UserScript==
function html5vlc(){
var videos = document.getElementsByTagName("video");
var embeds = new Array(videos.length);
for (var i = 0; i < videos.length; i++) {
var vlc = document.createElement("embed");
vlc.type = "application/x-vlc-plugin";
if (videos[i].autoplay) {
vlc.setAttribute("autoplay", videos[i].autoplay);
} else {
vlc.setAttribute("autoplay", "false");
}
if (videos[i].controls) {
vlc.setAttribute("controls", "true");
}
if (videos[i].width) {
vlc.width = videos[i].width;
}
if (videos[i].height) {
vlc.height = videos[i].height;
}
vlc.setAttribute("target", videos[i].src);
var sources = videos[i].getElementsByTagName("source");
for (var j = 0; j < sources.length; j++) {
vlc.setAttribute("target", sources[j].src);
}
let id = videos[i].getAttribute("id");
if (id) {
vlc.setAttribute("id", id);
}
let clas = videos[i].getAttribute("class");
if (clas) {
vlc.setAttribute("class", clas);
}
embeds[i] = vlc;
}
for (var i = embeds.length-1; i >= 0; i--) {
videos[i].parentNode.replaceChild(embeds[i], videos[i]);
}
}
var retry = 0;
function wait(){
if(retry++ > 100) //adjust timeout and retry value for instable connection
return;
if(document.getElementsByTagName("video").length == 0 || document.getElementsByTagName("video")[0].src == "")
setTimeout(wait,100);
else html5vlc();
}
if(window.location.href.indexOf("youtube.com") > -1)
wait();
else html5vlc();
@JIMJFOX
Copy link

JIMJFOX commented Aug 14, 2016

screen shot 2016-08-14 at 21 02 15

Newbie- what is all that 'script'? Do I copy-paste all that into "Terminal"? Then what happens?
I seem to be stuck with HTML5 player and want to try VLC, since HTML5 takes AGES to buffer even a 3-minute video.
Really, I have little idea what to do...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment