(developed by @xclricky, see more news application)
var emoticons = {
    "laugh":"☺",
    "lol": "☻",
    "unhappy": "☹",
    "love": "♥",
    "yeah": "✌",
    "dislike": "✖",
    "music": "♫",
    "suprised": ":-O",
    ":-O": ":-O",
    ":)": "☺",
    ":(": "☹",
    ":'(": ":'(",
    ";)": ";)",
    ":/": ":/", 
}

var noun_type_emoticon = {
    _name: "emoticon",
    suggest: function( text, html ) {
        var suggestions = [];
        for ( var emoticon in emoticons ) {
            if ( emoticon.indexOf( text.toLowerCase() ) > -1 ) {
                var sugg = CmdUtils.makeSugg(emoticons[emoticon]);
                suggestions.push(sugg);
            }
        }
        return suggestions;
    }
}

var timespeople_data = {
    'userid':null,
    'thumbnail':null,
}

CmdUtils.CreateCommand({ 
  name: "timespeople",
  synonyms: ["tp"],
  icon: "http://www.nytimes.com/favicon.ico",
  homepage: "http://nytimes.com/",
  author: { name: "Changliang (Charlie) Xu", email: "xuchangliang@gmail.com"},
  license: "GPL",
  description: "Laugh, cry ... with your readings",
  help: "add your note instead of the default article description",
  takes: {"note with e emotion": noun_arb_text},
  modifiers: {e: noun_type_emoticon},
  preview: function( pblock, input, emo ) {
    var doc = CmdUtils.getDocument();
    var url = doc.location.href;
    var title = doc.title;
    var type = "article";
    if (url.indexOf("nytimes.com/imagepages/")>0) {
        type = "graphic";
        if (title.indexOf("The New York Times") == 0) {
            title = jQuery(doc.body).find("font[size='-1']").text();
            title = title.substring(0, 50);
        }
    }

    var template = "You are going to comment at the ${type}
titled: ${name}
with your note: ${note}
${emoticon}"; var emo_text = ''; if (emo['e'].text && emo['e'].text.length > 0) { emo_text = 'and You ' + emo['e'].text + ' at it'; } pblock.innerHTML = CmdUtils.renderTemplate(template, {"name": title, 'note': input.text, 'emoticon': emo_text, 'type': type}); }, execute: function(input, emo) { var doc = CmdUtils.getDocument(); var url = doc.location.href; var type = "article"; var title = doc.title; if (url.indexOf("blogs.nytimes.com") > 0) { type = "blog"; } else if (url.indexOf("nytimes.com/imagepages/")>0) { type = "graphic"; if (title.indexOf("The New York Times") == 0) { title = jQuery(doc.body).find("font[size='-1']").text(); title = title.substring(0, 50); } } if (emo['e'].text && emo['e'].text.length > 0) { title = emo['e'].text + ' | ' + title; } var RMID = Utils.getCookie(".nytimes.com", "RMID"); if (timespeople_data.userid == null) { var userinfo = jQuery(doc.body).find("#TP_user"); var thumbnail = userinfo.find("img").attr("src"); var jpg_pos = thumbnail.indexOf(".jpg"); timespeople_data.userid = thumbnail.substring(jpg_pos-8, jpg_pos); timespeople_data.thumbnail = thumbnail; } var postData = { "RMID": RMID, "activities": '[{"userid": ' + timespeople_data.userid + ', "verb": "recommended", "object": "'+ title +'", "object_desc": "'+ input.text +'", "object_type": "' + type +'", "object_url": "'+ url + '", "object_thumbnail_url": "http://graphics8.nytimes.com/", "visible": 1, "source": "nytimes.com", "actorDisplayname": "You", "date_updated": "' + Date() + '", "picURL": "' + timespeople_data.thumbnail + '"}]', "version": "1.0" }; jQuery.ajax({ data: postData, url: "http://www.nytimes.com/svc/timespeople/toolbar/1.0/activity/post", dataType: "text", type: "POST", success: function(msg){ displayMessage(msg); }, error: function(msg){ displayMessage(msg); } }); } });