Skip to content

Instantly share code, notes, and snippets.

@lemenkov
Last active August 29, 2015 14:04
Show Gist options
  • Save lemenkov/158ef88f59e85d0fb4f6 to your computer and use it in GitHub Desktop.
Save lemenkov/158ef88f59e85d0fb4f6 to your computer and use it in GitHub Desktop.
This Greasemonkey script transforms all outdated LJ placeholders for YouTube videos to valid HTML5 objects
// ==UserScript==
// @name LJ HTML5
// @namespace lj-youtube-html5
// @include https://*.livejournal.com/*
// @include http://*.livejournal.com/*
// @version 1.1
// @grant none
// ==/UserScript==
function replace(frame, regexp){
var match = frame.src.match(regexp);
var youtubeid = match ? match[1] : null;
if (youtubeid) {
frame.src = "//www.youtube.com/embed/".concat(youtubeid, "?rel=0");
}
}
var frames = document.getElementsByClassName("lj_embedcontent");
for (var i = 0; i < frames.length; i++) {
var re = new RegExp("^http://l.lj-toys.com/.*vid=([^&]+)(&|$)");
replace(frames[i], re);
}
var frames = document.getElementsByTagName('iframe');
for (var i = 0; i < frames.length; i++) {
var re = new RegExp("^http://www.youtube.com/embed/([^&]+)\\?wmode=opaque(&|$)");
replace(frames[i], re);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment