2015-08-27 15:42:19 +02:00
/ * B e t t e r D i s c o r d A p p C o r e J a v a S c r i p t
2016-04-10 14:43:27 +02:00
* Version : 1.53
2015-08-27 15:42:19 +02:00
* Author : Jiiks | http : //jiiks.net
* Date : 27 / 08 / 2015 - 16 : 36
2016-04-10 14:43:27 +02:00
* Last Update : 02 / 04 / 2016
2015-08-27 15:42:19 +02:00
* https : //github.com/Jiiks/BetterDiscordApp
* /
2016-04-10 14:43:27 +02:00
var settingsPanel , emoteModule , utils , quickEmoteMenu , opublicServers , voiceMode , pluginModule , themeModule , customCssEditor ;
var jsVersion = 1.63 ;
var supportedVersion = "0.2.5" ;
2015-08-29 08:55:06 +02:00
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" ;
2015-12-16 12:21:46 +01:00
var bttvEmoteUrlStart = "https://cdn.betterttv.net/emote/" ;
var bttvEmoteUrlEnd = "/1x" ;
2015-08-27 15:42:19 +02:00
2015-10-26 06:27:55 +01:00
var mainCore ;
2015-08-27 15:42:19 +02:00
2015-08-29 08:55:06 +02:00
var settings = {
2016-04-10 14:43:27 +02:00
"Save logs locally" : { "id" : "bda-gs-0" , "info" : "Saves chat logs locally" , "implemented" : false , "hidden" : false , "cat" : "core" } ,
"Public Servers" : { "id" : "bda-gs-1" , "info" : "Display public servers button" , "implemented" : true , "hidden" : false , "cat" : "core" } ,
"Minimal Mode" : { "id" : "bda-gs-2" , "info" : "Hide elements and reduce the size of elements." , "implemented" : true , "hidden" : false , "cat" : "core" } ,
"Voice Mode" : { "id" : "bda-gs-4" , "info" : "Only show voice chat" , "implemented" : true , "hidden" : false , "cat" : "core" } ,
"Hide Channels" : { "id" : "bda-gs-3" , "info" : "Hide channels in minimal mode" , "implemented" : true , "hidden" : false , "cat" : "core" } ,
"Dark Mode" : { "id" : "bda-gs-5" , "info" : "Make certain elements dark by default(wip)" , "implemented" : true , "hidden" : false , "cat" : "core" } ,
"Override Default Emotes" : { "id" : "bda-es-5" , "info" : "Override default emotes" , "implemented" : false , "hidden" : false , "cat" : "core" } ,
"Voice Disconnect" : { "id" : "bda-dc-0" , "info" : "Disconnect from voice server when closing Discord" , "implemented" : true , "hidden" : false , "cat" : "core" } ,
"Custom css live update" : { "id" : "bda-css-0" , "info" : "" , "implemented" : true , "hidden" : true , "cat" : "core" } ,
"Custom css auto udpate" : { "id" : "bda-css-1" , "info" : "" , "implemented" : true , "hidden" : true , "cat" : "core" } ,
"Show Emotes" : { "id" : "bda-es-7" , "info" : "Show any emotes" , "implemented" : true , "hidden" : false , "cat" : "emote" } ,
"FrankerFaceZ Emotes" : { "id" : "bda-es-1" , "info" : "Show FrankerFaceZ Emotes" , "implemented" : true , "hidden" : false , "cat" : "emote" } ,
"BetterTTV Emotes" : { "id" : "bda-es-2" , "info" : "Show BetterTTV Emotes" , "implemented" : true , "hidden" : false , "cat" : "emote" } ,
"Emote Menu" : { "id" : "bda-es-0" , "info" : "Show Twitch/Favourite emotes in emote menu" , "implemented" : true , "hidden" : false , "cat" : "emote" } ,
"Emoji Menu" : { "id" : "bda-es-9" , "info" : "Show Discord emoji menu" , "implemented" : true , "hidden" : false , "cat" : "emote" } ,
"Emote Autocomplete" : { "id" : "bda-es-3" , "info" : "Autocomplete emote commands" , "implemented" : false , "hidden" : false , "cat" : "emote" } ,
"Emote Auto Capitalization" : { "id" : "bda-es-4" , "info" : "Autocapitalize emote commands" , "implemented" : true , "hidden" : false , "cat" : "emote" } ,
"Show Names" : { "id" : "bda-es-6" , "info" : "Show emote names on hover" , "implemented" : true , "hidden" : false , "cat" : "emote" } ,
"Show emote modifiers" : { "id" : "bda-es-8" , "info" : "Enable emote mods" , "implemented" : true , "hidden" : false , "cat" : "emote" } ,
} ;
2015-12-16 12:21:46 +01:00
var links = {
"Jiiks.net" : { "text" : "Jiiks.net" , "href" : "http://jiiks.net" , "target" : "_blank" } ,
"twitter" : { "text" : "Twitter" , "href" : "http://twitter.com/jiiksi" , "target" : "_blank" } ,
"github" : { "text" : "Github" , "href" : "http://github.com/jiiks" , "target" : "_blank" }
2015-08-29 08:55:06 +02:00
} ;
var defaultCookie = {
2016-04-10 14:43:27 +02:00
"version" : jsVersion ,
2015-12-16 12:21:46 +01:00
"bda-gs-0" : false ,
"bda-gs-1" : true ,
"bda-gs-2" : false ,
"bda-gs-3" : false ,
"bda-gs-4" : false ,
2016-04-10 14:43:27 +02:00
"bda-gs-5" : true ,
2015-12-16 12:21:46 +01:00
"bda-es-0" : true ,
2016-04-10 14:43:27 +02:00
"bda-es-1" : true ,
"bda-es-2" : true ,
2015-12-16 12:21:46 +01:00
"bda-es-3" : false ,
"bda-es-4" : false ,
"bda-es-5" : true ,
"bda-es-6" : true ,
"bda-es-7" : true ,
2016-04-10 14:43:27 +02:00
"bda-es-8" : true ,
"bda-jd" : true ,
"bda-es-8" : true ,
"bda-dc-0" : false ,
"bda-css-0" : false ,
"bda-css-1" : false ,
"bda-es-9" : true
2015-12-16 12:21:46 +01:00
} ;
var bdchangelog = {
"changes" : {
2016-04-10 14:43:27 +02:00
"darkmode" : {
"title" : "v1.63 : Dark Mode" ,
"text" : "Dark mode makes certain elements dark by default(currently only applies to emote menu)" ,
2015-12-16 12:21:46 +01:00
"img" : ""
} ,
2016-04-10 14:43:27 +02:00
"emotemenu" : {
"title" : "v1.62 : Brand new emote menu that fits in Discord emoji menu!" ,
"text" : "The emote menu has been replaced by a new one that injects itself in the Discord emoji menu!" ,
2015-12-16 12:21:46 +01:00
"img" : ""
} ,
2016-04-10 14:43:27 +02:00
"cccss" : {
"title" : "v1.61 : New custom CSS editor" ,
"text" : "The custom CSS editor now has options and can be detached!" ,
2015-12-16 12:21:46 +01:00
"img" : ""
} ,
2016-04-10 14:43:27 +02:00
"vdc" : {
"title" : "v1.61 : Voice Disconnect" ,
"text" : "Disconnect from voice server when closing Discord!" ,
2015-12-16 12:21:46 +01:00
"img" : ""
} ,
2016-04-10 14:43:27 +02:00
"pslist" : {
"title" : "v1.60 : New public server list!" ,
"text" : 'New and shiny public server list powered by <a href="https://www.discordservers.com/" target="_blank">DiscordServers.com</a>!' ,
2015-12-16 12:21:46 +01:00
"img" : ""
} ,
2016-04-10 14:43:27 +02:00
"api" : {
"title" : "v1.59 : New plugin api callback" ,
"text" : "Use the `observer(e)` callback instead of creating your own MutationObserver" ,
2015-12-16 12:21:46 +01:00
"img" : ""
2016-04-10 14:43:27 +02:00
} ,
"emotemods" : {
"title" : "v1.59 : New emote mods!" ,
"text" : "The following emote mods have been added: :shake2, :shake3, :flap" ,
2015-12-16 12:21:46 +01:00
"img" : ""
} ,
2016-04-10 14:43:27 +02:00
"minmode" : {
"title" : "v1.59: Minimal mode" ,
"text" : "Minimal mode embed fixed size has been removed" ,
"img" : ""
}
} ,
"fixes" : {
"modal" : {
"title" : "v1.62 : Fixed modals" ,
"text" : "Fixed broken modal introduced by 0.0.287" ,
"imt" : ""
2015-12-16 12:21:46 +01:00
} ,
2016-04-10 14:43:27 +02:00
"emotes" : {
"title" : "v1.59 : Native sub emote mods" ,
"text" : "Emote mods now work with native sub emotes!" ,
"img" : ""
2015-12-16 12:21:46 +01:00
} ,
2016-04-10 14:43:27 +02:00
"emotes2" : {
"title" : "v1.59 : Emote mods and custom emotes" ,
"text" : "Emote mods will no longer interfere with custom emotes using :" ,
2015-12-16 12:21:46 +01:00
"img" : ""
}
}
2015-08-29 08:55:06 +02:00
} ;
var settingsCookie = { } ;
2015-08-27 15:42:19 +02:00
2015-10-26 06:27:55 +01:00
function Core ( ) { }
2015-08-27 15:42:19 +02:00
2016-04-10 14:43:27 +02:00
Core . prototype . init = function ( ) {
2015-12-16 12:21:46 +01:00
var self = this ;
2016-04-10 14:43:27 +02:00
if ( version < supportedVersion ) {
this . alert ( "Not Supported" , "BetterDiscord v" + version + "(your version)" + " is not supported by the latest js(" + jsVersion + ").<br><br> Please download the latest version from <a href='https://betterdiscord.net' target='_blank'>BetterDiscord.net</a>" ) ;
2015-10-26 06:27:55 +01:00
return ;
}
2015-08-29 08:55:06 +02:00
2015-08-27 15:42:19 +02:00
utils = new Utils ( ) ;
2016-04-10 14:43:27 +02:00
var sock = new BdWSocket ( ) ;
sock . start ( ) ;
2015-12-16 12:21:46 +01:00
utils . getHash ( ) ;
2015-08-27 15:42:19 +02:00
emoteModule = new EmoteModule ( ) ;
quickEmoteMenu = new QuickEmoteMenu ( ) ;
2015-10-26 06:27:55 +01:00
voiceMode = new VoiceMode ( ) ;
2015-08-27 15:42:19 +02:00
emoteModule . init ( ) ;
2015-08-29 08:55:06 +02:00
this . initSettings ( ) ;
this . initObserver ( ) ;
2015-10-26 06:27:55 +01:00
//Incase were too fast
function gwDefer ( ) {
console . log ( new Date ( ) . getTime ( ) + " Defer" ) ;
2016-04-10 14:43:27 +02:00
if ( $ ( ".guilds-wrapper .guilds" ) . children ( ) . length > 0 ) {
2015-10-26 06:27:55 +01:00
console . log ( new Date ( ) . getTime ( ) + " Defer Loaded" ) ;
2016-01-12 12:43:35 +01:00
var guilds = $ ( ".guilds>li:first-child" ) ;
2015-10-26 06:27:55 +01:00
2015-12-16 12:21:46 +01:00
var showChannelsButton = $ ( "<button/>" , {
class : "btn" ,
id : "bd-show-channels" ,
text : "R" ,
css : {
"cursor" : "pointer"
} ,
2016-04-10 14:43:27 +02:00
click : function ( ) {
2015-12-16 12:21:46 +01:00
settingsCookie [ "bda-gs-3" ] = false ;
$ ( "body" ) . removeClass ( "bd-minimal-chan" ) ;
self . saveSettings ( ) ;
}
} ) ;
$ ( ".guilds-wrapper" ) . prepend ( showChannelsButton ) ;
2015-10-26 06:27:55 +01:00
opublicServers = new PublicServers ( ) ;
2016-04-10 14:43:27 +02:00
customCssEditor = new CustomCssEditor ( ) ;
2015-12-16 12:21:46 +01:00
pluginModule = new PluginModule ( ) ;
pluginModule . loadPlugins ( ) ;
2016-04-10 14:43:27 +02:00
if ( typeof ( themesupport2 ) !== "undefined" ) {
2015-12-16 12:21:46 +01:00
themeModule = new ThemeModule ( ) ;
themeModule . loadThemes ( ) ;
}
settingsPanel = new SettingsPanel ( ) ;
settingsPanel . init ( ) ;
2015-10-26 06:27:55 +01:00
2015-08-31 15:20:33 +02:00
quickEmoteMenu . init ( false ) ;
2016-04-10 14:43:27 +02:00
$ ( "#tc-settings-button" ) . on ( "click" , function ( ) {
settingsPanel . show ( ) ;
} ) ;
window . addEventListener ( "beforeunload" , function ( ) {
if ( settingsCookie [ "bda-dc-0" ] ) {
$ ( '.btn.btn-disconnect' ) . click ( ) ;
}
} ) ;
2015-12-16 12:21:46 +01:00
opublicServers . init ( ) ;
emoteModule . autoCapitalize ( ) ;
/*Display new features in BetterDiscord*/
2016-04-10 14:43:27 +02:00
if ( settingsCookie [ "version" ] < jsVersion ) {
2015-12-16 12:21:46 +01:00
var cl = self . constructChangelog ( ) ;
$ ( "body" ) . append ( cl ) ;
settingsCookie [ "version" ] = jsVersion ;
self . saveSettings ( ) ;
}
2016-04-10 14:43:27 +02:00
2015-12-16 12:21:46 +01:00
$ ( "head" ) . append ( "<style>.CodeMirror{ min-width:100%; }</style>" ) ;
2016-04-10 14:43:27 +02:00
$ ( "head" ) . append ( '<style id="bdemotemenustyle"></style>' ) ;
2015-08-31 15:20:33 +02:00
} else {
2015-12-16 12:21:46 +01:00
setTimeout ( gwDefer , 100 ) ;
2015-08-31 15:20:33 +02:00
}
}
2015-10-26 06:27:55 +01:00
2016-04-10 14:43:27 +02:00
$ ( document ) . ready ( function ( ) {
2015-12-16 12:21:46 +01:00
setTimeout ( gwDefer , 1000 ) ;
2015-10-26 06:27:55 +01:00
} ) ;
} ;
2015-08-27 15:42:19 +02:00
2016-04-10 14:43:27 +02:00
Core . prototype . initSettings = function ( ) {
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:50:54 +02:00
this . loadSettings ( ) ;
2015-08-29 08:55:06 +02:00
2016-04-10 14:43:27 +02:00
for ( var setting in defaultCookie ) {
if ( settingsCookie [ setting ] == undefined ) {
2015-10-26 06:27:55 +01:00
settingsCookie [ setting ] = defaultCookie [ setting ] ;
2015-08-29 10:48:20 +02:00
this . saveSettings ( ) ;
2015-08-29 08:55:06 +02:00
}
2015-08-27 15:42:19 +02:00
}
}
2015-10-26 06:27:55 +01:00
} ;
2015-08-29 08:55:06 +02:00
2016-04-10 14:43:27 +02:00
Core . prototype . saveSettings = function ( ) {
$ . cookie ( "better-discord" , JSON . stringify ( settingsCookie ) , {
expires : 365 ,
path : '/'
} ) ;
2015-10-26 06:27:55 +01:00
} ;
2015-08-29 10:48:20 +02:00
2016-04-10 14:43:27 +02:00
Core . prototype . loadSettings = function ( ) {
2015-08-29 10:48:20 +02:00
settingsCookie = JSON . parse ( $ . cookie ( "better-discord" ) ) ;
2015-10-26 06:27:55 +01:00
} ;
2015-08-29 10:48:20 +02:00
2016-04-10 14:43:27 +02:00
var botlist = [ "119598467310944259" ] ; //Temp
Core . prototype . initObserver = function ( ) {
mainObserver = new MutationObserver ( function ( mutations ) {
mutations . forEach ( function ( mutation ) {
if ( $ ( mutation . target ) . find ( ".emoji-picker" ) . length ) {
var fc = mutation . target . firstChild ;
if ( fc . classList . contains ( "popout" ) ) {
quickEmoteMenu . obsCallback ( $ ( fc ) ) ;
}
}
if ( typeof pluginModule !== "undefined" ) pluginModule . rawObserver ( mutation ) ;
if ( mutation . target . getAttribute ( 'class' ) != null ) {
//console.log(mutation.target)
if ( mutation . target . classList . contains ( 'title-wrap' ) || mutation . target . classList . contains ( 'chat' ) ) {
// quickEmoteMenu.obsCallback();
2015-12-16 12:21:46 +01:00
voiceMode . obsCallback ( ) ;
2016-04-10 14:43:27 +02:00
if ( typeof pluginModule !== "undefined" ) pluginModule . channelSwitch ( ) ;
}
if ( mutation . target . getAttribute ( 'class' ) . indexOf ( 'scroller messages' ) != - 1 ) {
if ( typeof pluginModule !== "undefined" ) pluginModule . newMessage ( ) ;
2015-08-29 21:02:20 +02:00
}
2015-08-29 08:55:06 +02:00
}
2015-08-29 10:50:54 +02:00
emoteModule . obsCallback ( mutation ) ;
2015-08-29 08:55:06 +02:00
} ) ;
} ) ;
2015-10-26 06:27:55 +01:00
//noinspection JSCheckFunctionSignatures
2016-04-10 14:43:27 +02:00
mainObserver . observe ( document , {
childList : true ,
subtree : true
} ) ;
2015-12-16 12:21:46 +01:00
} ;
2016-04-10 14:43:27 +02:00
Core . prototype . constructChangelog = function ( ) {
2015-12-16 12:21:46 +01:00
var changeLog = '' +
'<div id="bd-wn-modal" class="modal" style="opacity:1;">' +
' <div class="modal-inner">' +
2016-04-10 14:43:27 +02:00
' <div id="bdcl" class="markdown-modal change-log"> ' +
' <div class="markdown-modal-header">' +
' <strong>What\'s new in BetterDiscord JS' + jsVersion + '</strong>' +
' <button class="markdown-modal-close" onclick=\'$("#bd-wn-modal").remove();\'></button>' +
2015-12-16 12:21:46 +01:00
' </div><!--header-->' +
' <div class="scroller-wrap">' +
' <div class="scroller">' ;
2016-04-10 14:43:27 +02:00
if ( bdchangelog . changes != null ) {
2015-12-16 12:21:46 +01:00
changeLog += '' +
'<h1 class="changelog-added">' +
' <span>New Stuff</span>' +
'</h1>' +
'<ul>' ;
2016-04-10 14:43:27 +02:00
for ( var change in bdchangelog . changes ) {
2015-12-16 12:21:46 +01:00
change = bdchangelog . changes [ change ] ;
changeLog += '' +
'<li>' +
2016-04-10 14:43:27 +02:00
' <strong>' + change . title + '</strong>' +
' <div>' + change . text + '</div>' +
2015-12-16 12:21:46 +01:00
'</li>' ;
}
changeLog += '</ul>' ;
}
2016-04-10 14:43:27 +02:00
if ( bdchangelog . fixes != null ) {
2015-12-16 12:21:46 +01:00
changeLog += '' +
'<h1 class="changelog-fixed">' +
' <span>Fixed</span>' +
'</h1>' +
'<ul>' ;
2016-04-10 14:43:27 +02:00
for ( var fix in bdchangelog . fixes ) {
2015-12-16 12:21:46 +01:00
fix = bdchangelog . fixes [ fix ] ;
changeLog += '' +
'<li>' +
2016-04-10 14:43:27 +02:00
' <strong>' + fix . title + '</strong>' +
' <div>' + fix . text + '</div>' +
2015-12-16 12:21:46 +01:00
'</li>' ;
}
changeLog += '</ul>' ;
}
2016-04-10 14:43:27 +02:00
if ( bdchangelog . upcoming != null ) {
2015-12-16 12:21:46 +01:00
changeLog += '' +
'<h1 class="changelog-in-progress">' +
' <span>Coming Soon</span>' +
'</h1>' +
'<ul>' ;
2016-04-10 14:43:27 +02:00
for ( var upc in bdchangelog . upcoming ) {
2015-12-16 12:21:46 +01:00
upc = bdchangelog . upcoming [ upc ] ;
changeLog += '' +
'<li>' +
2016-04-10 14:43:27 +02:00
' <strong>' + upc . title + '</strong>' +
' <div>' + upc . text + '</div>' +
2015-12-16 12:21:46 +01:00
'</li>' ;
}
changeLog += '</ul>' ;
}
changeLog += '' +
' </div><!--scoller-->' +
' </div><!--scroller-wrap-->' +
' <div class="footer">' +
' </div><!--footer-->' +
' </div><!--change-log-->' +
' </div><!--modal-inner-->' +
'</div><!--modal-->' ;
return changeLog ;
} ;
2016-04-10 14:43:27 +02:00
Core . prototype . alert = function ( title , text ) {
$ ( "body" ) . append ( '' +
'<div class="bd-alert">' +
' <div class="bd-alert-header">' +
' <span>' + title + '</span>' +
' <div class="bd-alert-closebtn" onclick="$(this).parent().parent().remove();">× </div>' +
' </div>' +
' <div class="bd-alert-body">' +
' <div class="scroller-wrap dark fade">' +
' <div class="scroller">' + text + '</div>' +
' </div>' +
' </div>' +
'</div>' ) ;
} ;