Skip to content

Instantly share code, notes, and snippets.

@atl
Created June 3, 2010 11:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atl/423773 to your computer and use it in GitHub Desktop.
Save atl/423773 to your computer and use it in GitHub Desktop.
example jTweetsAnywhere usage that filters out replies and old-style retweets, hides selected hashtags, preserves carriage returns, and hides repetitions of a userpic
<html>
<!-- I'm a beginnner with JS/jQuery, so I welcome suggestions
on how to make it more idiomatic. -->
<head>
<link rel="stylesheet" type="text/css" href="jquery.jtweetsanywhere-1.0.0.css" />
<style type="text/css">
/* Since we're showing one user's stream, show the profile image the first time: */
.jta-tweet-profile-image {visibility: hidden}
.jta-tweet-list-item:first-child .jta-tweet-profile-image {visibility: visible}
</style>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="jquery.jtweetsanywhere-1.0.0.min.js"></script>
</head>
<body>
...
<div id="tweetsFeed">
</div>
...
<script type="text/javascript">
$('#tweetsFeed').jTweetsAnywhere({
username: 'atl',
count: 25,
showFollowButton: false,
tweetProfileImagePresent: true,
hideHashTags: ['li', 'fb', 'lazytwitter'],
tweetDecorator: function(tweet, options) {
var html = '';
// Show only the tweets that are not replies or oldstyle retweets:
if (!(tweet.in_reply_to_screen_name || /^RT/i.test(tweet.text))) {
html = '<li class="jta-tweet-list-item">';
if (options.tweetProfileImagePresent)
html += options.tweetProfileImageDecorator(tweet, options);
if (options.tweetBodyDecorator)
html += options.tweetBodyDecorator(tweet, options);
html += '<div class="jta-clear">&nbsp;</div>';
html += '</li>';
}
return html;
},
tweetTextDecorator: function(tweet, options)
{
// the default tweet text decorator optionally marks links, @usernames, and
// #hashtags
var tweetText = options.linkDecorator ? options.linkDecorator(tweet.text, options) : tweet.text;
if (options.usernameDecorator)
tweetText = options.usernameDecorator(tweetText, options);
if (options.hashtagDecorator)
tweetText = options.hashtagDecorator(tweetText, options);
// I make the occasional whitespace gag, so I want carriage returns preserved:
tweetText = tweetText.replace(/\n/gi, '<br />')
return '<span class="tweet-text">' + tweetText + '</span>';
},
hashtagDecorator: function(text, options)
{
// Find hashtags, and then filter them according to the contents:
return text.replace(/#([a-zA-Z0-9_]+)/gi, function (str, p1, offset, s)
{
// return nothing if it's in the list of hidden hash tags
if (options.hideHashTags.indexOf(p1) + 1)
return '';
else
// otherwise, return the string from defaultHashtagDecorator
return '<a href="http://search.twitter.com/search?q=%23' +p1+ '" class="jta-tweet-a jta-tweet-hashtag" title="#' +p1+ '" target="_blank" rel="nofollow">#' +p1+ '<\/a>';
})
},
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment