Last active
July 25, 2016 14:10
-
-
Save Spartan322/20bc9f40db461e4acb301da88ebfef31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//META{"name":"emojiAPI"}*// | |
var emojiAPI = function () {}; | |
emojiAPI.prototype.emojiList = {}; | |
emojiAPI.prototype.addEmoji = function(containerId, json) { | |
var emoji = JSON.parse(json); | |
emojiAPI.prototype.emojiList[containerId] = emoji; | |
}; | |
emojiAPI.prototype.findCidByName = function(name) { | |
var list = emojiAPI.prototype.emojiList | |
for(var container in list) { | |
var emoji = container.find(function(obj){ obj.name === name; }); | |
if(emoji!==undefined) return emoji; | |
} | |
}; | |
emojiAPI.prototype.onConvert = function() { | |
$(".message-group .message-text .markup").each(function() { | |
var html = $(this).html(); | |
var title, cid, name; | |
html = html.replace(/\[[^\[\]]*\]\(([^\(\)]*:|)\/[^\(\)]+\)/ig, function(word, position, full){ | |
var begin = word.indexOf('['); | |
var end = word.indexOf(']'); | |
title = word.substring(begin+1, end-1); | |
begin = word.indexOf('(', end); | |
end = word.indexOf(':', begin); | |
if(end===-1) {cid = undefined;} | |
else { | |
cid = word.substring(begin+1, end-1); | |
} | |
begin = end===-1?begin:end; | |
end = word.indexOf(')', begin); | |
name = word.substring(being+1, end-1); | |
if(cid===undefined) { | |
cid = this.findCidByName(name); | |
} | |
var emoji = emojiAPI.prototype.emojiList[cid].find(function(obj){ return obj.name === name }); | |
if(emoji===undefined) { return word; } | |
var imgLink = emoji.image, t = emoji.top, l = emoji.left, r = emoji.right, b = emoji.bottom; | |
return "<img src='"+imgLink+"' title='"+title+" (Emoji: "+name+")' style='clip-path: inset("+t+" "+r+" "+b+" "+l+")'>" | |
}); | |
if($(this).html().localeCompare(html) !== 0) {$(this).replaceWith(html);} | |
}); | |
}; | |
emojiAPI.prototype.start = function() { | |
this.onConvert(); | |
}; | |
emojiAPI.prototype.stop = function() { | |
}; | |
emojiAPI.prototype.load = function() { | |
}; | |
emojiAPI.prototype.onMessage = function() { | |
this.onConvert(); | |
}; | |
emojiAPI.prototype.onSwitch = function() { | |
this.onConvert(); | |
}; | |
emojiAPI.prototype.socketEvent = function(data) { | |
}; | |
emojiAPI.prototype.observer = function(e) { | |
}; | |
emojiAPI.prototype.getSettingsPanel = function() { | |
}; | |
emojiAPI.prototype.getName = function() { | |
return "EmojiAPI"; | |
}; | |
emojiAPI.prototype.getDescription = function() { | |
return "Allows the creation of customized emojis through plugins"; | |
}; | |
emojiAPI.prototype.getVersion = function() { | |
return "0.1.0"; | |
}; | |
emojiAPI.prototype.getAuthor = function() { | |
return "Spartan322 (George Albany)"; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment