Wednesday, January 5, 2011

[IT] Facebook Automatic Selecter

Today while I was surfing around facebook like all young people do, I came across an annoying issue: Facebook doesn't allow me to select all my friends when I'm trying to suggest friends to someone new on Facebook. I have to manually click each one which is time-consuming and boring.

Naturally, there was a better way. I looked it up and saw a posting on facebook discussing this exact issue. Just paste this line of code into the address bar of your browser (where you type the URL), and your friends are automatically selected:

javascript:elms=document.getElementById('friends').getElementsByTagName('li');for(var fid in elms){if(typeof elms[fid] === 'object'){fs.click(elms[fid]);}}

If you're not as technically minded, you can go on your merry way and just use the code. I wanted to understand what it meant though. So to put it in more readable form:

elms = document.getElementByID('friends').getElementsByTagName('li');

for (var fid in elms) {
if (typeof elms[fid] === 'object') {
fs.click(elms[fid]);
}
}

With knowledge of DOM (Document Object Model) scripting and JavaScript, this is quite comprehensible. Let me write it step-by-step anyway though:

1. Assign the array variable 'elms' to be the array of elements (formally called collection) that is the listed items contained within the div tag named 'friends'. In this case, all the list elements are apparently objects.

2. Loop through all elements in the array 'elms'. For each loop, check whether the element is the type of data known as an object.

3. If so, activate the object called 'fs' to do the method 'click' on the 'fid'th element of the array 'elms'. Apparently, this method just selects the object for you which is the same method that is activated when you do a mouse click.

There are probably some other cool features that you can do to facebook. I'll keep my eyes peeled for some other places where code can come in handy.

No comments:

Post a Comment