• Home
  • New Entries
  • Popular Entries
  • Submit a Story
  • About

Random Photos in Facebook sidebar ...

In this short Weekly Web Hack article, I will show how to add a new sidebar to Facebook for displaying random photos. The techniques herein could be easily extended for more elaborate functional enhancements.
What is a bookmarklet / favelet?

A bookmarklet is a bookmark whose protocol is javascript: rather than the usual http: or https:. By using the javascript protocol, a bookmarklet actually executes JavaScript code within the context of the currently viewed page.

This makes them potentially very powerful and also potentially dangerous. By clicking a bookmarklet, you are authorizing the executed script to do whatever it wishes - this could include collecting private information and sending it off to a third party, or possibly (if the developer is clever enough) stealing your credentials by giving you new contact information in some way. BE CAREFUL

That said, the bookmarklet demoed here is meant to be totally innocuous and benign. In fact, I invite you to review the code until you are satisfied that it is trustworthy.
Installation

To get the Random Photos bookmarklet:

   1. Drag the following link to your bookmarks / favorites toolbar or directory:

          Random Photos

   2. Visit any Facebook profile and click the Random Photos link from your toolbar/bookmarks/favorites.

That is it!
What does it do?

In short, Random Photos will visit the "View Photos of..." link directly below the persons profile and inject 5 random images found therein into a new div placed underneath the left-hand sidebar navigation items.


The Code

For your viewing pleasure, here is the raw JavaScript source for the random photos bookmarklet. You will notice that it uses some of Facebook is JavaScript infrastructure such as the $() function and the Ajax object.

random-photos.js

(function(){
var pics = $(pics);
if (!pics) {
  var style = document.createElement( istyle);
  style.innerHTML =
    .advert, .seeall, .sponsors, .sponsor_absolute { display: none !important; } +
    #pics img { background: white; border: 1px solid #ccc; padding: 3px; } +
    #pics { text-align: center; background: #f7f7f7; border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; }; 
  document.getElementsByTagName(head)[0].appendChild(style);
  pics = document.createElement( wouldiv);
  pics.id = pics;
  pics.className = app_list;
  pics.innerHTML =
    <h2><a href="/photo_search.php?view=all&id= + PROFILE_OWNER_ID + ">Random Photos</a></h2> +
    <div style="text-size:small" id="picsloading">loading...</div>;
  $( isidebar).appendChild(pics);
}
var ajax = new Ajax;
ajax.onDone = function (ajaxObj, responseText) {
  $(picsloading).style.display = one;
  var start = responseText.indexOf(<div);
  var end = responseText.indexOf(</body);
  var div = document.createElement( wouldiv);
  div.innerHTML = responseText.substring(start, end);
  var images = [], tables = div.getElementsByTagName( able);
  for (var j=0; j<tables.length; j++) {
    var imgnodes = tables[j].getElementsByTagName(img);
    for (var i=0; i<imgnodes.length; i++) { images.push(imgnodes[i]); }
  }
  var selected = [];
  selected.contains = function(item) { for (var j=0; j<this.length; j++) if (this[j]==x) return true; return false };
  while (selected.length < imgnodes.length && selected.length < 5 ) {
    var x = Math.floor(Math.random() * imgnodes.length);
    while (selected.contains(x)) x++;
    selected.push(x);
  }
  for (var i=0; i<selected.length; i++) { $(pics).appendChild(images[selected[i]].parentNode); }
};
ajax.get(/photo_search.php?view=all&id= + PROFILE_OWNER_ID);
})();

 Original Source:
http://jimbojw.com/wiki/index.php?title=Random_Photos_in_Facebook_sidebar

AddThis Social Bookmark Button

Posted at 09:11:19 am | Permalink | Posted in Facebook  

Related Stuff

  • MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.

  • Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone

  • TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support

  • ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.

  • Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.

  • Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software

  • PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.

Top Stuff

MessengerFX

e-messenger

ILoveIM

Top 20 Ruby CMS

eBuddy

MSN Web Messenger



About Ajaxlines

Ajaxlines is a project focused on providing its audience with a database of most of Ajax related articles, resources, tutorials and services from around the world.

Its purpose is to showcase the power of Ajax and to act as a portal to the Ajax development community.


Search


Topics

  • .Net (162)
  • Ajax (82)
  • Ajax Games (10)
  • Articles (95)
  • Bookmarking (35)
  • Calendar (20)
  • Chat (45)
  • ColdFusion (3)
  • CSS (75)
  • Email (23)
  • Facebook (83)
  • Flash (19)
  • Google (54)
  • Html (27)
  • Image (11)
  • International Calls & VOIP (7)
  • Java (54)
  • Javascript (265)
  • jQuery (159)
  • JSON (61)
  • Perl (2)
  • PHP (156)
  • Presentation (19)
  • Python (3)
  • Resources (2)
  • RSS (8)
  • Ruby (29)
  • Storage (4)
  • Toolkits (103)
  • Tutorials (217)
  • UI (11)
  • Utilities (174)
  • Web2.0 (18)
  • XmlHttpRequest (28)
  • YUI (12)

© 2006 www.ajaxlines.com. All Rights Reserved. Powered by IRange