<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The html blog &#187; firefox</title>
	<atom:link href="http://htmlblog.net/tag/firefox/feed/" rel="self" type="application/rss+xml" />
	<link>http://htmlblog.net</link>
	<description>The web sandbox of Asvin Balloo</description>
	<lastBuildDate>Wed, 07 Oct 2009 17:20:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Writing your first Greasemonkey script &#8211; adding menus to Facebook&#8217;s top menu</title>
		<link>http://htmlblog.net/writing-your-first-greasemonkey-script-adding-menus-to-facebooks-top-menu/</link>
		<comments>http://htmlblog.net/writing-your-first-greasemonkey-script-adding-menus-to-facebooks-top-menu/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 19:25:50 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[greasemonkey]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=120</guid>
		<description><![CDATA[This post will show you how to write a basic Greasemonkey script that will add two more menu items to Facebook's friends top menu as shown below.

These 2 menu items are :

"Recently Updated" - show all your friends with recent updates
"Status Updates" - show the latest status updates of your friends

About Greasemonkey
Greasemonkey is a Firefox [...]]]></description>
			<content:encoded><![CDATA[<p>This post will show you how to write a basic <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> script that will add two more menu items to Facebook's friends top menu as shown below.</p>
<p><img src="http://htmlblog.net/wp-content/uploads/2009/04/facebook.png" alt="facebook" title="facebook" width="357" height="135" class="aligncenter size-full wp-image-123" /></p>
<p>These 2 menu items are :</p>
<ul>
<li>"Recently Updated" - show all your friends with recent updates</li>
<li>"Status Updates" - show the latest status updates of your friends</li>
</ul>
<h3 class="post-title">About <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a></h3>
<p><a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> is a <a href="http://www.mozilla.com/firefox/" target="_blank">Firefox</a> extension that allows you to write scripts that alter the web pages you visit. You can</p>
<ul>
<li>use it to make a web site more readable or more usable</li>
<li>fix rendering bugs that the site owner can't be bothered to fix themselves. </li>
<li>alter pages so they work better with assistive technologies that speak a web page out loud or convert it to Braille</li>
<li>even automatically retrieve data from other sites to make two sites more interconnected.</li>
</ul>
<p><a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> by itself does none of these things. In fact, after you install it, you won't notice any change at all... until you start installing what are called “user scripts”. A user script is just a chunk of javascript code, with some additional information that tells <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> where and when it should be run. Each user script can target a specific page, a specific site, or a group of sites.</p>
<h3 class="post-title">Install <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> addon for Firefox</h3>
<p>Go to <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> addon page, click on the "Add to Firefox" button and follow the instructions. After restarting Firefox, you will notice a monkey's head sitting at the bottom right its status bar.<br />
If you right click on the monkey's head and choose "Manage User Scripts" from the resulting menu, you will notice there isn't any script which is quite normal since we have not installed any ;-).</p>
<h3 class="post-title">Creating your first <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> script.</h3>
<p>For a <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> to be recognized, it must end with <strong>.user.js</strong>, so let us create an empty file and save it as <strong>myfirstscript.user.js</strong><br />
Fire up your favourite text editor and open your newly created file.</p>
<h3 class="post-title"><a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> script metadata</h3>
<p>All user scripts has a meta data section which tells <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> about the script itself, where it came from, and when to run it. For example, our script :</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">// ==UserScript==</span>
<span style="color: #009900; font-style: italic;">// @name          My First GM script</span>
<span style="color: #009900; font-style: italic;">// @namespace     http://htmlblog.net</span>
<span style="color: #009900; font-style: italic;">// @description   basic Greasemonkey script</span>
<span style="color: #009900; font-style: italic;">// @include       http://www.facebook.com/</span>
<span style="color: #009900; font-style: italic;">// ==/UserScript==</span>
&nbsp;</pre>
<p>You can find <a href="http://diveintogreasemonkey.org/helloworld/metadata.html" target="_blank">more information about the metadata here</a>. </p>
<p>Remember we want our script available only for <a href="http://www.facebook.com" target="_blank">Facebook</a> pages, that is why we use <strong>@include http://www.facebook.com</strong></p>
<h3 class="post-title">Show me some code.</h3>
<p>Alright, to add our own menus, we need to get the parent element holding the drop down menu. After inspecting Facebook's source code, we can rapidly come to the conclusion that the parent element's id is "fb_menu_friends_dropdown". So the current Facebook code looks like that :</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;fb_menu_dropdown hidden_elem&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;fb_menu_friends_dropdown&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;fb_menu_item&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://www.facebook.com/friends/?added&amp;amp;ref=tn&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Recently Added<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;fb_menu_item&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://www.facebook.com/friends/?everyone&amp;amp;ref=tn&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>All Friends<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;fb_menu_separator&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;fb_menu_item&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://www.facebook.com/invite.php?ref=tn&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Invite Friends<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;fb_menu_item&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://www.facebook.com/find-friends/?ref=friends&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Find Friends<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;</pre>
<p>and our goal is to insert the two menu items before the "Recently Added" item. </p>
<p>For us to do that, we need to get the first child of the parent element and then insert our elements before it and to help us, i.e walking through the DOM selecting parent and childs, I use a <a href="http://gist.github.com/41440" target="_blank">little piece of code found on Github</a>, which eliminates whitespace issues between elements among other features. So our myfirstscript.user.js can be updated to :</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">// ==UserScript==</span>
<span style="color: #009900; font-style: italic;">// @name          My First GM script</span>
<span style="color: #009900; font-style: italic;">// @namespace     http://htmlblog.net</span>
<span style="color: #009900; font-style: italic;">// @description   basic &lt;a href=&quot;https://addons.mozilla.org/firefox/addon/748&quot; target=&quot;_blank&quot;&gt;Greasemonkey&lt;/a&gt; script</span>
<span style="color: #009900; font-style: italic;">// @include       http://www.facebook.com/</span>
<span style="color: #009900; font-style: italic;">// ==/UserScript==</span>
DOM = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> get<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>id &amp;&amp; <span style="color: #000066; font-weight: bold;">typeof</span> id === <span style="color: #3366CC;">'string'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            id = document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> id || <span style="color: #003366; font-weight: bold;">null</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> walk<span style="color: #66cc66;">&#40;</span>element, tag, walk, start, all<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> el = get<span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span>start || walk<span style="color: #66cc66;">&#93;</span>, elements = all ? <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> : <span style="color: #003366; font-weight: bold;">null</span>;
        <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>el.<span style="color: #006600;">nodeType</span> === <span style="color: #CC0000;">1</span> &amp;&amp; <span style="color: #66cc66;">&#40;</span>!tag || el.<span style="color: #006600;">tagName</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> === tag<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>!all<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> el;
                <span style="color: #66cc66;">&#125;</span>
                elements.<span style="color: #006600;">push</span><span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
            el = el<span style="color: #66cc66;">&#91;</span>walk<span style="color: #66cc66;">&#93;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> elements;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
        <span style="color: #009900; font-style: italic;">// Get the element by its id</span>
        get: get,
&nbsp;
        walk: walk,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Returns the previousSibling of the Element (excluding text nodes).</span>
        getPrevious: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'previousSibling'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Like getPrevious, but returns a collection of all the matched previousSiblings.</span>
        getAllPrevious: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'previousSibling'</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// As getPrevious, but tries to find the nextSibling (excluding text nodes).</span>
        getNext: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Like getNext, but returns a collection of all the matched nextSiblings.</span>
        getAllNext: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Works as getPrevious, but tries to find the firstChild (excluding text nodes).</span>
        getFirst: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span>, <span style="color: #3366CC;">'firstChild'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Works as getPrevious, but tries to find the lastChild.</span>
        getLast: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'previousSibling'</span>, <span style="color: #3366CC;">'lastChild'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Works as getPrevious, but tries to find the parentNode.</span>
        getParent: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'parentNode'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Like getParent, but returns a collection of all the matched parentNodes up the tree.</span>
        getParents: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'parentNode'</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Returns all the Element's children (excluding text nodes).</span>
        getChildren: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span>, <span style="color: #3366CC;">'firstChild'</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Removes the Element from the DOM.</span>
        dispose: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            el = get<span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span>el.<span style="color: #006600;">parentNode</span><span style="color: #66cc66;">&#41;</span> ? el.<span style="color: #006600;">parentNode</span>.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span> : el;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #66cc66;">&#125;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>To get the parent element and its first child, we then append the following code :</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">// get drop down menu</span>
<span style="color: #003366; font-weight: bold;">var</span> parentNode = DOM.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'fb_menu_friends_dropdown'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #009900; font-style: italic;">// get its first child</span>
<span style="color: #003366; font-weight: bold;">var</span> firstNode = DOM.<span style="color: #006600;">getFirst</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'fb_menu_friends_dropdown'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<h3 class="post-title">Creating our nodes</h3>
<p>Now we must create our two nodes which will be inserted afterward. This is done easily with the following code which is self explanatory :</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">/** For &quot;Recently Updated&quot; */</span>
<span style="color: #009900; font-style: italic;">// create our div with class fb_menu_item</span>
<span style="color: #003366; font-weight: bold;">var</span> recentDiv = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #66cc66;">&#41;</span>;
recentDiv.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'class'</span>, <span style="color: #3366CC;">'fb_menu_item'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// create our link</span>
<span style="color: #003366; font-weight: bold;">var</span> recentLink = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #66cc66;">&#41;</span>;
recentLink.<span style="color: #006600;">href</span> = <span style="color: #3366CC;">'http://www.facebook.com/friends/?recent&amp;ref=tn'</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// add text to our link</span>
<span style="color: #003366; font-weight: bold;">var</span> recentDivContent = document.<span style="color: #006600;">createTextNode</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Recently Updated'</span><span style="color: #66cc66;">&#41;</span>;
recentLink.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>recentDivContent<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// add link to our div</span>
recentDiv.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>recentLink<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">/** For &quot;Status Updates&quot; */</span>
<span style="color: #009900; font-style: italic;">// create our div with class fb_menu_item</span>
<span style="color: #003366; font-weight: bold;">var</span> statusDiv = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #66cc66;">&#41;</span>;
statusDiv.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'class'</span>, <span style="color: #3366CC;">'fb_menu_item'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// create our link</span>
<span style="color: #003366; font-weight: bold;">var</span> statusLink = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #66cc66;">&#41;</span>;
statusLink.<span style="color: #006600;">href</span> = <span style="color: #3366CC;">'http://www.facebook.com/friends/?status&amp;ref=tn'</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// add text to our link</span>
<span style="color: #003366; font-weight: bold;">var</span> statusDivContent = document.<span style="color: #006600;">createTextNode</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Status Updates'</span><span style="color: #66cc66;">&#41;</span>;
statusLink.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>statusDivContent<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// add link to our div</span>
statusDiv.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>statusLink<span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>We can also add a separator, for having a cleaner look :</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">/** Creates a separator, just to look good */</span>
<span style="color: #003366; font-weight: bold;">var</span> separatorDiv = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #66cc66;">&#41;</span>;
separatorDiv.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'class'</span>, <span style="color: #3366CC;">'fb_menu_separator'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Finally we insert these 3 nodes before the first child element we got earlier on :</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">// add all divs before first child of menu</span>
parentNode.<span style="color: #006600;">insertBefore</span><span style="color: #66cc66;">&#40;</span>statusDiv, firstNode<span style="color: #66cc66;">&#41;</span>;
parentNode.<span style="color: #006600;">insertBefore</span><span style="color: #66cc66;">&#40;</span>recentDiv, firstNode<span style="color: #66cc66;">&#41;</span>;
parentNode.<span style="color: #006600;">insertBefore</span><span style="color: #66cc66;">&#40;</span>separatorDiv, firstNode<span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Just to be on the safe side of things, we surround the whole block of code with a try and catch statement.</p>
<h3 class="post-title">Putting it all together</h3>
<p>So finally our code is like this :</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">// ==UserScript==</span>
<span style="color: #009900; font-style: italic;">// @name          My First GM script</span>
<span style="color: #009900; font-style: italic;">// @namespace     http://htmlblog.net</span>
<span style="color: #009900; font-style: italic;">// @description   basic &lt;a href=&quot;https://addons.mozilla.org/firefox/addon/748&quot; target=&quot;_blank&quot;&gt;Greasemonkey&lt;/a&gt; script</span>
<span style="color: #009900; font-style: italic;">// @include       http://www.facebook.com/</span>
<span style="color: #009900; font-style: italic;">// ==/UserScript==</span>
&nbsp;
DOM = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> get<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>id &amp;&amp; <span style="color: #000066; font-weight: bold;">typeof</span> id === <span style="color: #3366CC;">'string'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            id = document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> id || <span style="color: #003366; font-weight: bold;">null</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> walk<span style="color: #66cc66;">&#40;</span>element, tag, walk, start, all<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> el = get<span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span>start || walk<span style="color: #66cc66;">&#93;</span>, elements = all ? <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> : <span style="color: #003366; font-weight: bold;">null</span>;
        <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>el.<span style="color: #006600;">nodeType</span> === <span style="color: #CC0000;">1</span> &amp;&amp; <span style="color: #66cc66;">&#40;</span>!tag || el.<span style="color: #006600;">tagName</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> === tag<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>!all<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> el;
                <span style="color: #66cc66;">&#125;</span>
                elements.<span style="color: #006600;">push</span><span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
            el = el<span style="color: #66cc66;">&#91;</span>walk<span style="color: #66cc66;">&#93;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> elements;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
        <span style="color: #009900; font-style: italic;">// Get the element by its id</span>
        get: get,
&nbsp;
        walk: walk,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Returns the previousSibling of the Element (excluding text nodes).</span>
        getPrevious: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'previousSibling'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Like getPrevious, but returns a collection of all the matched previousSiblings.</span>
        getAllPrevious: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'previousSibling'</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// As getPrevious, but tries to find the nextSibling (excluding text nodes).</span>
        getNext: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Like getNext, but returns a collection of all the matched nextSiblings.</span>
        getAllNext: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Works as getPrevious, but tries to find the firstChild (excluding text nodes).</span>
        getFirst: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span>, <span style="color: #3366CC;">'firstChild'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Works as getPrevious, but tries to find the lastChild.</span>
        getLast: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'previousSibling'</span>, <span style="color: #3366CC;">'lastChild'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Works as getPrevious, but tries to find the parentNode.</span>
        getParent: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'parentNode'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Like getParent, but returns a collection of all the matched parentNodes up the tree.</span>
        getParents: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'parentNode'</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Returns all the Element's children (excluding text nodes).</span>
        getChildren: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span>, <span style="color: #3366CC;">'firstChild'</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Removes the Element from the DOM.</span>
        dispose: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            el = get<span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span>el.<span style="color: #006600;">parentNode</span><span style="color: #66cc66;">&#41;</span> ? el.<span style="color: #006600;">parentNode</span>.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span> : el;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #66cc66;">&#125;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000066; font-weight: bold;">try</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #009900; font-style: italic;">// get drop down menu</span>
	<span style="color: #003366; font-weight: bold;">var</span> parentNode = DOM.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'fb_menu_friends_dropdown'</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #009900; font-style: italic;">// get its first child</span>
	<span style="color: #003366; font-weight: bold;">var</span> firstNode = DOM.<span style="color: #006600;">getFirst</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'fb_menu_friends_dropdown'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">/** For &quot;Recently Updated&quot; */</span>
	<span style="color: #009900; font-style: italic;">// create our div with class fb_menu_item</span>
	<span style="color: #003366; font-weight: bold;">var</span> recentDiv = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #66cc66;">&#41;</span>;
	recentDiv.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'class'</span>, <span style="color: #3366CC;">'fb_menu_item'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// create our link</span>
	<span style="color: #003366; font-weight: bold;">var</span> recentLink = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #66cc66;">&#41;</span>;
	recentLink.<span style="color: #006600;">href</span> = <span style="color: #3366CC;">'http://www.facebook.com/friends/?recent&amp;ref=tn'</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// add text to our link</span>
	<span style="color: #003366; font-weight: bold;">var</span> recentDivContent = document.<span style="color: #006600;">createTextNode</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Recently Updated'</span><span style="color: #66cc66;">&#41;</span>;
	recentLink.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>recentDivContent<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// add link to our div</span>
	recentDiv.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>recentLink<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">/** For &quot;Status Updates&quot; */</span>
	<span style="color: #009900; font-style: italic;">// create our div with class fb_menu_item</span>
	<span style="color: #003366; font-weight: bold;">var</span> statusDiv = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #66cc66;">&#41;</span>;
	statusDiv.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'class'</span>, <span style="color: #3366CC;">'fb_menu_item'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// create our link</span>
	<span style="color: #003366; font-weight: bold;">var</span> statusLink = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #66cc66;">&#41;</span>;
	statusLink.<span style="color: #006600;">href</span> = <span style="color: #3366CC;">'http://www.facebook.com/friends/?status&amp;ref=tn'</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// add text to our link</span>
	<span style="color: #003366; font-weight: bold;">var</span> statusDivContent = document.<span style="color: #006600;">createTextNode</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Status Updates'</span><span style="color: #66cc66;">&#41;</span>;
	statusLink.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>statusDivContent<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// add link to our div</span>
	statusDiv.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>statusLink<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">/** Creates a separator, just to look good */</span>
	<span style="color: #003366; font-weight: bold;">var</span> separatorDiv = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #66cc66;">&#41;</span>;
	separatorDiv.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'class'</span>, <span style="color: #3366CC;">'fb_menu_separator'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// add both divs before first child of menu</span>
	parentNode.<span style="color: #006600;">insertBefore</span><span style="color: #66cc66;">&#40;</span>statusDiv, firstNode<span style="color: #66cc66;">&#41;</span>;
	parentNode.<span style="color: #006600;">insertBefore</span><span style="color: #66cc66;">&#40;</span>recentDiv, firstNode<span style="color: #66cc66;">&#41;</span>;
	parentNode.<span style="color: #006600;">insertBefore</span><span style="color: #66cc66;">&#40;</span>separatorDiv, firstNode<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000066; font-weight: bold;">catch</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;
&nbsp;</pre>
<h3 class="post-title">Installing and testing our script</h3>
<p>Fire up Firefox and select <strong>"File" -> "Open File..."</strong> in the menu bar and then browse for your script, i.e myfirstscript.user.js in our case. You will be prompted to install the script by <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a>. After installation is complete, head to Facebook, login and hover over the "Friends" menu, you will see your newly created menus.</p>
<p><a href="/demo/greasemonkey/fb_recently_updated_link.user.zip"><strong>Download script</strong></a><br />
<a href="/demo/greasemonkey/fb_recently_updated_link.user.js"><strong>Install script</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/writing-your-first-greasemonkey-script-adding-menus-to-facebooks-top-menu/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>10 starting signs of a good web developer (php version)</title>
		<link>http://htmlblog.net/10-starting-signs-of-good-web-developers-php-version/</link>
		<comments>http://htmlblog.net/10-starting-signs-of-good-web-developers-php-version/#comments</comments>
		<pubDate>Sat, 05 Jul 2008 10:03:33 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[good]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[practice]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[templating]]></category>
		<category><![CDATA[w3c]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[web developer]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=10</guid>
		<description><![CDATA[

Nowadays many people call themselves PHP programmers / web developers as soon as they know a bit of Frontpage or using Dreamweaver to generate the code for them. But are they really good web developers? Here's my top 10 characteristics of good web developers, feel free to comment.

1. Ability to hand code
Instead of using an [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://farm1.static.flickr.com/75/158927067_86bcadf62f.jpg?v=0" alt="web developer" /></p>
<div style="clear: both"></div>
<p>Nowadays many people call themselves PHP programmers / web developers as soon as they know a bit of Frontpage or using Dreamweaver to generate the code for them. But are they really good web developers? Here's my top 10 characteristics of good web developers, feel free to comment.<br />
<span id="more-10"></span><br />
<strong>1. Ability to hand code</strong><br />
Instead of using an IDE where it justs generate a bunch of lines which you don't understand, why you don't fire up a text editor such as VI, Emacs, Notepad or Notepad++ if you prefer and start coding right away? There are many advantages of hand coding HTML.</p>
<ul>
<li>The code is clean</li>
<li>You understand what you're doing</li>
<li>Easy maintenance and debugging.</li>
</ul>
<p><a href='http://www.eclipse.org/pdt/'><img src="http://htmlblog.net/wp-content/uploads/2008/07/eclipse.jpg" alt="" title="eclipse" width="131" height="68" class="alignnone size-full wp-image-11" /></a></p>
<div style="clear: both"></div>
<p>I currently use <a href="http://www.eclipse.org/pdt/">Eclipse PDT as IDE</a></p>
<div style="clear: both"></div>
<p><br/><br />
<strong>2. Ability to produce valid HTML.</strong><br />
The <a href="http://validator.w3.org/">W3C has an online tool</a> which checks whether the HTML code you write is valid or not and there's a debate whether your code must valid or not. IMHO they must be and that's why :</p>
<ul>
<li>Future proof</li>
<li>Cross browser compatibilities</li>
<li>Easier to maintain</li>
</ul>
<p><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /><br />
<a href="http://validator.w3.org/">Validate your code</a></p>
<div style="clear: both"></div>
<p><br/><br />
<strong>3. Use Linux as operating system</strong><br />
Why on earth a web developer doesn't use Linux? It's free, comes with bunch of applications, you know the internals, you compile from source, you experiment things and most important, you're more productive. An example, I must edit a file on server A.<br />
On Windows :<br />
Launch WinSCP -> connect to server A -> retrieve file -> edit file -> save -> upload -> ask for confirmation -> wait upload finish</p>
<p>On Linux:<br />
Launch console -> SSH on server A -> open file in VI for editing -> save</p>
<p>Enough said ;-)</p>
<p><a href='http://kubuntu.org'><img src="http://htmlblog.net/wp-content/uploads/2008/07/kubuntu-header.png" alt="" title="kubuntu-header" width="450" height="90" class="alignnone size-full wp-image-12" /></a></p>
<div style="clear: both"></div>
<p>I currently use <a href="http://kubuntu.org">Kubuntu (Hardy Heron)</a></p>
<div style="clear: both"></div>
<p><br/><br />
<strong>4. Templating</strong><br />
Have you heard of spaghetti code? If not, it's mixing PHP code with HTML code. For example :</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span>?php echo <span style="color: #ff0000;">'hi'</span>; ?<span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
&nbsp;</pre>
<p>This results in nightmare maintenance, a mess of code. Both designer and web developer work in the same file which is a bad mixture of logic and presentation. Fortunately there are templating engines which separate these two things.<br />
<a href='http://smarty.php.net'><img src="http://htmlblog.net/wp-content/uploads/2008/07/smarty-logo-orange.gif" alt="" title="smarty-logo-orange" width="250" height="64" class="alignnone size-full wp-image-13" /></a></p>
<p>The most popular one being <a href="http://smarty.php.net">Smarty </a>which I currently use. Have the <a href="http://www.smarty.net/crashcourse.php">crash course</a> if you haven't already.</p>
<div style="clear: both"></div>
<p><br/><br />
<strong>5. Database abstraction layer</strong><br />
Your scripts must be database independent, i.e. if tomorrow your boss decides to throw all <a href="http://www.mysql.com/">MySQL </a>away and replace them by <a href="http://www.postgresql.org/">PostgreSQL</a>, you don't have to write the scripts all again replacing all MySQL functions by PostgreSQL one. Also, you just have to learn a single API.</p>
<p>I use <a href="http://pear.php.net/package/MDB2">PEAR MDB2 </a>as DB abstraction library.</p>
<div style="clear: both"></div>
<p><br/><br />
<strong>6. JS framework</strong><br />
Javascript is everywhere nowadays together with the AJAX buzz word. Good web developers must have an overview of all the js frameworks available and choose the best one for his task. Popular frameworks include the <a href="http://developer.yahoo.com/yui/">YUI library</a>,<a href="http://www.prototypejs.org/"> Prototype</a>, <a href="http://jquery.com/">jQuery</a>, <a href="http://mootools.net/">MooTools</a>, <a href="http://dojotoolkit.org/">Dojo Toolkit</a> and <a href="http://extjs.com/">Ext JS</a> to name just a few.</p>
<p><a href='http://developer.yahoo.com/yui/'><img src="http://htmlblog.net/wp-content/uploads/2008/07/yuilib.jpg" alt="" title="yuilib" width="260" height="161" class="alignnone size-full wp-image-14" /></a></p>
<p>I prefer <a href="http://developer.yahoo.com/yui/">YUI library</a> (lots of documentation and exciting future)</p>
<div style="clear: both"></div>
<p><br/><br />
<strong>7. Caching</strong><br />
Why retrieving the same information from the database again and again whereas you can cache the output to files or in memory. This will reduce the load on your database server. If you use the Smarty templating engine you can use <a href="http://www.smarty.net/manual/en/caching.groups.php">cache groups </a>. Another popular technique is by using <a href="http://www.danga.com/memcached/">Memcache</a>, for high volume websites.</p>
<p>At work I use the Smarty caching system and a little bit of Memcache (for the taste ;-)), and my database load reduced by more than 70%.</p>
<div style="clear: both"></div>
<p><br/><br />
<strong>8. Must have Firefox extensions : Firebug, web developer toolbar, YSlow</strong><br />
<a href='http://www.getfirebug.com/'><img src="http://htmlblog.net/wp-content/uploads/2008/07/firebug.png" alt="" title="firebug" width="500" height="104" class="alignnone size-full wp-image-16" /></a></p>
<div style="clear: both"></div>
<p>These great firefox extensions will help you greatly whether to debug some javascript, fix some CSS issues, increase your site performance. These are must-have for web developers, all three of them.</p>
<ul>
<li><a href="http://www.getfirebug.com/">Firebug</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/60">Web developer</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/5369">YSlow!</a></li>
</ul>
<div style="clear: both"></div>
<p><br/><br />
<strong>9. Keep reading</strong><br />
Keep reading reading and reading. Find popular programming posts on <a href="http://digg.com">Digg</a>, <a href="http://del.icio.us/popular/">del.icio.us</a> and read great magazines like <a href="http://www.smashingmagazine.com/">Smashing Magazine</a>, blogs like the <a href="http://yuiblog.com">YUI blog</a>. Don't forget to participate actively in forums and ask questions.</p>
<p><a href='http://del.icio.us/popular'><img src="http://htmlblog.net/wp-content/uploads/2008/07/delicious42px.gif" alt="" title="delicious42px" width="42" height="42" class="alignnone size-full wp-image-15" /></a></p>
<p>I don't know why it's like that but I like <a href="http://del.icio.us/popular">del.icio.us popular</a> section more interesting and everyday I find lots of interesting stuff via this page.</p>
<div style="clear: both"></div>
<p><br/><br />
<strong>10. Look around you</strong><br />
<a href='http://www.rubyonrails.org/'><img src="http://htmlblog.net/wp-content/uploads/2008/07/rails.png" alt="" title="rails" width="87" height="112" class="alignnone size-full wp-image-17" /></a><br />
Don't focus only on PHP. It's OK but have a look around you, there are fantastic things happening, like <a href="http://www.rubyonrails.org/">RoR</a>, Python ;-)<br />
A web developer who hasn't heard of RoR is NOT a good web developer.</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/10-starting-signs-of-good-web-developers-php-version/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
