// ==UserScript==
// @name           LJSupport: Expand Community Name
// @namespace      http://afunamatata.com/greasemonkey/
// @description    Expands community names to link to their profiles when you type in [!commname]. Code adapted from Ciaran's FAQs by Number script
// @include        http://www.livejournal.com/support/see_request.bml?id=*
// @tags        ljsupport
// ==/UserScript==


var bodybox = document.getElementById("body");
if (bodybox) {
    bodybox.addEventListener("keyup", expandCommName, false);
}

function expandCommName() {
    var bodybox = document.getElementById("body");
    if (bodybox) {
      var text = bodybox.value;
      var cursor = bodybox.selectionEnd;
      var texttwo = text.replace(/\[!([\S]*)?\]/g, "$1 [http://community.livejournal.com/$1/profile]");     
      
      if (text != texttwo) {
        var sel = cursor + (texttwo.length - text.length);
        bodybox.value = texttwo;
        bodybox.setSelectionRange(sel, sel);           
      }
    }
}
