Skip to content

Instantly share code, notes, and snippets.

@Strikeskids
Last active February 21, 2017 06:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Strikeskids/11508607 to your computer and use it in GitHub Desktop.
Save Strikeskids/11508607 to your computer and use it in GitHub Desktop.
// ==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