Skip to content

Instantly share code, notes, and snippets.

@sshaw sshaw/index.html forked from sasharevzin/slack.js
Last active Apr 10, 2017

Embed
What would you like to do?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Slack Message to Emoji</title>
<script src="slack.js"></script>
<style>
h1 {
text-align: center;
}
body {
width: 400px;
margin: 10px auto;
}
label {
display: block;
}
textarea {
min-height: 100px;
width: 100%;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
var emojified = document.getElementById("emojified");
document.getElementById("emojify").onclick = function(e) {
var message = document.getElementById("message"), text = message.value, result = emojify(text);
if(result.length === 0) return;
emojified.value = result;
emojified.focus();
document.execCommand("SelectAll");
document.execCommand("copy");
message.focus();
document.execCommand("SelectAll");
};
});
</script>
</head>
<body>
<h1>Slack Message to Emoji</h1>
<div>
<label for="message">Message:</label>
<textarea id="message"> </textarea>
</div>
<div>
<label for="emojified">Emojified:</label>
<textarea id="emojified"></textarea>
</div>
<button id="emojify">
Emojify!
</button>
</body>
</html>
(function(){
var ABC = {
"a": ":atrain:",
"b": ":btrain:",
"c": ":ctrain:",
"d": ":dtrain:",
"e": ":etrain:",
"f": ":ftrain:",
"g": ":gtrain:",
"h": "H",
"i": "I",
"j": ":jtrain:",
"k": "K",
"l": ":ltrain:",
"m": ":mtrain:",
"n": ":ntrain:",
"o": ":mysql:",
"p": "P",
"q": ":qtrain:",
"r": ":rtrain:",
"s": ":strain:",
"t": ":ttrain:",
"u": "U",
"v": "V",
"w": ":wtrain:",
"x": "X",
"y": "Y",
"z": ":ztrain:"
};
window.emojify = function(str){
var messages = [];
str = str.trim();
for (var i = 0; i < str.length; i++) {
var char = str.charAt(i).toLowerCase();
var replaced = ABC[char];
if(!replaced){
replaced = char;
}
messages.push(replaced);
}
return messages.join('');
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.