2015-08-26 10:47:30 +02:00
|
|
|
/* BetterDiscordApp EmoteModule JavaScript
|
2015-10-26 06:27:55 +01:00
|
|
|
* Version: 1.5
|
2015-08-26 10:47:30 +02:00
|
|
|
* Author: Jiiks | http://jiiks.net
|
2015-08-27 15:28:43 +02:00
|
|
|
* Date: 26/08/2015 - 15:29
|
2015-10-14 08:50:34 +02:00
|
|
|
* Last Update: 14/10/2015 - 09:48
|
2015-08-26 10:47:30 +02:00
|
|
|
* https://github.com/Jiiks/BetterDiscordApp
|
2015-08-26 16:21:02 +02:00
|
|
|
* Note: Due to conflicts autocapitalize only supports global emotes
|
2015-08-26 10:47:30 +02:00
|
|
|
*/
|
2015-08-25 13:26:36 +02:00
|
|
|
|
2015-10-26 06:27:55 +01:00
|
|
|
/*
|
|
|
|
* =Changelog=
|
|
|
|
* -v1.5
|
|
|
|
* --Twitchemotes.com api
|
|
|
|
*/
|
|
|
|
|
2015-08-26 16:21:02 +02:00
|
|
|
var emotesFfz = {};
|
|
|
|
var emotesBTTV = {};
|
2016-04-10 14:43:27 +02:00
|
|
|
var emotesTwitch = {
|
|
|
|
"emotes": {
|
|
|
|
"emote": {
|
|
|
|
"image_id": 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}; //for ide
|
2015-10-26 06:27:55 +01:00
|
|
|
var subEmotesTwitch = {};
|
2015-08-25 13:26:36 +02:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
function EmoteModule() {}
|
2015-08-26 14:52:48 +02:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
EmoteModule.prototype.init = function () {};
|
2015-08-29 08:55:06 +02:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
EmoteModule.prototype.getBlacklist = function () {
|
|
|
|
$.getJSON("https://cdn.rawgit.com/Jiiks/betterDiscordApp/" + _hash + "/data/emotefilter.json", function (data) {
|
|
|
|
bemotes = data.blacklist;
|
|
|
|
});
|
2015-12-16 12:21:46 +01:00
|
|
|
};
|
2015-08-25 14:43:53 +02:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
EmoteModule.prototype.obsCallback = function (mutation) {
|
2015-08-29 08:55:06 +02:00
|
|
|
var self = this;
|
2015-12-16 12:21:46 +01:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
if (!settingsCookie["bda-es-7"]) return;
|
|
|
|
|
|
|
|
$(".emoji").each(function () {
|
|
|
|
var t = $(this);
|
|
|
|
if (t.attr("src").indexOf(".png") != -1) {
|
|
|
|
|
|
|
|
var next = t.next();
|
|
|
|
var newText = t.attr("alt");
|
|
|
|
if(next.size() > 0) {
|
|
|
|
if(next.prop("tagName") == "SPAN") {
|
|
|
|
newText += next.text();
|
|
|
|
next.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(t.parent().prop("tagName") != "SPAN") {
|
|
|
|
t.replaceWith("<span>" + newText + "</span>");
|
|
|
|
} else {
|
|
|
|
t.replaceWith(newText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-12-16 12:21:46 +01:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
for (var i = 0; i < mutation.addedNodes.length; ++i) {
|
2015-08-29 08:55:06 +02:00
|
|
|
var next = mutation.addedNodes.item(i);
|
2016-04-10 14:43:27 +02:00
|
|
|
if (next) {
|
2015-08-29 08:55:06 +02:00
|
|
|
var nodes = self.getNodes(next);
|
2016-04-10 14:43:27 +02:00
|
|
|
for (var node in nodes) {
|
|
|
|
if (nodes.hasOwnProperty(node)) {
|
2015-10-26 06:27:55 +01:00
|
|
|
self.injectEmote(nodes[node]);
|
|
|
|
}
|
2015-08-29 08:55:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-26 06:27:55 +01:00
|
|
|
};
|
2015-08-25 14:43:53 +02:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
EmoteModule.prototype.getNodes = function (node) {
|
2015-08-25 14:56:32 +02:00
|
|
|
var next;
|
|
|
|
var nodes = [];
|
2015-08-25 14:43:53 +02:00
|
|
|
|
2015-08-25 14:56:32 +02:00
|
|
|
var treeWalker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, null, false);
|
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
while (next = treeWalker.nextNode()) {
|
2015-08-25 14:56:32 +02:00
|
|
|
nodes.push(next);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nodes;
|
2015-10-26 06:27:55 +01:00
|
|
|
};
|
2015-08-26 14:52:48 +02:00
|
|
|
|
2015-12-16 12:21:46 +01:00
|
|
|
var bemotes = [];
|
|
|
|
var spoilered = [];
|
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
EmoteModule.prototype.injectEmote = function (node) {
|
2015-08-25 14:56:32 +02:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
if (typeof emotesTwitch === 'undefined') return;
|
2015-08-25 14:56:32 +02:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
if (!node.parentElement) return;
|
2015-08-25 14:56:32 +02:00
|
|
|
|
|
|
|
var parent = node.parentElement;
|
2015-12-16 12:21:46 +01:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
if (parent.tagName != "SPAN") return;
|
|
|
|
if (!$(parent.parentElement).hasClass("markup") && !$(parent.parentElement).hasClass("message-content")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-16 12:21:46 +01:00
|
|
|
var edited = false;
|
2016-04-10 14:43:27 +02:00
|
|
|
|
|
|
|
if ($(parent.parentElement).hasClass("edited")) {
|
|
|
|
parent = parent.parentElement.parentElement.firstChild;
|
2015-12-16 12:21:46 +01:00
|
|
|
edited = true;
|
|
|
|
}
|
2015-08-25 14:56:32 +02:00
|
|
|
|
2015-12-16 12:21:46 +01:00
|
|
|
function inject() {
|
|
|
|
var parentInnerHTML = parent.innerHTML;
|
|
|
|
var words = parentInnerHTML.split(/\s+/g);
|
2015-08-25 14:56:32 +02:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
if (!words) return;
|
2015-12-16 12:21:46 +01:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
words.some(function (word) {
|
|
|
|
if (word.slice(0, 4) == "[!s]") {
|
2015-12-16 12:21:46 +01:00
|
|
|
|
|
|
|
parentInnerHTML = parentInnerHTML.replace("[!s]", "");
|
|
|
|
var markup = $(parent).parent();
|
|
|
|
var reactId = markup.attr("data-reactid");
|
2016-04-10 14:43:27 +02:00
|
|
|
|
|
|
|
if (spoilered.indexOf(reactId) > -1) {
|
2015-12-16 12:21:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
markup.addClass("spoiler");
|
2016-04-10 14:43:27 +02:00
|
|
|
markup.on("click", function () {
|
2015-12-16 12:21:46 +01:00
|
|
|
$(this).removeClass("spoiler");
|
|
|
|
spoilered.push($(this).attr("data-reactid"));
|
|
|
|
});
|
2015-10-26 06:27:55 +01:00
|
|
|
|
|
|
|
return;
|
2015-08-25 14:56:32 +02:00
|
|
|
}
|
2016-04-10 14:43:27 +02:00
|
|
|
|
|
|
|
if (word.length < 4) {
|
2015-10-26 06:27:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
if (word == "ClauZ") {
|
|
|
|
parentInnerHTML = parentInnerHTML.replace("ClauZ", '<img src="https://cdn.frankerfacez.com/emoticon/70852/1" style="width:25px; transform:translate(-29px, -14px);"></img>');
|
|
|
|
return;
|
|
|
|
}
|
2015-08-25 14:56:32 +02:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
var useEmoteCss = false;
|
|
|
|
var sWord = word;
|
|
|
|
var emoteClass = "";
|
|
|
|
var allowedClasses = ["emoteflip", "emotespin", "emotepulse", "emotespin2", "emotespin3", "emote1spin", "emote2spin", "emote3spin", "emotetr", "emotebl", "emotebr", "emoteshake", "emoteshake2", "emoteshake3", "emoteflap"];
|
|
|
|
if(word.indexOf(":") > -1) {
|
|
|
|
var split = word.split(/:(?!.*:)/);
|
|
|
|
if (split[0] != "" && split[1] != "") {
|
|
|
|
userEmoteCss = true;
|
|
|
|
sWord = split[0];
|
|
|
|
if(settingsCookie["bda-es-8"]) {
|
|
|
|
emoteClass = "emote" + split[1];
|
|
|
|
if(allowedClasses.indexOf(emoteClass) < 0) {
|
|
|
|
emoteClass = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($.inArray(sWord, bemotes) != -1) return;
|
|
|
|
|
|
|
|
if (emotesTwitch.emotes.hasOwnProperty(sWord)) {
|
|
|
|
var len = Math.round(sWord.length / 4);
|
|
|
|
var name = sWord.substr(0, len) + "\uFDD9" + sWord.substr(len, len) + "\uFDD9" + sWord.substr(len * 2, len) + "\uFDD9" + sWord.substr(len * 3);
|
|
|
|
var url = twitchEmoteUrlStart + emotesTwitch.emotes[sWord].image_id + twitchEmoteUrlEnd;
|
|
|
|
parentInnerHTML = parentInnerHTML.replace(word, '<div class="emotewrapper"><img class="emote '+emoteClass+'" alt="' + name + '" src="' + url + '"/><input onclick=\'quickEmoteMenu.favorite(\"' + name + '\", \"' + url + '\");\' class="fav" title="Favorite!" type="button"></div>');
|
2015-12-16 12:21:46 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-10-26 06:27:55 +01:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
if (subEmotesTwitch.hasOwnProperty(sWord)) {
|
|
|
|
var len = Math.round(sWord.length / 4);
|
|
|
|
var name = sWord.substr(0, len) + "\uFDD9" + sWord.substr(len, len) + "\uFDD9" + sWord.substr(len * 2, len) + "\uFDD9" + sWord.substr(len * 3);
|
|
|
|
var url = twitchEmoteUrlStart + subEmotesTwitch[sWord] + twitchEmoteUrlEnd;
|
|
|
|
parentInnerHTML = parentInnerHTML.replace(word, '<div class="emotewrapper"><img class="emote '+emoteClass+'" alt="' + name + '" src="' + url + '"/><input onclick=\'quickEmoteMenu.favorite(\"' + name + '\", \"' + url + '\");\' class="fav" title="Favorite!" type="button"></div>');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-16 12:21:46 +01:00
|
|
|
if (typeof emotesFfz !== 'undefined' && settingsCookie["bda-es-1"]) {
|
2016-04-10 14:43:27 +02:00
|
|
|
if (emotesFfz.hasOwnProperty(sWord)) {
|
|
|
|
var len = Math.round(sWord.length / 4);
|
|
|
|
var name = sWord.substr(0, len) + "\uFDD9" + sWord.substr(len, len) + "\uFDD9" + sWord.substr(len * 2, len) + "\uFDD9" + sWord.substr(len * 3);
|
|
|
|
var url = ffzEmoteUrlStart + emotesFfz[sWord] + ffzEmoteUrlEnd;
|
|
|
|
parentInnerHTML = parentInnerHTML.replace(word, '<div class="emotewrapper"><img class="emote '+emoteClass+'" alt="' + name + '" src="' + url + '"/><input onclick=\'quickEmoteMenu.favorite(\"' + name + '\", \"' + url + '\");\' class="fav" title="Favorite!" type="button"></div>');
|
2015-12-16 12:21:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-10-14 08:50:34 +02:00
|
|
|
|
2015-12-16 12:21:46 +01:00
|
|
|
if (typeof emotesBTTV !== 'undefined' && settingsCookie["bda-es-2"]) {
|
2016-04-10 14:43:27 +02:00
|
|
|
if (emotesBTTV.hasOwnProperty(sWord)) {
|
|
|
|
var len = Math.round(sWord.length / 4);
|
|
|
|
var name = sWord.substr(0, len) + "\uFDD9" + sWord.substr(len, len) + "\uFDD9" + sWord.substr(len * 2, len) + "\uFDD9" + sWord.substr(len * 3);
|
|
|
|
var url = emotesBTTV[sWord];
|
|
|
|
parentInnerHTML = parentInnerHTML.replace(word, '<div class="emotewrapper"><img class="emote '+emoteClass+'" alt="' + name + '" src="' + url + '"/><input onclick=\'quickEmoteMenu.favorite(\"' + name + '\", \"' + url + '\");\' class="fav" title="Favorite!" type="button"></div>');
|
2015-12-16 12:21:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-04-10 14:43:27 +02:00
|
|
|
|
|
|
|
if (typeof emotesBTTV2 !== 'undefined' && settingsCookie["bda-es-2"]) {
|
|
|
|
if (emotesBTTV2.hasOwnProperty(sWord)) {
|
|
|
|
var len = Math.round(sWord.length / 4);
|
|
|
|
var name = sWord.substr(0, len) + "\uFDD9" + sWord.substr(len, len) + "\uFDD9" + sWord.substr(len * 2, len) + "\uFDD9" + sWord.substr(len * 3);
|
|
|
|
var url = bttvEmoteUrlStart + emotesBTTV2[sWord] + bttvEmoteUrlEnd;
|
|
|
|
parentInnerHTML = parentInnerHTML.replace(word, '<div class="emotewrapper"><img class="emote '+emoteClass+'" alt="' + name + '" src="' + url + '"/><input onclick=\'quickEmoteMenu.favorite(\"' + name + '\", \"' + url + '\");\' class="fav" title="Favorite!" type="button"></div>');
|
2015-12-16 12:21:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
if (parent.parentElement == null) return;
|
2015-12-16 12:21:46 +01:00
|
|
|
|
|
|
|
var oldHeight = parent.parentElement.offsetHeight;
|
|
|
|
parent.innerHTML = parentInnerHTML.replace(new RegExp("\uFDD9", "g"), "");
|
|
|
|
var newHeight = parent.parentElement.offsetHeight;
|
|
|
|
|
|
|
|
var scrollPane = $(".scroller.messages").first();
|
|
|
|
scrollPane.scrollTop(scrollPane.scrollTop() + (newHeight - oldHeight));
|
2016-04-10 14:43:27 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edited) {
|
|
|
|
setTimeout(inject, 250);
|
|
|
|
} else {
|
|
|
|
inject();
|
|
|
|
}
|
2015-10-26 06:27:55 +01:00
|
|
|
};
|
2015-08-26 16:21:02 +02:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
EmoteModule.prototype.autoCapitalize = function () {
|
2015-12-16 12:21:46 +01:00
|
|
|
|
2015-08-26 16:21:02 +02:00
|
|
|
var self = this;
|
2015-08-31 15:36:28 +02:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
$('body').delegate($(".channel-textarea-inner textarea"), 'keyup change paste', function () {
|
|
|
|
if (!settingsCookie["bda-es-4"]) return;
|
2015-08-26 18:39:04 +02:00
|
|
|
|
2015-12-16 12:21:46 +01:00
|
|
|
var text = $(".channel-textarea-inner textarea").val();
|
2015-08-29 10:48:20 +02:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
if (text == undefined) return;
|
2015-08-29 10:48:20 +02:00
|
|
|
|
2015-08-26 16:21:02 +02:00
|
|
|
var lastWord = text.split(" ").pop();
|
2016-04-10 14:43:27 +02:00
|
|
|
if (lastWord.length > 3) {
|
|
|
|
if (lastWord == "danSgame") return;
|
2015-08-26 16:21:02 +02:00
|
|
|
var ret = self.capitalize(lastWord.toLowerCase());
|
2016-04-10 14:43:27 +02:00
|
|
|
if (ret !== null && ret !== undefined) {
|
2015-12-16 12:21:46 +01:00
|
|
|
$(".channel-textarea-inner textarea").val(text.replace(lastWord, ret));
|
2015-08-26 16:21:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-10-26 06:27:55 +01:00
|
|
|
};
|
2015-08-26 16:21:02 +02:00
|
|
|
|
2016-04-10 14:43:27 +02:00
|
|
|
EmoteModule.prototype.capitalize = function (value) {
|
2015-12-16 12:21:46 +01:00
|
|
|
var res = emotesTwitch.emotes;
|
2016-04-10 14:43:27 +02:00
|
|
|
for (var p in res) {
|
|
|
|
if (res.hasOwnProperty(p) && value == (p + '').toLowerCase()) {
|
2015-12-16 12:21:46 +01:00
|
|
|
return p;
|
|
|
|
}
|
2015-08-26 16:21:02 +02:00
|
|
|
}
|
2015-10-26 06:27:55 +01:00
|
|
|
};
|