BetterDiscordApp-v2/js/emotemodule.js

138 lines
7.1 KiB
JavaScript
Raw Normal View History

2015-08-26 10:47:30 +02:00
/* BetterDiscordApp EmoteModule JavaScript
* 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
/*
* =Changelog=
* -v1.5
* --Twitchemotes.com api
*/
2015-08-26 16:21:02 +02:00
var emotesFfz = {};
var emotesBTTV = {};
var emotesTwitch = { "emotes": { "emote": { "image_id": 0 } } }; //for ide
var subEmotesTwitch = {};
2015-08-25 13:26:36 +02:00
//TODO Use emotesTwitch for autocap
var twitchAc = {"4head":"4Head","anele":"ANELE","argieb8":"ArgieB8","arsonnosexy":"ArsonNoSexy","asianglow":"AsianGlow","atgl":"AtGL","athenapms":"AthenaPMS","ativy":"AtIvy","atww":"AtWW","babyrage":"BabyRage","batchest":"BatChest","bcwarrior":"BCWarrior","biblethump":"BibleThump","bigbrother":"BigBrother","bionicbunion":"BionicBunion","blargnaut":"BlargNaut","bloodtrail":"BloodTrail","bort":"BORT","brainslug":"BrainSlug","brokeback":"BrokeBack","buddhabar":"BuddhaBar","coolcat":"CoolCat","corgiderp":"CorgiDerp","cougarhunt":"CougarHunt","daesuppy":"DAESuppy","dansgame":"DansGame","dathass":"DatHass","datsheffy":"DatSheffy","dbstyle":"DBstyle","deexcite":"deExcite","deilluminati":"deIlluminati","dendiface":"DendiFace","dogface":"DogFace","doomguy":"DOOMGuy","eagleeye":"EagleEye","elegiggle":"EleGiggle","evilfetus":"EvilFetus","failfish":"FailFish","fpsmarksman":"FPSMarksman","frankerz":"FrankerZ","freakinstinkin":"FreakinStinkin","fungineer":"FUNgineer","funrun":"FunRun","fuzzyotteroo":"FuzzyOtterOO","gasjoker":"GasJoker","gingerpower":"GingerPower","grammarking":"GrammarKing","hassanchop":"HassanChop","heyguys":"HeyGuys","hotpokket":"HotPokket","humblelife":"HumbleLife","itsboshytime":"ItsBoshyTime","jebaited":"Jebaited","jkanstyle":"JKanStyle","joncarnage":"JonCarnage","kapow":"KAPOW","kappa":"Kappa","kappapride":"KappaPride","keepo":"Keepo","kevinturtle":"KevinTurtle","kippa":"Kippa","kreygasm":"Kreygasm","kzskull":"KZskull","mau5":"Mau5","mcat":"mcaT","mechasupes":"MechaSupes","mrdestructoid":"MrDestructoid","mvgame":"MVGame","nightbat":"NightBat","ninjatroll":"NinjaTroll","nonospot":"NoNoSpot","notatk":"NotATK","notlikethis":"NotLikeThis","omgscoots":"OMGScoots","onehand":"OneHand","opieop":"OpieOP","optimizeprime":"OptimizePrime","osbeaver":"OSbeaver","osbury":"OSbury","osdeo":"OSdeo","osfrog":"OSfrog","oskomodo":"OSkomodo","osrob":"OSrob","ossloth":"OSsloth","panicbasket":"panicBasket","panicvis":"PanicVis","pazpazowitz":"PazPazowitz","peopleschamp":"PeoplesChamp","permasmug":"PermaSmug","picomause":"PicoMause","pipehype":"PipeHype","pjharley":"PJHarley","pjsalt":"PJSalt","pmstwin":"PMSTwin","pogchamp":"PogChamp","poooound":"Poooound","praiseit":"PraiseIt","prchase":"PRChase","punchtrees":"PunchTrees","puppeyface":"PuppeyFace","raccattack":"RaccAttack","ralpherz":"RalpherZ","redcoat":"RedCoat","residentsleeper":"ResidentSleeper","ritzmitz":"RitzMitz","rulefive":"RuleFive","shadylulu":"ShadyLulu","shazam":"Shazam","shazamicon":"shazamicon","shazbotstix":"ShazBotstix","shibez":"ShibeZ","smorc":"SMOrc","smskull":"SMSkull","sobayed":"SoBayed","soonerlater":"SoonerLater","srihead":"SriHead","ssssss":"SSSsss","stonelightning":"StoneLightning","strawbeary":"StrawBeary","supervinlin":"SuperVinlin","swiftrage":"SwiftRage","tbbaconbiscuit":"tbBaconBiscuit","tbchickenbiscuit":"tbChickenBiscuit","tbquesarito":"tbQuesarito","tbsausagebiscuit":"tbSausageBiscuit","tbspicy":"tbSpicy","tbsriracha":"tbSriracha","tf2john":"TF2John","theking":"TheKing","theringer":"TheRinger","thetarfu":"TheTarFu","thething":"TheThing","thunbeast":"ThunBeast","tinyface":"TinyFace","toospicy":"TooSpicy","trihard":"TriHard","ttours":"TTours","uleetbackup":"UleetBackup","unclenox":"UncleNox","unsane":"UnSane","vaultboy":"VaultBoy","volcania":"Volcania","wholewheat":"WholeWheat","winwaker":"WinWaker","wtruck":"WTRuck","wutface":"WutFace","youwhy":"YouWHY"};
2015-08-26 14:52:48 +02:00
function EmoteModule() {}
2015-08-29 08:55:06 +02:00
EmoteModule.prototype.init = function() {};
2015-08-25 14:43:53 +02:00
2015-08-29 08:55:06 +02:00
EmoteModule.prototype.obsCallback = function(mutation) {
var self = this;
for(var i = 0 ; i < mutation.addedNodes.length ; ++i) {
var next = mutation.addedNodes.item(i);
if(next) {
var nodes = self.getNodes(next);
for(var node in nodes) {
if(nodes.hasOwnProperty(node)) {
self.injectEmote(nodes[node]);
}
2015-08-29 08:55:06 +02:00
}
}
}
};
2015-08-25 14:43:53 +02:00
2015-08-26 14:52:48 +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);
while(next = treeWalker.nextNode()) {
nodes.push(next);
}
return nodes;
};
2015-08-26 14:52:48 +02:00
//TODO Functional titles
2015-08-26 14:52:48 +02:00
EmoteModule.prototype.injectEmote = function(node) {
2015-08-25 14:56:32 +02:00
if(typeof emotesTwitch === 'undefined') return;
if(!node.parentElement) return;
var parent = node.parentElement;
if(parent.tagName != "SPAN") return;
var parentInnerHTML = parent.innerHTML;
2015-11-12 13:31:52 +01:00
var words = parentInnerHTML.split(/\s+/g);
2015-08-25 14:56:32 +02:00
if(!words) return;
words.some(function(word) {
if(word.length < 4) {
return;
}
if(emotesTwitch.emotes.hasOwnProperty(word)) {
parentInnerHTML = parentInnerHTML.replace(word, "<img src=" + twitchEmoteUrlStart + emotesTwitch.emotes[word].image_id + twitchEmoteUrlEnd + " ><\/img>");
return;
}
if(typeof emotesFfz !== 'undefined' && settingsCookie["bda-es-1"]) {
2015-08-25 14:56:32 +02:00
if(emotesFfz.hasOwnProperty(word)) {
parentInnerHTML = parentInnerHTML.replace(word, "<img src=" + ffzEmoteUrlStart + emotesFfz[word] + ffzEmoteUrlEnd + " ><\/img>");
return;
2015-08-25 14:56:32 +02:00
}
}
if(typeof emotesBTTV !== 'undefined' && settingsCookie["bda-es-2"]) {
if(emotesBTTV.hasOwnProperty(word)) {
parentInnerHTML = parentInnerHTML.replace(word, "<img src=" + emotesBTTV[word] + " ><\/img>");
return;
}
}
if (subEmotesTwitch.hasOwnProperty(word)) {
parentInnerHTML = parentInnerHTML.replace(word, "<img src=" + twitchEmoteUrlStart + subEmotesTwitch[word] + twitchEmoteUrlEnd + " ><\/img>");
}
2015-08-25 14:56:32 +02:00
});
if(parent.parentElement == null) return;
2015-10-14 08:50:34 +02:00
var oldHeight = parent.parentElement.offsetHeight;
2015-08-25 14:56:32 +02:00
parent.innerHTML = parentInnerHTML;
2015-10-14 08:50:34 +02:00
var newHeight = parent.parentElement.offsetHeight;
//Scrollfix
var scrollPane = $(".scroller.messages").first();
2015-10-14 08:50:34 +02:00
scrollPane.scrollTop(scrollPane.scrollTop() + (newHeight - oldHeight));
};
2015-08-26 16:21:02 +02:00
EmoteModule.prototype.autoCapitalize = function() {
var self = this;
var textArea = $(".channel-textarea-inner textarea");
2015-08-31 15:36:28 +02:00
$('body').delegate(textArea, 'keyup change paste', function() {
2015-08-29 10:48:20 +02:00
if(!settingsCookie["bda-es-4"]) return;
2015-08-26 18:39:04 +02:00
var text = textArea.val();
2015-08-29 10:48:20 +02:00
if(text == undefined) return;
2015-08-26 16:21:02 +02:00
var lastWord = text.split(" ").pop();
if(lastWord.length > 3) {
var ret = self.capitalize(lastWord.toLowerCase());
if(ret != null) {
textArea.val(text.replace(lastWord, ret));
2015-08-26 16:21:02 +02:00
}
}
});
};
2015-08-26 16:21:02 +02:00
EmoteModule.prototype.capitalize = function(value) {
if(twitchAc.hasOwnProperty(value)) {
return twitchAc[value];
}
return null;
};