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
* /
2015-08-29 08:55:06 +02:00
2016-04-11 09:41:17 +02:00
var BD ;
2015-08-29 08:55:06 +02:00
2016-04-11 09:41:17 +02:00
function Core ( ) {
BD = this ;
}
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-11 09:41:17 +02:00
this . version = version ;
2016-04-11 10:10:25 +02:00
if ( this . version < bdConfig . versionInfo . supportedVersion ) {
this . alert ( "Not Supported" , "BetterDiscord v" + this . version + "(your version)" + " is not supported by the latest js(" + bdConfig . versionInfo . version + ").<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
2016-04-11 10:10:25 +02:00
this . modules = {
emoteModule : new EmoteModule ( ) ,
publicServers : new PublicServers ( ) ,
emoteMenu : new QuickEmoteMenu ( ) ,
cssEditor : new customCssEditor ( ) ,
settingsPanel : new SettingsPanel ( ) ,
utils : new Utils ( ) ,
voiceMode : new VoiceMode ( ) ,
pluginModule : new pluginModule ( ) ,
themeModule : new ThemeModule ( )
}
2016-04-11 09:41:17 +02:00
2016-04-11 10:10:25 +02:00
this . modules . utils . getHash ( ) ;
2015-08-27 15:42:19 +02:00
2016-04-11 10:10:25 +02:00
this . modules . emoteModule . init ( ) ;
2015-08-27 15:42:19 +02:00
2015-08-29 08:55:06 +02:00
this . initSettings ( ) ;
this . initObserver ( ) ;
2016-04-11 10:10:25 +02:00
2015-10-26 06:27:55 +01:00
//Incase were too fast
function gwDefer ( ) {
2016-04-11 10:10:25 +02:00
self . modules . utils . log ( new Date ( ) . getTime ( ) + " Defer" ) ;
2016-04-10 14:43:27 +02:00
if ( $ ( ".guilds-wrapper .guilds" ) . children ( ) . length > 0 ) {
2016-04-11 10:10:25 +02:00
self . modules . utils . 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 ( ) {
2016-04-11 10:10:25 +02:00
self . settingsCookie [ "bda-gs-3" ] = false ;
2015-12-16 12:21:46 +01:00
$ ( "body" ) . removeClass ( "bd-minimal-chan" ) ;
self . saveSettings ( ) ;
}
} ) ;
$ ( ".guilds-wrapper" ) . prepend ( showChannelsButton ) ;
2015-10-26 06:27:55 +01:00
2016-04-11 10:10:25 +02:00
self . modules . pluginModule . loadPlugins ( ) ;
2016-04-10 14:43:27 +02:00
if ( typeof ( themesupport2 ) !== "undefined" ) {
2016-04-11 10:10:25 +02:00
self . modules . themeModule . loadThemes ( ) ;
2015-12-16 12:21:46 +01:00
}
2016-04-11 10:10:25 +02:00
self . modules . settingsPanel . init ( ) ;
2015-10-26 06:27:55 +01:00
2016-04-11 10:10:25 +02:00
self . modules . quickEmoteMenu . init ( false ) ;
2016-04-10 14:43:27 +02:00
window . addEventListener ( "beforeunload" , function ( ) {
2016-04-11 10:10:25 +02:00
if ( self . settingsCookie [ "bda-dc-0" ] ) {
2016-04-10 14:43:27 +02:00
$ ( '.btn.btn-disconnect' ) . click ( ) ;
}
} ) ;
2016-04-11 10:10:25 +02:00
self . modules . publicServers . init ( ) ;
self . modules . emoteModule . autoCapitalize ( ) ;
2015-12-16 12:21:46 +01:00
/*Display new features in BetterDiscord*/
2016-04-11 10:10:25 +02:00
if ( self . settingsCookie [ "version" ] < bdConfig . versionInfo . version ) {
2015-12-16 12:21:46 +01:00
var cl = self . constructChangelog ( ) ;
$ ( "body" ) . append ( cl ) ;
2016-04-11 10:10:25 +02:00
self . settingsCookie [ "version" ] = bdConfig . versionInfo . version ;
2015-12-16 12:21:46 +01:00
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 ) {
2016-04-11 10:10:25 +02:00
this . settingsCookie = bdConfig . defaults ;
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 ) {
2016-04-11 10:10:25 +02:00
if ( this . settingsCookie [ setting ] == undefined ) {
this . settingsCookie [ setting ] = bdConfig . defaults [ 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 ( ) {
2016-04-11 10:10:25 +02:00
$ . cookie ( "better-discord" , JSON . stringify ( this . settingsCookie ) , {
2016-04-10 14:43:27 +02:00
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 ( ) {
2016-04-11 10:10:25 +02:00
this . 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
Core . prototype . initObserver = function ( ) {
2016-04-11 10:10:25 +02:00
var self = this ;
this . observer = new MutationObserver ( function ( mutations ) {
2016-04-10 14:43:27 +02:00
mutations . forEach ( function ( mutation ) {
if ( $ ( mutation . target ) . find ( ".emoji-picker" ) . length ) {
var fc = mutation . target . firstChild ;
if ( fc . classList . contains ( "popout" ) ) {
2016-04-11 10:10:25 +02:00
self . modules . quickEmoteMenu . obsCallback ( $ ( fc ) ) ;
2016-04-10 14:43:27 +02:00
}
}
2016-04-11 10:10:25 +02:00
if ( typeof pluginModule !== "undefined" ) self . modules . pluginModule . rawObserver ( mutation ) ;
2016-04-10 14:43:27 +02:00
if ( mutation . target . getAttribute ( 'class' ) != null ) {
//console.log(mutation.target)
if ( mutation . target . classList . contains ( 'title-wrap' ) || mutation . target . classList . contains ( 'chat' ) ) {
// quickEmoteMenu.obsCallback();
2016-04-11 10:10:25 +02:00
self . modules . voiceMode . obsCallback ( ) ;
if ( typeof pluginModule !== "undefined" ) self . modules . pluginModule . channelSwitch ( ) ;
2016-04-10 14:43:27 +02:00
}
if ( mutation . target . getAttribute ( 'class' ) . indexOf ( 'scroller messages' ) != - 1 ) {
2016-04-11 10:10:25 +02:00
if ( typeof self . modules . pluginModule !== "undefined" ) self . modules . pluginModule . newMessage ( ) ;
2015-08-29 21:02:20 +02:00
}
2015-08-29 08:55:06 +02:00
}
2016-04-11 10:10:25 +02:00
self . modules . 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-11 10:10:25 +02:00
if ( bdConfig . changelog . changes != null ) {
2015-12-16 12:21:46 +01:00
changeLog += '' +
'<h1 class="changelog-added">' +
' <span>New Stuff</span>' +
'</h1>' +
'<ul>' ;
2016-04-11 10:10:25 +02:00
for ( var change in bdConfig . changelog . changes ) {
change = bdConfig . changelog . changes [ change ] ;
2015-12-16 12:21:46 +01:00
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-11 10:10:25 +02:00
if ( bdConfig . changelog . fixes != null ) {
2015-12-16 12:21:46 +01:00
changeLog += '' +
'<h1 class="changelog-fixed">' +
' <span>Fixed</span>' +
'</h1>' +
'<ul>' ;
2016-04-11 10:10:25 +02:00
for ( var fix in bdConfig . changelog . fixes ) {
fix = bdConfig . changelog . fixes [ fix ] ;
2015-12-16 12:21:46 +01:00
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-11 10:10:25 +02:00
if ( bdConfig . changelog . upcoming != null ) {
2015-12-16 12:21:46 +01:00
changeLog += '' +
'<h1 class="changelog-in-progress">' +
' <span>Coming Soon</span>' +
'</h1>' +
'<ul>' ;
2016-04-11 10:10:25 +02:00
for ( var upc in bdConfig . changelog . upcoming ) {
upc = bdConfig . changelog . upcoming [ upc ] ;
2015-12-16 12:21:46 +01:00
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>' ) ;
} ;