Twitter video links

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

  1. // ==UserScript==
  2. // @name Twitter video links
  3. // @namespace twitter
  4. // @description Показывает прямые ссылки на видео в твиттере. Direct twitter video links showing in the bottom of the player.
  5. // @include https://twitter.com/i/videos/*
  6. // @version 2.2
  7. // @grant none
  8. // ==/UserScript==
  9. $(document).on("dataPlayerReadyEvent", function(){
  10. Number.prototype.dd = function(){ return (this<10)? '0'+this : this.toString(); }
  11. var vmap_url = ($pt=$("#playerContainer")).length == 1? ( $pt.data("config").vmap_url || '' ) : '',
  12. a_attrs = 'target="_blank" style="text-decoration: underline; color: #37f;"',
  13. $vspan = $('<span>').css({ 'position': "fixed", 'bottom': "0px", 'right': "0px",
  14. 'background-color': "#fff", 'padding': "0px 5px 2px", 'margin': "2px", }),
  15. st = $pt.data("config").source_type, ct = $pt.data("config").content_type, fl = Math.floor,
  16. sd = (dr=$pt.data("config").duration)?
  17. ' ('+[(h=fl((d=fl(dr/1000))/3600)), (m=fl((d-h*3600)/60)).dd(), (d-h*3600-m*60).dd()].join(':')+')'
  18. : '';
  19. if(vmap_url !== '' || $.inArray(st, ['consumer', 'snap-reel', 'gif']) > -1 ){
  20. if( $.inArray(ct, ['video/mp4', 'application/x-mpegURL'] ) > -1
  21. && typeof (vu = $pt.data("config").video_url) !== 'undefined' ){
  22. $vspan.append('<a '+a_attrs+' href="'+vu+'" title="'+ct+sd+'">Main video</a>&nbsp;');
  23. }
  24. if( vmap_url !== '' ){
  25. var dlm = ($vspan.text() == '')? '' : '|&nbsp;';
  26. $vspan.append(dlm+'<a '+a_attrs+' href="'+vmap_url+'">vmap.xml</a>&nbsp;')
  27. .append('<span id="progress">&#9200;</span>');
  28. $.get( vmap_url, function( vdata ) {
  29. $("#progress").remove();
  30. var mv_url = ($mf=$(vdata).find("MediaFile")).length == 1? $mf.text().replace(/[\s\n\r\t]/gm, '') : '';
  31. if( mv_url !== '' ){
  32. ct = $mf.attr("type");
  33. $vspan.append('|&nbsp;<a '+a_attrs+' href="'+mv_url+'" title="'+ct+sd+'">Main video</a>&nbsp;');
  34. }
  35. var yt_url = ($wn=$(vdata).find("tw\\:cta_watch_now, cta_watch_now")).length == 1? $wn.attr("url") : '';
  36. if( yt_url !== '' ){
  37. $vspan.append('|&nbsp;<a '+a_attrs+' href="'+yt_url+'">YouTube</a>&nbsp;');
  38. }
  39. $(vdata).find("tw\\:videoVariant, videoVariant").each(function(vidx, vidvar){
  40. if( (ct=$(vidvar).attr("content_type")) == 'video/mp4' ){
  41. var vcap = (mtch = $(vidvar).attr("url").match(/vid\/(\d+x\d+)\//)).length > 1 ?
  42. mtch[1] : $(vidvar).attr("bit_rate")+'&nbsp;bps';
  43. $vspan.append('|&nbsp;<a '+a_attrs+' href="'+$(vidvar).attr("url")+'" title="'+ct+'">'+vcap+'</a>&nbsp;');
  44. }
  45. });
  46. });
  47. }
  48. if($vspan.text() == ''){
  49. $vspan.append('<a '+a_attrs+' href="'+document.location.href+'">Can`t parse this frame</a>');
  50. }
  51. $(".error-msg-container").css('opacity', "0");
  52. $(document.body).append($vspan);
  53. }
  54. });