Vertel het eerste bericht van NOS.nl




Wat gebeurt hier?

De knop draait een stukje javascript code dat het eerste bericht bovenaan de NOS pagina ophaalt en dat doorgeeft aan de text-to-speech engine via responsiveVoice.js

De code


readstory = function(){
  var topstory = 'http://query.yahooapis.com/v1/public/yql?q=select * from html where url=\'http://nos.nl/\' and xpath=\'//*[@id="topstories"]/div/div[1]/a\'&format=json&callback=?';
  var baseurl = 'http://nos.nl';
  var content = '';
  var res = '';
  var text = '';
  $.getJSON( topstory, function(data){
    baseurl = baseurl + data.query.results.a.href;
    content='http://query.yahooapis.com/v1/public/yql?q=select * from html where url=\''+baseurl+'\' and xpath=\'//*[@id="content"]/article/section/div[1]/div\'&format=json&callback=?';
    $.getJSON( content, function(data){
      res = data.query.results;
      for (i in res.div.p) {
        if (res.div.p[i].hasOwnProperty('a')){
          text = text + " " + res.div.p[i].content.replace(/\s\s/g, " "+ res.div.p[i].a.content+" ");
        } else {
          text = text + " " + res.div.p[i];
        };
      };
      responsiveVoice.speak(text, "Dutch Female");
    });
  });
  console.log(text);
}