See
This commit is contained in:
parent
d054daaaaf
commit
74fb0eb261
|
@ -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) {
|
var _helper;
|
||||||
mutations.forEach(function(mutation) {
|
|
||||||
for(var i = 0 ; i < mutation.addedNodes.length ; ++i) {
|
function EmoteModule(helper) {
|
||||||
var next = mutation.addedNodes.item(i);
|
_helper = helper;
|
||||||
if(next) {
|
_helper.log("Emotes Initialized");
|
||||||
var nodes = getNodes(next);
|
|
||||||
for(var node in nodes) {
|
_helper.execJs('var twitchEmoteUrlStart = "' + config.EmoteModule.Twitch.EmoteUrlStart + '", twitchEmoteUrlEnd = "' + config.EmoteModule.Twitch.EmoteUrlEnd + '";');
|
||||||
injectEmote(nodes[node]);
|
_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) {
|
exports.EmoteModule = EmoteModule;
|
||||||
|
|
||||||
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 src=" + twitchEmoteUrlStart + emotesTwitch[word] + twitchEmoteUrlEnd + "><\/img>");
|
|
||||||
} else if(typeof emotesFfz !== 'undefined') {
|
|
||||||
if(emotesFfz.hasOwnProperty(word)) {
|
|
||||||
parentInnerHTML = parentInnerHTML.replace(word, "<img src=" + ffzEmoteUrlStart + emotesFfz[word] + ffzEmoteUrlEnd + "><\/img>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
parent.innerHTML = parentInnerHTML;
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue