/*
(c) Copyright 2014 Charlie Harvey
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
// TODO: memoize here
function tweetsFor(user,jQueryElem,fn,asHTML,handler) {
var yql = "http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20html%20WHERE%20url%3D%22https%3A%2F%2Ftwitter.com%2F"
+ user
+ "%22%20AND%20xpath%3D%22%2F%2Fdiv%5Bcontains(%40class%2C'js-stream-item')%5D%22&format=json"
$.ajax({ type: 'GET'
, url: yql
, dataType: 'jsonp'
, success: function(data, textStatus) {
if(null==data.query.results) {
alert("Couldn't retrieve anything for " + user);
return;
}
tweets = extractTweets(data.query.results,5);
if(asHTML)
jQueryElem.html(fn(user,tweets));
else
jQueryElem.text(fn(user,tweets));
}
, failure: function(status,err){ alert("Problems running query" + err); }
, complete: function() {
if(handler)
handler(jQueryElem)
}
});
}
function showFeed(jQueryElem) {
rss = encodeURIComponent(jQueryElem.text());
window.location.assign('data:text/xml,'+rss);
}
function makeHTML(user,tweets) {
html = "