/* (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) { 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); } }); } function makeHTML(user,tweets) { html = "

Twitter feed for " + user + "

\n" + "" } function makeRSS (user,tweets) { rss = '' + "\n" + '' + "\n" + "\n\tTwitter Search / " + user + "\n\thttp://twitter.com/" + user + "\n\tTwitter feed for: " + user + ". Generated by TwitRSS.me/JS\n\ten-us\n\t40\n\n"; for (i=0;i\n\t\n\t" + t.tweetDate + "\n\t" + t.tweetURL + "\n\t" + t.tweetURL + "\n\t\n\t\n\n"; } rss += "\n"; return rss; } function extractTweets (tweets, max) { toReturn = []; for(i=0;i-1) { tweetImg = body.div[0].div.div.div.a.img; } if(tweetImg) { tweetHTML = tweetHTML + '
'; } if(tweetAs) { for(j=0;j'+tweetAs[j].title+' '; } else if (tweetAs[j].class.indexOf('twitter-hashtag')>-1){ link = '#'+tweetAs[j].strong+' '; } else if (tweetAs[j].class.indexOf('twitter-atreply')>-1){ link = '@'+tweetAs[j].strong+' '; } tweetHTML = tweetHTML.replace(/\n\s*/,link); } } toReturn[i] = { 'authorFullName' : authorFullName , 'authorTwitterName' : authorTwitterName , 'authorTwitterURL' : authorTwitterURL , 'tweetURL' : tweetURL , 'tweetDate' : tweetDate , 'tweetHTML' : tweetHTML , 'tweetAs' : tweetAs , 'tweetImg' : tweetImg } } // if } //for return toReturn; }