Skip to content

Instantly share code, notes, and snippets.

@jasisk
Last active August 29, 2015 14:04
Show Gist options
  • Save jasisk/033edd6498648cf60a2e to your computer and use it in GitHub Desktop.
Save jasisk/033edd6498648cf60a2e to your computer and use it in GitHub Desktop.
SUPERSEDED: jasisk/slack-emoji-randomizer - Slack userscript to replace all your emojis with 🦀
(function () {
function replaceText(msg, replaceWith) {
emoji.init_colons();
msg = emoji.replace_emoticons_with_colons(msg);
return msg.replace(emoji.rx_colons, function (colonEmoji) {
var emojiKey = colonEmoji.substr(1, colonEmoji.length-2);
var replacement = emoji.map.colons[emojiKey];
return replacement ? replaceWith : colonEmoji;
});
}
TS.channels.onSendMsg = (function (original) {
return function (ok, msg) {
var channel;
if (ok) {
channel = TS.channels.getChannelById(msg.SENT_MSG.channel);
setTimeout(function () {
var newText = replaceText(msg.text, ':crab:');
if (newText !== msg.text) {
TS.msg_edit.commitEdit(msg, channel, newText);
}
}, 2000);
}
return original.apply(this, arguments);
};
}(TS.channels.onSendMsg));
}());
@jasisk
Copy link
Author

jasisk commented Jul 17, 2014

Randomly selected replacements with:

var emojis = Object.keys(emoji.map.colons);

function getRandomEmoji() {
  var randomIdx = Math.floor(Math.random() * emojis.length);
  return ':' + emojis[randomIdx] + ':';
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment