Last active
December 31, 2015 01:38
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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