Twitter video links

Показывает прямые ссылки на видео в твиттере. Direct twitter video links showing in the bottom of the player.

As of 2016-12-10. See the latest version.

// ==UserScript==
// @name        Twitter video links
// @namespace   twitter
// @description Показывает прямые ссылки на видео в твиттере. Direct twitter video links showing in the bottom of the player.
// @include     https://twitter.com/i/videos/*
// @version     2.1
// @grant       none
// ==/UserScript==
$(document).on("dataPlayerReadyEvent", function(){
	var astyle = "text-decoration: underline; color: #37f;",
		vmap_url = ($pt=$("#playerContainer")).length == 1? 
			( (st=$pt.data("config").source_type) === 'amplify'? $pt.data("config").vmap_url : '' ) : '',
		vd = (dr=$pt.data("config").duration)? Math.floor(dr/1000) : 0;
	Number.prototype.to2D = function(){ return (this<10)? '0' + this : this.toString(); }
	with(Math){
		vd = (vd > 0)? ' ('+[(h=floor(vd/3600)).to2D(), (m=floor((vd - h*3600)/60)).to2D(), (vd - h*3600 - m*60).to2D()].join(':')+')' : '';
	}
	if(vmap_url !== '' || $.inArray(st, ['consumer', 'snap-reel', 'gif']) > -1 ){
		var $vspan = $('<span>').css({ 'position': "fixed", 'bottom': "0px", 'right': "0px", 
			'background-color': "#fff", 'padding': "0px 5px 2px", 'margin': "2px", });
		if( $.inArray( (ct = $pt.data("config").content_type), ['video/mp4', 'application/x-mpegURL'] ) > -1 
			&& typeof (vu = $pt.data("config").video_url) !== 'undefined' ){
			$vspan.append('<a style="'+astyle+'" href="'+vu+'" target="_blank" title="'+ct+vd+'">Main video</a>&nbsp;');
		}else if( vmap_url !== '' ){
			$vspan.append('<a style="'+astyle+'" href="'+vmap_url+'" target="_blank">vmap.xml</a>&nbsp;')
				.append('<span id="progress">&#9200;</span>');
			$.get( vmap_url, function( vdata ) {
				$("#progress").remove();
				var mvid_url = ($mf = $(vdata).find("MediaFile")).length == 1? $mf.text().replace(/[\s\n\r\t]/gm, '') : '';
				if(mvid_url !== ''){
					$vspan.append('|&nbsp;<a style="'+astyle+'" href="'+mvid_url+'" target="_blank" title="'+vd+'">Main video</a>&nbsp;');
				}
				var yt_url = ($wn = $(vdata).find("tw\\:cta_watch_now, cta_watch_now")).length == 1? $wn.attr("url") : '';
				if(yt_url !== ''){
					$vspan.append('|&nbsp;<a style="'+astyle+'" href="'+yt_url+'" target="_blank">YouTube</a>&nbsp;');
				}
				$(vdata).find("tw\\:videoVariant, videoVariant").each(function(vidx, vidvar){
					if($(vidvar).attr("content_type") == 'video/mp4'){
						var vcap = (mtch = $(vidvar).attr("url").match(/vid\/(\d+x\d+)\//)).length > 1 ? mtch[1] : $(vidvar).attr("bit_rate")+'&nbsp;bps';
						$vspan.append('|&nbsp;<a style="'+astyle+'" href="'+$(vidvar).attr("url")+'" target="_blank">'+vcap+'</a>&nbsp;')
					}
				});
			});
		}else{
			$vspan.append('<a style="'+astyle+'" href="'+document.location.href+'" target="_blank">Can`t parse this frame</a>');
		}
		$(document.body).append($vspan);
		$(".error-msg-container").css('opacity', "0");
	}
});