function insert_emoticons(ident, classes) {
  classes = classes || "";
  decoder = image_decoder.images;
  console.log("Replacing " + $(ident).length + " instances of " + ident);
  $(ident).each(function() {
    for (var i = 0; i < decoder.length; i++) {
      key = Object.keys(decoder[i]);
      image = decoder[i][key];
      key = "(" + key + ")";
      $(this).html($(this).html().replace(key,
        "<img class='" + classes + "' style='height: 28px; width: auto;' src='" + image + "'/>"
      ));
    }
  });
  console.log("Swapped " + ident);
}

function markdown_decoder(ident) {
  decoder = image_decoder.images;
  for (var i = 0; i < decoder.length; i++) {
    raw_key = Object.keys(decoder[i]);
    image = decoder[i][raw_key];
    key = "(" + raw_key + ")";
    $(ident).val($(ident).val().replace(key,
      "![" + raw_key + "](" + image + ")"
    ));
  }
}

console.log("Hipchat-emoticons-for-all is enabled on " + location.href);

var image_decoder = %image_decoder%

@@ -364,16 +364,47 @@
 s).html(
+%0A        replaceAll(%0A          
 $(this).
@@ -409,30 +409,35 @@
 ).html()
-.replace(
+,%0A          
 key,%0A
+  
         
@@ -526,25 +526,35 @@
 %22'/%3E%22%0A      
-)
+  );%0A      
 );%0A    %7D%0A  %7D
@@ -828,16 +828,43 @@
 nt).val(
+%0A      replaceAll(%0A        
 $(ident)
@@ -873,22 +873,25 @@
 al()
-.replace(
+,%0A        
 key,%0A
+  
     
@@ -936,15 +936,243 @@
     
-));%0A  %7D
+  );%0A    );%0A  %7D%0A%7D%0A%0Afunction escapeRegExp(string) %7B%0A    return string.replace(/(%5B.*+?%5E=!:$%7B%7D()%7C%5C%5B%5C%5D%5C/%5C%5C%5D)/g, %22%5C%5C$1%22);%0A%7D%0A%0Afunction replaceAll(string, find, replace) %7B%0A  return string.replace(new RegExp(escapeRegExp(find), 'g'), replace);
 %0A%7D%0A%0A

Replace now does multiple recurrances of emoticon code