Valid YouTube Embed

By Matthew Hill Last update Dec 30, 2010 — Installed 2,367 times.

There are 12 previous versions of this script.

// --------------------------------------------------------------------------------
//
// Valid YouTube Embed
// version 0.4 BETA
// 30-12-2010
// Copyright (c) 2010, Matthew Hill
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------------------
//
// ==UserScript==
// @name          Valid YouTube Embed
// @namespace     http://www.userscripts.org/scripts/show/68323
// @description   Provides 100% valid and semantic (XHTML 1.0 Strict & Transitional) embed code for YouTube videos.
// @include       http://www.youtube.com/watch?v=*
// ==/UserScript==
//
// ---------------------------------------- EDIT BELOW ----------------------------------------
//
// Do you want the Valid Embed Code Button to replace the original Embed Code Button? - true or false
var replaceOriginal = false
//
// ---------------------------------------- DO NOT EDIT BELOW ----------------------------------------
var embedButton, validEmbedButton;
embedButton = document.getElementById('watch-embed');
validEmbedButton = document.createElement('div');
validEmbedButton.setAttribute('style', 'display: inline; margin-right: 3px;');
validEmbedButton.innerHTML = '<button class="yt-uix-tooltip-reverse yt-uix-button yt-uix-tooltip" data-tooltip-title="Get valid video embed code" data-tooltip-timer="1507"><span class="yt-uix-button-content">Valid Embed</span></button>';
embedButton.parentNode.insertBefore(validEmbedButton, embedButton);
validEmbedButton.addEventListener('click', validEmbedTextareaShow, false)
var watchActions, validEmbedTextarea, videoUrl, videoId, video, videoWidth, videoHeight;
watchActions = document.getElementById('watch-actions');
validEmbedTextarea = document.createElement('div');
videoUrl = new String(window.location);
videoId = videoUrl.substring(31, 42);
video = document.getElementById('movie_player');
videoWidth = video.getAttribute('width', 2);
videoHeight = video.getAttribute('height', 2);
validEmbedTextarea.setAttribute('style', 'margin-bottom: 10px; display: none');
validEmbedTextarea.innerHTML = '<div id="validEmbedTextareaClose" class="close" style="margin:6px 6px 0 0"><img src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" class="master-sprite close-button" /></div><div class="yt-rounded" style="padding:10px;border:#CCC 1px solid"><textarea id="validEmbedTextarea" style="width:595px;display:block;font-family:monospace">&lt;object type="application/x-shockwave-flash" width="' + videoWidth + '" height="' + videoHeight + '" data="http://www.youtube.com/v/' + videoId + '"&gt;&lt;param name="movie" value="http://www.youtube.com/v/' + videoId + '" /&gt;&lt;/object&gt;</textarea></div>';
watchActions.parentNode.insertBefore(validEmbedTextarea, watchActions.nextSibling);
document.getElementById('validEmbedTextareaClose').addEventListener('click', validEmbedTextareaClose, false)

function validEmbedTextareaClose() {
    validEmbedTextarea.style.display = 'none'
}

function validEmbedTextareaShow() {
    if (validEmbedTextarea.style.display != 'none') {
        validEmbedTextarea.style.display = 'none'
    }
    else {
        validEmbedTextarea.style.display = '';
        document.getElementById('validEmbedTextarea').focus();
        document.getElementById('validEmbedTextarea').select()
    }
}
if (replaceOriginal == true) {
    embedButton.style.display = 'none';
	validEmbedButton.setAttribute('style', 'display: inline');
}
else {
    var watchActionsArea = document.getElementById('watch-actions-area');
    watchActionsArea.style.marginRight = '0';
    watchActionsArea.style.marginBottom = '10px';
    watchActionsArea.style.marginLeft = '0'
}
//
// --------------------------------------------------------------------------------