2015-08-27 15:42:19 +02:00
|
|
|
/* BetterDiscordApp Core JavaScript
|
2015-08-29 10:48:20 +02:00
|
|
|
* Version: 1.2
|
2015-08-27 15:42:19 +02:00
|
|
|
* Author: Jiiks | http://jiiks.net
|
|
|
|
* Date: 27/08/2015 - 16:36
|
2015-08-29 10:48:20 +02:00
|
|
|
* Last Update: 29/08/2015 - 11:48
|
2015-08-27 15:42:19 +02:00
|
|
|
* https://github.com/Jiiks/BetterDiscordApp
|
|
|
|
*/
|
|
|
|
|
2015-08-29 08:55:06 +02:00
|
|
|
var settingsPanel, emoteModule, utils, quickEmoteMenu;
|
|
|
|
var jsVersion = 1.1;
|
|
|
|
|
|
|
|
var mainObserver;
|
|
|
|
|
2015-08-27 15:42:19 +02:00
|
|
|
var twitchEmoteUrlStart = "https://static-cdn.jtvnw.net/emoticons/v1/";
|
|
|
|
var twitchEmoteUrlEnd = "/1.0";
|
|
|
|
var ffzEmoteUrlStart = "https://cdn.frankerfacez.com/emoticon/";
|
|
|
|
var ffzEmoteUrlEnd = "/1";
|
|
|
|
var bttvEmoteUrlStart = "";
|
|
|
|
var bttvEmoteUrlEnd = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-29 08:55:06 +02:00
|
|
|
var settings = {
|
|
|
|
"Save logs locally": { "id": "bda-gs-0", "info": "Saves chat logs locally", "implemented":false },
|
|
|
|
"Public Servers": { "id": "bda-gs-1", "info": "Display public servers", "implemented":false},
|
|
|
|
"Quick Emote Menu": { "id": "bda-es-0", "info": "Show quick emote menu for adding emotes", "implemented":true },
|
|
|
|
"FrankerFaceZ Emotes": { "id": "bda-es-1", "info": "Show FrankerFaceZ Emotes", "implemented":true },
|
|
|
|
"BetterTTV Emotes": { "id": "bda-es-2", "info": "Show BetterTTV Emotes", "implemented":false },
|
|
|
|
"Emote Autocomplete": { "id": "bda-es-3", "info": "Autocomplete emote commands", "implemented":false },
|
|
|
|
"Emote Auto Capitalization": { "id": "bda-es-4", "info": "Autocapitalize emote commands", "implemented":true },
|
|
|
|
"Override Default Emotes": { "id": "bda-es-5", "info": "Override default emotes", "implemented":false }
|
|
|
|
};
|
|
|
|
|
2015-08-27 15:42:19 +02:00
|
|
|
|
2015-08-29 08:55:06 +02:00
|
|
|
|
|
|
|
var defaultCookie = {
|
2015-08-29 10:48:20 +02:00
|
|
|
"version":jsVersion,
|
2015-08-29 08:55:06 +02:00
|
|
|
"bda-gs-0":false,
|
|
|
|
"bda-gs-1":true,
|
|
|
|
"bda-es-0":true,
|
|
|
|
"bda-es-1":false,
|
|
|
|
"bda-es-2":false,
|
|
|
|
"bda-es-3":false,
|
|
|
|
"bda-es-4":false,
|
|
|
|
"bda-es-5":true
|
|
|
|
};
|
|
|
|
|
|
|
|
var settingsCookie = {};
|
2015-08-27 15:42:19 +02:00
|
|
|
|
|
|
|
function Core() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-29 08:55:06 +02:00
|
|
|
|
2015-08-27 15:42:19 +02:00
|
|
|
Core.prototype.init = function() {
|
|
|
|
utils = new Utils();
|
|
|
|
emoteModule = new EmoteModule();
|
|
|
|
quickEmoteMenu = new QuickEmoteMenu();
|
|
|
|
|
|
|
|
emoteModule.init();
|
|
|
|
emoteModule.autoCapitalize();
|
|
|
|
|
2015-08-29 08:55:06 +02:00
|
|
|
this.initSettings();
|
|
|
|
this.initObserver();
|
|
|
|
|
|
|
|
//Temp timeout, defer
|
2015-08-27 15:42:19 +02:00
|
|
|
setTimeout(function() {
|
|
|
|
|
|
|
|
//Settings button
|
|
|
|
$(".guilds li:first-child").after($("<li/>", {id:"tc-settings-li"}).append($("<div/>", { class: "guild-inner" }).append($("<a/>").append($("<div/>", { class: "avatar-small", id: "tc-settings-button", style: 'background-image:url("https://a96edc24045943bce10e086d4fdfb287582825b6.googledrive.com/host/0B4q1DpUVMKCofkgwdTRpWkxYdVhhdEdDYXdFa2V3eWJvbUJ5bHM3dHFDM21taHJJem5JaUU/settings_icon.png")' })))));
|
|
|
|
|
|
|
|
settingsPanel = new SettingsPanel();
|
|
|
|
settingsPanel.init();
|
2015-08-29 08:55:06 +02:00
|
|
|
quickEmoteMenu.init(false);
|
2015-08-27 15:42:19 +02:00
|
|
|
|
|
|
|
$("#tc-settings-button").on("click", function(e) { settingsPanel.show(); });
|
|
|
|
|
|
|
|
}, 3000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-29 08:55:06 +02:00
|
|
|
Core.prototype.initSettings = function() {
|
2015-08-29 10:48:20 +02:00
|
|
|
if($.cookie("better-discord") == undefined) {
|
2015-08-29 08:55:06 +02:00
|
|
|
settingsCookie = defaultCookie;
|
2015-08-29 10:48:20 +02:00
|
|
|
this.saveSettings();
|
2015-08-29 08:55:06 +02:00
|
|
|
} else {
|
2015-08-29 10:48:20 +02:00
|
|
|
this.loadSettigns();
|
2015-08-29 08:55:06 +02:00
|
|
|
|
|
|
|
for(var setting in defaultCookie) {
|
|
|
|
if(settingsCookie[setting] == undefined) {
|
|
|
|
settingsCookie = defaultCookie;
|
2015-08-29 10:48:20 +02:00
|
|
|
this.saveSettings();
|
2015-08-29 08:55:06 +02:00
|
|
|
alert("BetterDiscord settings reset due to update/error");
|
|
|
|
break;
|
|
|
|
}
|
2015-08-27 15:42:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-29 08:55:06 +02:00
|
|
|
|
2015-08-29 10:48:20 +02:00
|
|
|
Core.prototype.saveSettings = function() {
|
|
|
|
$.cookie("better-discord", JSON.stringify(settingsCookie), { expires: 365, path: '/' });
|
|
|
|
}
|
|
|
|
|
|
|
|
Core.prototype.loadSettings = function() {
|
|
|
|
settingsCookie = JSON.parse($.cookie("better-discord"));
|
|
|
|
}
|
|
|
|
|
2015-08-29 08:55:06 +02:00
|
|
|
Core.prototype.initObserver = function() {
|
|
|
|
|
|
|
|
mainObserver = new MutationObserver(function(mutations) {
|
|
|
|
mutations.forEach(function(mutation) {
|
|
|
|
if(mutation.target.getAttribute('class').indexOf("titlebar") != -1) {
|
|
|
|
quickEmoteMenu.obsCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.emoteModule.obsCallback(mutation);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
mainObserver.observe(document, { childList: true, subtree: true });
|
|
|
|
}
|