Oh, and here's a modular version of the updated JavaScriptKit method:
Code:
<!DOCTYPE html>
<html>
<head>
<title>Simple YQL Modular Version</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div id="qznews"></div>
<div id="nbcnews"></div>
<script>
function parsefeed(cfig, c){
var numretries = 30; // increase this number (number of retries) if you're still having problems
//////// No Need To Edit Beyond Here Unless You Want To /////////
var counter = typeof c === 'number'? c : numretries;
var head = document.getElementsByTagName('head')[0];
var s = document.createElement('script');
window["callback_" + cfig.id + (--counter)] = function(r){
head.removeChild(s);
if(r && r.query && r.query.count === 0 && counter > 0){
return parsefeed(cfig, counter);
}
window.console && console.log(cfig.id + ': ' + counter); // for optional diagnostic info - may be removed or commented out
//r now contains the result of the YQL Query as a JSON
var feedmarkup = '<p>', i = -1;
var feed = r.query.results.item // get feed as array of entries
while (++i < feed.length){
feedmarkup += '<a href="' + feed[i].link + '">';
feedmarkup += feed[i].title + '</a><br />';
feedmarkup += feed[i].description + '</p>';
}
document.getElementById(cfig.id).innerHTML = feedmarkup;
};
var baseurl = "https://query.yahooapis.com/v1/public/yql?q=";
s.src = baseurl + encodeURIComponent(cfig.query) + "&format=json&callback=callback_" + cfig.id + counter;
head.append(s);
}
parsefeed({id: 'qznews', query: 'select * from rss(0,5) where url = "http://qz.com/feed/"'});
parsefeed({id: 'nbcnews', query: 'select * from rss(0,5) where url = "http://feeds.nbcnews.com/feeds/topstories"'});
</script>
</body>
</html>
Bookmarks