Twofifty Facebook app

I recently went to update my progress on IMDb’s top 250 films on the handy Facebook app by Tim Broddin only to find that it redirects to a domain that no longer seems to be working. I suspect this app has run its course now. How very annoying. The reason I’m most annoyed is that I used to be a member of twofifty.org a few years back. This site was also created by Tim Broddin, and it was also allowed to expire, so I lost track of my progress.

I wrote my own version to use for a while, but then this Facebook app turned up and I figured that was going to be a good replacement. How wrong I was.

I’m considering writing my own, again, and I will keep it running because I want to use it.

Old web techniques

I often go around looking at the source for the websites I frequent. It’s not very interesting to most people, but I am not most people.

Something I’ve noticed a few times in the last couple of weeks is that sites are suddenly using an evolved form of a script I was very familiar with many years ago:

if(top.location != self) {
  top.location.replace(document.location.href);
}

That’s how it appears on Last.fm. Essentially the script checks to see if the page is contained within another page, and then takes the user to the page by itself if it is. This gets rid of page headings you sometimes see from sites like Digg and Facebook when you follow a link from there.

The script used to be used to make your own site break out of frames put there by sites like Geocities (R.I.P.) before domains and hosting were quite so affordable. Obviously now there are basically no sites on the Internet that use frames in the traditional sense (that’s a good thing), but the modern equivalent (iframes) are pretty much all over the place. They tend to be used for displaying external content rather than the layout of internal content, but the idea is mostly the same: multiple documents on one page.

I just find it somewhat interesting that “web 2.0” seems to be encountering the exact same things I really hated about web 1.0 all those years ago.

Facebook share button shows no count

Share

I was working on adding a Facebook Share button to blog posts at work and I couldn't seem to get it to display the speech bubble with the number of shares without clicking on the icon.

I did a whole bunch of searching and it turned out that it was caused by some Javascript from Facebook that only displays the count if it's more than 3. I don't really like the inconsistency of that, so I looked for a way to get it displayed even if it's zero. A guy named Patrick Kelly suggests getting your own local copy of the Facebook Javascript (FB.Share) and modifying the displayBox() function call so it shows any number. This is fine for now in that it will work, but as Patrick points out on his blog, it will potentially break if Facebook update their API, or make other changes to the underlying code.

I decided to pick apart the code and come up with a solution that doesn't involve the same issues. The fix is fairly basic. You just need to include the share button in the same way as Facebook tells you, and then insert the following Javascript after that:

<script type="text/javascript">
var buttons = document.getElementsByName('fb_share');
var count = buttons.length;
for(var i = 0; i<count; i++) {
  var data = FB.Share.getUrl(buttons[i]);
  if(FB.Share.results[data]) {
    buttons[i].fb_count = FB.Share.results[data].total_count;
  }
  FB.Share.displayBox(buttons[i], 0);
}
</script>

Hopefully that's a bit tidier than copying and editing the FB.Share file. It also means that you'll benefit from a cached version of the code being presented to the user if they've been on any other site with that button. A fairly tiny benefit, but every little helps. 🙂

Cash Gordon sucks

Just been looking at the Cash Gordon website and decided it’s not very good. Thought I’d share that with you all. 🙂

More info
I just thought I’d take a second to explain this post… The Conservative Party put up a website that I’m not going to bother linking to that had a Twitter stream of all posts with a certain hashtag. They had no filtering of content, and no sanitising either. All HTML and Javascript got rendered directly on their page.

Cue carnage. People posted massive pictures, huge text, and a few people (myself included) posted Javascript redicrects to various other sites around the Internet.

The site appears to be down now. Whether that’s on purpose by the sysadmin team in the data centre, or because of a DDoS I don’t know. I guess it won’t be coming back up in its original form though. 🙂

Google Analytics data:
Cash Gordon Google Analytics data

It was fun while it lasted.

Most annoying hashtag of the month (#moonfruit)

I was getting bored of finding that several people I know (mostly you, 0lly :P) only bother tweeting if they stand a tiny little chance of winning a MacBook or whatever by sticking #moonfruit everywhere.

I decided to write a little command chain to show me how many of the most recent 200 tweets in my “friends timeline” contained the ubiquitous hashtag.

Turned out to be 9.5% of tweets. That’s damn near to 1 in 10 tweets being of absolutely no interest to me. Booooring! Here’s the command chain I wrote. I’m sure it can be refined plenty. I only use the XML API interface for Twitter because the JSON format doesn’t bother splitting results onto separate lines.

curl -s -u YOUR_TWITTER_USERNAME http://twitter.com/statuses/friends_timeline.xml?count=200 > /tmp/twitterlog.txt && echo -n 'scale=2; 100/200*' >/tmp/twittercount.txt && grep '#moonfruit' /tmp/twitterlog.txt | wc -l >>/tmp/twittercount.txt && cat /tmp/twittercount.txt && cat /tmp/twittercount.txt | bc

Obviously you’ll have to substitute YOUR_TWITTER_USERNAME for your actual username. You can also change the bit that says #moonfruit to anything else you want to search for. Oh yeah, this will prompt you for your Twitter password, but all communication is directly with Twitter, so you’ll be just about as safe as if you’d gone to the website. You’ll encounter a lot of problems if you try to run this in Windows, too. 🙂