Skip to content

Instantly share code, notes, and snippets.

@EhsanKia
Last active February 12, 2017 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EhsanKia/37db62596ee56ff2d866 to your computer and use it in GitHub Desktop.
Save EhsanKia/37db62596ee56ff2d866 to your computer and use it in GitHub Desktop.
Rabb.it Twitch emotes
var twitchEmotes = {};
var bttvEmotes = {};
$.getJSON('https://twitchemotes.com/api_cache/v2/global.json', function(data) {
$.each(data.emotes, function(key, val) {
twitchEmotes[key] = val.image_id;
});
})
$.getJSON('https://twitchemotes.com/api_cache/v2/subscriber.json', function(data) {
$.each(data.channels, function(key, val){
$.each(val.emotes, function(key, val) {
twitchEmotes[val.code] = val.image_id;
});
});
});
$.getJSON('https://api.betterttv.net/2/emotes', function(data) {
$.each(data.emotes, function(key, val) {
bttvEmotes[val.code] = val.id;
});
});
$.getJSON('https://cdn.rawgit.com/Jiiks/BetterDiscordApp/master/data/emotedata_bttv.json', function(data) {
$.each(data, function(key, val) {
bttvEmotes[key] = val;
});
});
function emotify() {
$('.messages .messageBody').each(function(i, el) {
var node = $(el);
if (node.hasClass('emoted')) return;
var text = node.text().trim();
var words = text.split(/\s+/g);
var html = node.html();
words.some(function(word) {
var url = undefined;
if (twitchEmotes.hasOwnProperty(word)) {
url = "https://static-cdn.jtvnw.net/emoticons/v1/" + twitchEmotes[word] + "/1.0";
}
if (bttvEmotes.hasOwnProperty(word)) {
url = "https://cdn.betterttv.net/emote/" + bttvEmotes[word] + "/1x";
}
if (url === undefined) return;
var emoteHTML = '<img class="emote" src="' + url + '" />';
html = html.replace(word, emoteHTML);
});
node.html(html);
node.addClass("emoted");
});
}
$('body').bind("DOMSubtreeModified", function() {
emotify();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment