NPR.org HTML5 player

Listen to NPR without having to install Flash, downloads, no ads.

Verze ze dne 06. 03. 2016. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name NPR.org HTML5 player
  3. // @description Listen to NPR without having to install Flash, downloads, no ads.
  4. // @namespace https://greatest.deepsurf.us/users/4813-swyter
  5. // @match *://www.npr.org/player/v2/mediaPlayer.html*
  6. // @version 1
  7. // @grant GM_addStyle
  8. // @run-at document-start
  9. // ==/UserScript==
  10.  
  11. // https://api.npr.org/query?id=466555217&format=json&apiKey=MDAzMzQ2MjAyMDEyMzk4MTU1MDg3ZmM3MQ010
  12.  
  13. // http://www.npr.org/player/v2/mediaPlayer.html?action=1&t=1&islist=false&id=466555217&m=468149502
  14. // http://www.npr.org/player/v2/mediaPlayer.html?action=1&t=1&islist=false&id=468901493&m=468940337
  15. // http://www.npr.org/player/v2/mediaPlayer.html?action=1&t=1&islist=false&id=468933562&m=469337177&live=1
  16.  
  17. if (!(id = location.search.split('id=')[1].split('&')[0]))
  18. throw "Invalid identifier, it's not possible to guess what item we want.";
  19.  
  20. window.xhr = new XMLHttpRequest();
  21. xhr.open('GET', 'https://api.npr.org/query?id=' + id + '&format=json&apiKey=MDAzMzQ2MjAyMDEyMzk4MTU1MDg3ZmM3MQ010');
  22. xhr.responseType = 'json';
  23. xhr.onload = function(e)
  24. {
  25. console.log(this.response);
  26.  
  27. container = document.createElement("fieldset");
  28. selector = document.createElement("select");
  29. aplayer = document.createElement("audio");
  30.  
  31. flash_sucks = document.querySelector('#homepageFlash, body');
  32. flash_sucks.parentElement.replaceChild(container, flash_sucks);
  33.  
  34. legend = document.createElement("legend");
  35. legend.textContent = this.response.list.story[0].title.$text;
  36.  
  37. container.style.backgroundImage = "url(" + this.response.list.story[0].image[0].src + ")";
  38. aplayer.src=this.response.list.story[0].audio[0].format.mp3[0].$text;
  39. aplayer.controls=true;
  40.  
  41. selector.size=10;
  42.  
  43. audios=this.response.list.story[0].audio;
  44.  
  45. for(var entry in audios)
  46. {
  47. console.log("=> ", audios[entry]);
  48.  
  49. elem = document.createElement("option");
  50. elem.value = audios[entry].title.$text;
  51.  
  52. selector.add(new Option((entry|0 + 1) + ". " + audios[entry].title.$text + " - " + audios[entry].duration.$text, entry));
  53. }
  54.  
  55. container.appendChild(legend);
  56.  
  57. container.appendChild(selector);
  58. container.appendChild(aplayer);
  59. document.addEventListener('change', function(e)
  60. {
  61. console.log("(*)", e);
  62. });
  63. };
  64.  
  65. xhr.send();
  66.  
  67. GM_addStyle("audio, select{display:block; width:100%;} fieldset {padding-left:200px;}");