1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
hipchat-emoticons-for-all/src/global.js

49 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

function insert_emoticons(ident, classes) {
classes = classes || "";
2015-08-28 15:52:12 +01:00
decoder = image_decoder.images;
2015-09-22 15:54:27 +01:00
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(
replaceAll(
$(this).html(),
key,
"<img class='" + classes + "' style='height: 28px; width: auto;' src='" + image + "'/>"
2015-09-25 11:27:23 +01:00
)
);
}
});
2015-08-28 15:52:12 +01:00
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(
replaceAll(
$(ident).val(),
key,
"![" + raw_key + "](" + image + ")"
2015-09-25 11:27:23 +01:00
)
);
}
}
function escapeRegExp(string) {
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
function replaceAll(string, find, replace) {
return string.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}
2015-08-28 15:52:12 +01:00
console.log("Hipchat-emoticons-for-all is enabled on " + location.href);
2015-08-24 21:42:23 +01:00
2015-09-22 15:54:27 +01:00
var image_decoder = %image_decoder%