diff --git a/src/global.js b/src/global.js index 01a6236..5e60061 100644 --- a/src/global.js +++ b/src/global.js @@ -7,9 +7,13 @@ function insert_emoticons(ident, classes) { key = Object.keys(decoder[i]); image = decoder[i][key]; key = "(" + key + ")"; - $(this).html($(this).html().replace(key, - "" - )); + $(this).html( + replaceAll( + $(this).html(), + key, + "" + ); + ); } }); console.log("Swapped " + ident); @@ -21,12 +25,24 @@ function markdown_decoder(ident) { raw_key = Object.keys(decoder[i]); image = decoder[i][raw_key]; key = "(" + raw_key + ")"; - $(ident).val($(ident).val().replace(key, - "![" + raw_key + "](" + image + ")" - )); + $(ident).val( + replaceAll( + $(ident).val(), + key, + "![" + raw_key + "](" + image + ")" + ); + ); } } +function escapeRegExp(string) { + return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); +} + +function replaceAll(string, find, replace) { + return string.replace(new RegExp(escapeRegExp(find), 'g'), replace); +} + console.log("Hipchat-emoticons-for-all is enabled on " + location.href); var image_decoder = %image_decoder%