Last active
February 21, 2017 06:52
-
-
Save Strikeskids/11508607 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Youtube Download Video | |
// @namespace http://www.strikeskids.com | |
// @version 0.05 | |
// @description Creates a download button on youtube videos to enable them to be downloaded | |
// @match http*://*.youtube.com/watch*v=* | |
// @copyright 2014+, Strikeskids | |
// @require http://code.jquery.com/jquery-latest.js | |
// @run-at document-end | |
// @author Strikeskids | |
// ==/UserScript== | |
function parseUrlFmt(formatted) { | |
var parts = formatted.split("&") | |
var map = {} | |
parts.forEach(function(part) { | |
var sections = part.split('='), | |
key = sections[0], | |
value = decodeURIComponent(sections[1]) | |
map[key] = value | |
}) | |
return map | |
} | |
function parseStreams() { | |
var streams = ytplayer.config.args.url_encoded_fmt_stream_map.split(",") | |
return streams.map(parseUrlFmt) | |
} | |
jQuery(function($) { | |
var streams, select, link, container; | |
container = $("#watch7-headline") | |
select = $('<select/>', { | |
on: { | |
change: function(event) { | |
link.attr('href', select.val()) | |
} | |
} | |
}).appendTo(container) | |
parseStreams().forEach(function(stream) { | |
$('<option/>', { | |
value: stream.url, | |
text: stream.quality + ' ' + stream.type.split(';')[0] | |
}).appendTo(select) | |
}) | |
link = $('<a/>', { | |
href: select.val(), | |
text: 'Download' | |
}).appendTo(container) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment