Skip to content

Instantly share code, notes, and snippets.

@f99aq8ove
Created August 15, 2008 07:27
Show Gist options
  • Save f99aq8ove/5552 to your computer and use it in GitHub Desktop.
Save f99aq8ove/5552 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name youtube tweaks
// @description Add H.264 version link and .mp4 file link
// @namespace f99aq8ove.net
// @include http://*.youtube.com/watch?*
// ==/UserScript==
var video_file_url = function(fmt) {
var s = unsafeWindow.yt.getConfig("SWF_ARGS");
return "http://" + location.host + "/get_video?" +
[
"video_id=" + s.video_id,
"t=" + s.t,
"fmt=" + fmt,
].join("&");
};
$("watch-video-details-inner").appendChild(json2dom(
[
"div",
[
"a",
{ href: video_file_url(18) },
"download .mp4",
],
" ",
[
"a",
{ href: video_file_url(22) },
"download .mp4 (HD)",
],
]));
function $(e) {
return document.getElementById(e);
}
// ref: http://blog.livedoor.jp/dankogai/archives/51065972.html
function json2dom(json) {
// ["tag name", { attribute name: "attribute value" }, ..., "text node", ..., ["tag name", ...], ... ]
var i = 0;
var node = document.createElement(json[i++]);
if (json[i] instanceof Object && !(json[i] instanceof String) && !(json[i] instanceof Array)) {
var attrs = json[i++];
for (var name in attrs)
node.setAttribute(name, attrs[name]);
}
for (; i < json.length; ++i) {
if (json[i] == null)
continue;
node.appendChild((json[i] instanceof Array) ? arguments.callee(json[i]) : document.createTextNode(json[i]));
}
return node;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment