Skip to content

Instantly share code, notes, and snippets.

@rlemon
Last active December 31, 2015 01:38
Show Gist options
  • Save rlemon/7914903 to your computer and use it in GitHub Desktop.
Save rlemon/7914903 to your computer and use it in GitHub Desktop.
SE Chat Inline YouTube UserScript - Replaces the new window youtube links with inline videos
// ==UserScript==
// @name SE Chat Inline YouTube
// @author Robert Lemon
// @version 0.1
// @namespace http://rlemon.ca
// @description Replaces the new window youtube links with inline videos
// @include http://chat.stackexchange.com/rooms/*
// @include http://chat.stackoverflow.com/rooms/*
// ==/UserScript==
function EmbedCodeOnPage(type, kode) {
var elm = document.createElement(type);
elm.textContent = kode;
document.head.appendChild(elm);
}
function EmbedFunctionOnPageAndExecute(fn) {
EmbedCodeOnPage("script", "(" + fn.toString() + ")()");
}
EmbedFunctionOnPageAndExecute(function () {
$(document).on('click', '.onebox.ob-youtube', function () {
var link = $(this).find('a'),
href = (link[0].href.match(/v\=(.*)&?/).pop()).replace(/&/, '/?');
var vid = $('<iframe>', {
width: 320,
height: 240,
frameborder: 0,
allowfullscreen: true,
src: 'http://www.youtube.com/embed/' + href
});
link.replaceWith(vid);
$(this).find('ob-youtube-overlay').remove();
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment