HTML5 player for BBC News

Use a natively uncluttered hardware-accelerated player, no ads or annoyances. Also, easily downloadable videos.

目前为 2015-07-16 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name HTML5 player for BBC News
  3. // @match http://www.bbc.com/*
  4. // @version 2015.07.16
  5. // @description Use a natively uncluttered hardware-accelerated player, no ads or annoyances. Also, easily downloadable videos.
  6. // @grant GM_xmlhttpRequest
  7. // @namespace https://greasyfork.org/users/4813
  8. // ==/UserScript==
  9.  
  10.  
  11. for (var i in (src = document.querySelectorAll('script:not([src])')))
  12. {
  13. if (typeof src[i] !== 'object' || src[i].textContent.indexOf('externalId') === -1)
  14. {
  15. continue;
  16. }
  17.  
  18. var vpid = src[i].textContent.match(/externalId":"([^"]+)"/)[1];
  19.  
  20. console.log(i, vpid);
  21. }
  22.  
  23. if (!vpid)
  24. throw 'BBC HTML5: nothing to do :)';
  25.  
  26. GM_xmlhttpRequest(
  27. {
  28. method: 'GET',
  29. url: 'http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/vpid/' + vpid + '/format/json/mediaset/journalism-http-tablet/',
  30.  
  31. onreadystatechange: function(e)
  32. {
  33. if (e.readyState !== XMLHttpRequest.DONE)
  34. {
  35. return;
  36. }
  37.  
  38. this.responseJSON = JSON.parse(e.responseText);
  39.  
  40. /* just for taking a look, please don't mind me! :-) */
  41. console.log(e, this.responseJSON);
  42.  
  43. unsafeWindow.cock = e.responseText;//this.responseJSON;
  44.  
  45. if (!this.responseJSON.media)
  46. {
  47. console.warn('BBC HTML5: the listing did not come with any video at all!', this.responseJSON); return;
  48. }
  49.  
  50. /* add a download button per result video */
  51. for(var vid in this.responseJSON.media)
  52. {
  53. //console.log("=>", vid, this.responseJSON.media, this.responseJSON.media[vid], this.responseJSON.media[vid].connection[0].href);
  54.  
  55. console.log("=>", vid, this.responseJSON.media[vid].width,
  56. this.responseJSON.media[vid].height,
  57. this.responseJSON.media[vid],
  58. this.responseJSON.media[vid].connection[0].href);
  59.  
  60. /*
  61. dwnbutton = document.createElement("a");
  62. dwnbutton.setAttribute('style', 'padding-left: 35px; padding-right:12px');
  63.  
  64. dwnbutton.textContent = 'Descargar [' + vid + ']';
  65. dwnbutton.className = 'mar-l_10 fn_slide_link left btn_black icon_35 descarga';
  66. dwnbutton.href = this.responseJSON.media[vid];
  67. dwnbutton.download = document.querySelector('#imagen_modulo_player > img').alt + '.' + vid + '.mp4';
  68.  
  69. / / * replace it on the page * / /
  70. dwnbuttonHolderElement = document.querySelector('.mod_producto_social > div > div');
  71. dwnbuttonHolderElement.appendChild(dwnbutton); */
  72. }
  73.  
  74. var hq = 2 // 0;
  75.  
  76. /* build our own html5 player with our own stuff */
  77. vplayer = document.createElement('video');
  78.  
  79. vplayer.src = this.responseJSON.media[hq].connection[0].href;
  80. vplayer.poster = document.querySelector('#media-asset-placeholder').src;
  81.  
  82. vplayer.controls = 'true';
  83. vplayer.autoplay = 'false';
  84. vplayer.preload = 'none';
  85.  
  86. vplayer.volume = '0.4';
  87.  
  88. vplayer.style.width = '100%';
  89.  
  90. /* replace it on the page */
  91. videoHolderElement = document.querySelector('#media-asset-page-video');
  92. videoHolderElement.parentElement.replaceChild(vplayer, videoHolderElement);
  93. },
  94.  
  95. onerror: function(e)
  96. {
  97. console.warn('BBC HTML5: Houston, we have an unidentified problem!', e);
  98. }
  99. });