Skip to content

Instantly share code, notes, and snippets.

@xtagon
Last active December 11, 2015 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtagon/3fc1abc1713128245896 to your computer and use it in GitHub Desktop.
Save xtagon/3fc1abc1713128245896 to your computer and use it in GitHub Desktop.
"YouTube Kid Mode" for Tampermonkey
// ==UserScript==
// @name YouTube Kid Mode
// @description Don't show recommendations at the end of YouTube videos
// @version 0.1
// @namespace http://www.xtagon.com/
// @copyright 2012 Justin Workman
// @match http://www.youtube.com/watch*
// @match http://www.youtu.be/*
// @match http://youtu.be/*
// ==/UserScript==
// See http://www.reddit.com/r/SomebodyMakeThis/comments/16gtte/
function replace_video()
{
var video_id_regex = /(?:http:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g;
var embed_code_pattern = '<iframe width="640" height="390" src="http://www.youtube.com/embed/$1?rel=0" frameborder="0" allowfullscreen></iframe>';
var embed_code = window.location.href.replace(video_id_regex, embed_code_pattern);
var player_root_element = document.getElementsByClassName("player-root")[0];
player_root_element.innerHTML = embed_code;
}
// Set a short delay before replacing YouTube's player embed code
// It doesn't work without the delay, but it can probably be tweaked
setTimeout(replace_video, 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment