f99aq8ove (owner)

Revisions

gist: 5552 Download_button fork
public
Public Clone URL: git://gist.github.com/5552.git
Embed All Files: show embed
youtube_tweaks.user.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// ==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;
}