diff --git a/js/emotemodule.js b/js/emotemodule.js
index 8ed2e9e0..098bb4af 100644
--- a/js/emotemodule.js
+++ b/js/emotemodule.js
@@ -1,62 +1,31 @@
-var observer;
+/* BetterDiscordApp Emote Module aka TwitchCord
+ * See https://github.com/Jiiks/BetterDiscordApp/blob/master/js/emotemodule.js
+ * Version: 1.0
+ * Author: Jiiks | http://jiiks.net
+ * Date: 25/08/2015 - 09:33
+ * https://github.com/Jiiks/BetterDiscordApp
+ */
-(function() {
+var config = require("../config.json");
- observer = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- for(var i = 0 ; i < mutation.addedNodes.length ; ++i) {
- var next = mutation.addedNodes.item(i);
- if(next) {
- var nodes = getNodes(next);
- for(var node in nodes) {
- injectEmote(nodes[node]);
- }
- }
- }
+var _helper;
+
+function EmoteModule(helper) {
+ _helper = helper;
+ _helper.log("Emotes Initialized");
+
+ _helper.execJs('var twitchEmoteUrlStart = "' + config.EmoteModule.Twitch.EmoteUrlStart + '", twitchEmoteUrlEnd = "' + config.EmoteModule.Twitch.EmoteUrlEnd + '";');
+ _helper.execJs('var ffzEmoteUrlStart = "' + config.EmoteModule.FrankerFaceZ.EmoteUrlStart + '", ffzEmoteUrlEnd = "' + config.EmoteModule.FrankerFaceZ.EmoteUrlEnd + '";');
+ _helper.execJs('var bttvEmoteUrlStart = "' + config.EmoteModule.BetterTTV.EmoteUrlStart + '", bttvEmoteUrlEnd = "' + config.EmoteModule.BetterTTV.EmoteUrlEnd + '";');
+
+ _helper.download(config.Urls.Cdn + "master/" + config.EmoteModule.Twitch.EmoteData, function(twitchEmoteData) {
+ _helper.execJs("var emotesTwitch = " + twitchEmoteData + ";");
+
+ _helper.download(config.Urls.Cdn + "master/" + config.EmoteModule.FrankerFaceZ.EmoteData, function(ffzEmoteData) {
+ _helper.execJs("var emotesFfz = " + ffzEmoteData + ";");
+ _helper.injectJavaScript(config.Cdn + config.js.EmoteModule);
});
});
-
- observer.observe(document, {childList: true, subtree: true});
-
-})();
-
-function getNodes(node) {
- var next;
- var nodes = [];
-
- var treeWalker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, null, false);
-
- while(next = treeWalker.nextNode()) {
- nodes.push(next);
- }
-
- return nodes;
}
-function injectEmote(node) {
-
- if(typeof emotesTwitch === 'undefined') return;
-
- if(!node.parentElement) return;
-
- var parent = node.parentElement;
- if(parent.tagName != "SPAN") return;
-
- var parentInnerHTML = parent.innerHTML;
- var words = parentInnerHTML.split(" ");
-
- if(!words) return;
-
- words.some(function(word) {
- if (emotesTwitch.hasOwnProperty(word)) {
- parentInnerHTML = parentInnerHTML.replace(word, "<\/img>");
- } else if(typeof emotesFfz !== 'undefined') {
- if(emotesFfz.hasOwnProperty(word)) {
- parentInnerHTML = parentInnerHTML.replace(word, "<\/img>");
- }
- }
- });
-
- parent.innerHTML = parentInnerHTML;
-
-}
+exports.EmoteModule = EmoteModule;
\ No newline at end of file