
// Frownies
// version 0.5 BETA!
// 2005-07-08
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script that converts graphical
// smilies to their text equivalents.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Frownies", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          Frownies
// @namespace     http://diveintomark.org/projects/greasemonkey/
// @description   convert graphical smilies to their text equivalents
// @include       *
// ==/UserScript==

/* BEGIN LICENSE BLOCK
Copyright (C) 2005 Mark Pilgrim

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You can download a copy of the GNU General Public License at
http://diveintomark.org/projects/greasemonkey/COPYING
or get a free printed copy by writing to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
END LICENSE BLOCK */

(function() {
    var smilies, images, img, i, j, smily, replacement;
    smilies = [":)", ":-(", ":(", ";-)", ";)", ":-D", ":D", ":-/",
        ":/", ":X", ":-X", ":\">", ":P", ":-P", ":O", ":-O", "X-(",
        "X(", ":->", ":>", "B-)", "B)", ">:)", ":((", ":(((", ":-((",
        ":))", ":-))", ":-|", ":|", "O:-)", "O:)", ":-B", ":B", "=;",
        "I)", "I-)", "|-)", "|)", ":-&", ":&", ":-$", ":$", "[-(", ":O)",
        ":@)", "3:-O", ":(|)", "@};-", "**==", "(~~)", "*-:)", "8-X",
        "8X", "=:)", "<):)", ";;)", ":*", ":-*", ":S", ":-S", "/:)",
        "/:-)", "8-|", "8|", "8-}", "8}", "(:|", "=P~", ":-?", ":?",
        "#-O", "#O", "=D>", "~:>", "%%-", "~O)", ":-L", ":L", "[-O<",
        "[O<", "@-)", "@)", "$-)", "$)", ">-)", ":-\"", ":^O", "B-(",
        "B(", ":)>-", "[-X", "[X", "\\:D/", ">:D<", "(%)", "=((", "#:-S",
        "#:S", "=))", "L-)", "L)", "<:-P", "<:P", ":-SS", ":SS", ":-W",
        ":W", ":-<", ":<", ">:P", ">:-P", ">:/", ";))", ":-@", "^:)^",
        ":-J", "(*)", ":GRIN:", ":-)", ":SMILE:", ":SAD:", ":EEK:",
        ":SHOCK:", ":???:", "8)", "8-)", ":COOL:", ":LOL:", ":MAD:",
        ":RAZZ:", ":OOPS:", ":CRY:", ":EVIL:", ":TWISTED:", ":ROLL:",
        ":WINK:", ":!:", ":?:", ":IDEA:", ":ARROW:", ":NEUTRAL:",
        ":MRGREEN:"];
    images = document.evaluate(
        '//img[@alt]',
        document,
        null,
        XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
        null);
    for (i = 0; i < images.snapshotLength; i += 1) {
        img = images.snapshotItem(i);
        for (j in smilies) {
            smily = smilies[j];
            if (img.getAttribute("alt").toUpperCase() == smily) {
                replacement = document.createTextNode(smily);
                img.parentNode.replaceChild(replacement, img);
            }
        }
    }
})();

//
// ChangeLog
// 2005-07-08 - 0.5 - MAP - added license block
// 2005-04-21 - 0.4 - MAP - linted
// 2005-04-18 - 0.3 - MAP - tidy code
// 
