2019-01-31 17:06:48 +01:00
//META{"name":"OldTitleBar","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/OldTitleBar","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/OldTitleBar/OldTitleBar.plugin.js"}*//
2018-10-11 10:21:26 +02:00
class OldTitleBar {
2019-01-17 13:46:11 +01:00
getName ( ) { return "OldTitleBar" ; }
2019-01-17 23:48:29 +01:00
getVersion ( ) { return "1.5.3" ; }
2019-01-17 13:46:11 +01:00
getAuthor ( ) { return "DevilBro" ; }
getDescription ( ) { return "Reverts the title bar back to its former self." ; }
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
initConstructor ( ) {
2019-01-05 11:30:37 +01:00
this . patchModules = {
"HeaderBar" : [ "componentDidMount" , "componentDidUpdate" ] ,
2019-01-05 20:24:38 +01:00
"StandardSidebarView" : [ "componentDidMount" , "componentWillUnmount" ] ,
"AuthWrapper" : [ "componentDidMount" , "componentWillUnmount" ]
2019-01-05 11:30:37 +01:00
} ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . patched = false ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . css = `
2018-11-02 21:01:04 +01:00
. hidden - by - OTB $ { BDFDB . dotCN . titlebar } ,
. hidden - by - OTB $ { BDFDB . dotCN . titlebar } + $ { BDFDB . dotCNS . app + BDFDB . dotCN . splashbackground } : before {
display : none ! important ;
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2019-01-17 13:46:11 +01:00
body : not ( . settingsTitlebarOTB - added ) $ { BDFDB . dotCN . channelheaderheaderbardrag } {
2018-10-11 10:21:26 +02:00
- webkit - app - region : drag ! important ;
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
$ { BDFDB . dotCN . channelheaderheaderbardrag } * ,
$ { BDFDB . dotCN . contextmenu } * {
- webkit - app - region : no - drag ! important ;
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
. settingsTitlebarOTB {
position : relative ;
z - index : 1000 ;
text - align : right ;
padding : 10 px ;
- webkit - app - region : drag ;
} ` ;
2019-01-26 22:45:19 +01:00
2019-01-05 11:30:37 +01:00
this . dividerMarkup = ` <div class="buttonOTB dividerOTB ${ BDFDB . disCN . channelheaderdivider } "></div> ` ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . reloadButtonMarkup =
2019-01-05 11:30:37 +01:00
` <span class=" ${ BDFDB . disCN . channelheadericonmargin } buttonOTB reloadButtonOTB">
2018-10-11 10:21:26 +02:00
< svg class = "${BDFDB.disCNS.channelheadericoninactive + BDFDB.disCN.channelheadericon}" xmlns = "http://www.w3.org/2000/svg" >
< g fill = "none" class = "${BDFDB.disCN.channelheadericonforeground}" fill - rule = "evenodd" >
< path fill = "currentColor" transform = "translate(4,4)" d = "M17.061,7.467V0l-2.507,2.507C13.013,0.96,10.885,0,8.528,0C3.813,0,0.005,3.819,0.005,8.533s3.808,8.533,8.523,8.533c3.973,0,7.301-2.72,8.245-6.4h-2.219c-0.88,2.485-3.237,4.267-6.027,4.267c-3.536,0-6.4-2.864-6.4-6.4s2.864-6.4,6.4-6.4c1.765,0,3.349,0.736,4.507,1.893l-3.44,3.44H17.061z" / >
< / g >
< / s v g >
< / s p a n > ` ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . minButtonMarkup =
2019-01-05 11:30:37 +01:00
` <span class=" ${ BDFDB . disCN . channelheadericonmargin } buttonOTB minButtonOTB">
2018-10-11 10:21:26 +02:00
< svg class = "${BDFDB.disCNS.channelheadericoninactive + BDFDB.disCN.channelheadericon}" xmlns = "http://www.w3.org/2000/svg" width = "26" height = "26" >
< g fill = "none" class = "${BDFDB.disCN.channelheadericonforeground}" fill - rule = "evenodd" >
< path stroke - width = "2" stroke = "currentColor" d = "M6 18 l13 0" / >
< / g >
< / s v g >
< / s p a n > ` ;
2019-01-26 22:45:19 +01:00
2019-01-17 13:46:11 +01:00
this . maxButtonMarkup =
2019-01-05 11:30:37 +01:00
` <span class=" ${ BDFDB . disCN . channelheadericonmargin } buttonOTB maxButtonOTB">
2018-10-11 10:21:26 +02:00
< svg class = "${BDFDB.disCNS.channelheadericoninactive + BDFDB.disCN.channelheadericon}" xmlns = "http://www.w3.org/2000/svg" width = "26" height = "26" >
2019-01-17 13:46:11 +01:00
< g fill = "none" class = "${BDFDB.disCN.channelheadericonforeground}" fill - rule = "evenodd" > < / g >
2018-10-11 10:21:26 +02:00
< / s v g >
< / s p a n > ` ;
2019-01-17 13:46:11 +01:00
this . maxButtonInnerMin = ` <path stroke-width="2" stroke="currentColor" d="M6 6 l13 0 l0 13 l-13 0 l0 -13"/> ` ;
this . maxButtonInnerMax = ` <path stroke-width="2" stroke="currentColor" d="M6 9 l10 0 l0 10 l-10 0 l0 -10 m3 -3 l10 0 l0 10"/> ` ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . closeButtonMarkup =
2019-01-05 11:30:37 +01:00
` <span class=" ${ BDFDB . disCN . channelheadericonmargin } buttonOTB closeButtonOTB">
2018-10-11 10:21:26 +02:00
< svg class = "${BDFDB.disCNS.channelheadericoninactive + BDFDB.disCN.channelheadericon}" xmlns = "http://www.w3.org/2000/svg" width = "26" height = "26" >
< g fill = "none" class = "${BDFDB.disCN.channelheadericonforeground}" fill - rule = "evenodd" >
< path stroke - width = "2" stroke = "currentColor" d = "M6 6 l13 13 m0 -13 l-13 13" / >
< / g >
< / s v g >
< / s p a n > ` ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . defaults = {
settings : {
2018-12-14 18:58:35 +01:00
displayNative : { value : ! ! document . querySelector ( ".platform-linux" ) , description : "Displays the native Title Bar." } ,
addOldBar : { value : true , description : "Displays the Title Bar in the old fashion." } ,
2018-11-08 09:49:46 +01:00
addToSettings : { value : true , description : "Adds a Title Bar to Settings Windows." } ,
reloadButton : { value : false , description : "Adds a Reload Button to the Title Bar." }
2018-10-11 10:21:26 +02:00
}
} ;
}
getSettingsPanel ( ) {
2019-01-22 11:28:32 +01:00
if ( ! global . BDFDB || typeof BDFDB != "object" || ! BDFDB . loaded || ! this . started ) return ;
2018-10-11 10:21:26 +02:00
var settings = BDFDB . getAllData ( this , "settings" ) ;
2019-01-24 13:37:08 +01:00
var settingshtml = ` <div class=" ${ this . name } -settings DevilBro-settings"><div class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . title + BDFDB . disCNS . size18 + BDFDB . disCNS . height24 + BDFDB . disCNS . weightnormal + BDFDB . disCN . marginbottom8 } "> ${ this . name } </div><div class="DevilBro-settings-inner"> ` ;
2018-10-11 10:21:26 +02:00
for ( let key in settings ) {
2019-01-17 23:48:29 +01:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . flex2 + BDFDB . disCNS . horizontal + BDFDB . disCNS . horizontal2 + BDFDB . disCNS . directionrow + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } " style="flex: 1 1 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . title + BDFDB . disCNS . marginreset + BDFDB . disCNS . weightmedium + BDFDB . disCNS . size16 + BDFDB . disCNS . height24 + BDFDB . disCN . flexchild } " style="flex: 1 1 auto;"> ${ this . defaults . settings [ key ] . description } </h3><div class=" ${ BDFDB . disCNS . flexchild + BDFDB . disCNS . switchenabled + BDFDB . disCNS . switch + BDFDB . disCNS . switchvalue + BDFDB . disCNS . switchsizedefault + BDFDB . disCNS . switchsize + BDFDB . disCN . switchthemedefault } " style="flex: 0 0 auto;"><input type="checkbox" value="settings ${ key } " class=" ${ BDFDB . disCNS . switchinnerenabled + BDFDB . disCN . switchinner } settings-switch ${ key == "displayNative" ? " nativetitlebar-switch" : "" } " ${ settings [ key ] ? " checked" : "" } ></div></div> ` ;
2018-10-11 10:21:26 +02:00
}
settingshtml += ` </div></div> ` ;
2019-01-26 22:45:19 +01:00
2019-01-17 13:46:11 +01:00
let settingspanel = BDFDB . htmlToElement ( settingshtml ) ;
2018-10-11 10:21:26 +02:00
2019-01-17 13:46:11 +01:00
BDFDB . initElements ( settingspanel , this ) ;
2018-10-11 10:21:26 +02:00
2019-01-17 23:48:29 +01:00
BDFDB . addEventListener ( this , settingspanel , "click" , ".nativetitlebar-switch" , e => {
if ( this . patchMainScreen ( e . currentTarget . checked ) ) {
this . patched = ! this . patched ;
let notifybar = document . querySelector ( "#OldTitleBarNotifyBar" ) ;
if ( notifybar ) notifybar . querySelector ( BDFDB . dotCN . noticedismiss ) . click ( ) ;
if ( this . patched ) {
notifybar = BDFDB . createNotificationsBar ( "Changed nativebar settings, relaunch to see changes:" , { type : "danger" , btn : "Relaunch" , id : "OldTitleBarNotifyBar" } ) ;
notifybar . querySelector ( BDFDB . dotCN . noticebutton ) . addEventListener ( "click" , ( ) => {
let app = require ( "electron" ) . remote . app ;
app . relaunch ( ) ;
app . quit ( ) ;
} ) ;
}
}
} ) ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
return settingspanel ;
}
//legacy
load ( ) { }
start ( ) {
2019-02-04 09:13:15 +01:00
if ( ! global . BDFDB ) global . BDFDB = { myPlugins : { } } ;
if ( global . BDFDB && global . BDFDB . myPlugins && typeof global . BDFDB . myPlugins == "object" ) global . BDFDB . myPlugins [ this . getName ( ) ] = this ;
2019-01-17 23:48:29 +01:00
var libraryScript = document . querySelector ( 'head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]' ) ;
if ( ! libraryScript || performance . now ( ) - libraryScript . getAttribute ( "date" ) > 600000 ) {
2018-10-11 10:21:26 +02:00
if ( libraryScript ) libraryScript . remove ( ) ;
libraryScript = document . createElement ( "script" ) ;
libraryScript . setAttribute ( "type" , "text/javascript" ) ;
libraryScript . setAttribute ( "src" , "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js" ) ;
2019-01-17 23:48:29 +01:00
libraryScript . setAttribute ( "date" , performance . now ( ) ) ;
2019-01-30 21:23:49 +01:00
libraryScript . addEventListener ( "load" , ( ) => { if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) this . initialize ( ) ; } ) ;
2018-10-11 10:21:26 +02:00
document . head . appendChild ( libraryScript ) ;
}
2019-01-17 23:48:29 +01:00
else if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) this . initialize ( ) ;
2018-10-11 10:21:26 +02:00
this . startTimeout = setTimeout ( ( ) => { this . initialize ( ) ; } , 30000 ) ;
}
initialize ( ) {
2019-01-17 13:46:11 +01:00
if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) {
2019-01-22 11:05:54 +01:00
if ( this . started ) return ;
2018-10-11 10:21:26 +02:00
BDFDB . loadMessage ( this ) ;
2019-01-26 22:45:19 +01:00
2019-01-17 13:46:11 +01:00
BDFDB . addEventListener ( this , window , "resize" , e => { this . changeMaximizeButtons ( ) ; } ) ;
2019-01-26 22:45:19 +01:00
2019-01-17 13:46:11 +01:00
this . window = require ( "electron" ) . remote . getCurrentWindow ( ) ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . patchMainScreen ( BDFDB . getData ( "displayNative" , this , "settings" ) ) ;
2019-01-26 22:45:19 +01:00
2019-01-17 13:46:11 +01:00
BDFDB . addClass ( [ document . body , document . querySelector ( BDFDB . dotCN . titlebar ) ] , "hidden-by-OTB" ) ;
2019-01-26 22:45:19 +01:00
2019-01-05 11:30:37 +01:00
BDFDB . WebModules . forceAllUpdates ( this ) ;
2018-10-11 10:21:26 +02:00
}
else {
2019-02-12 21:56:34 +01:00
console . error ( ` %c[ ${ this . getName ( ) } ]%c ` , 'color: #3a71c1; font-weight: 700;' , '' , 'Fatal Error: Could not load BD functions!' ) ;
2018-10-11 10:21:26 +02:00
}
}
stop ( ) {
2019-01-17 13:46:11 +01:00
if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) {
BDFDB . removeEles ( ".headerbarOTB" , ".settingsTitlebarOTB" ) ;
2019-01-26 22:45:19 +01:00
2019-01-17 13:46:11 +01:00
BDFDB . removeClasses ( "hidden-by-OTB" , "settingsTitlebarOTB-added" ) ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
BDFDB . unloadMessage ( this ) ;
}
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
// begin of own functions
2019-01-26 22:45:19 +01:00
2019-01-05 11:30:37 +01:00
processHeaderBar ( instance , wrapper ) {
this . addTitleBar ( ) ;
}
2019-01-26 22:45:19 +01:00
2019-01-05 11:30:37 +01:00
processStandardSidebarView ( instance , wrapper , methodnames ) {
2019-01-05 20:24:38 +01:00
this . processAuthWrapper ( instance , wrapper , methodnames ) ;
}
2019-01-26 22:45:19 +01:00
2019-01-05 20:24:38 +01:00
processAuthWrapper ( instance , wrapper , methodnames ) {
2019-01-05 11:30:37 +01:00
if ( methodnames . includes ( "componentDidMount" ) ) {
this . addSettingsTitleBar ( wrapper ) ;
}
else if ( methodnames . includes ( "componentWillUnmount" ) ) {
2019-01-05 20:24:38 +01:00
BDFDB . removeEles ( ".settingsTitlebarOTB" ) ;
2019-01-17 13:46:11 +01:00
BDFDB . removeClass ( document . body , "settingsTitlebarOTB-added" ) ;
2019-01-05 11:30:37 +01:00
this . addTitleBar ( ) ;
}
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
addTitleBar ( ) {
2019-01-05 11:30:37 +01:00
BDFDB . removeEles ( ".headerbarOTB" ) ;
2018-10-11 10:21:26 +02:00
var settings = BDFDB . getAllData ( this , "settings" ) ;
2019-01-05 11:30:37 +01:00
if ( BDFDB . getData ( "addOldBar" , this , "settings" ) ) {
2019-01-17 13:46:11 +01:00
var headerbar = BDFDB . htmlToElement ( ` <span class="headerbarOTB ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . horizontal2 + BDFDB . disCNS . directionrow + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCN . nowrap } "></span> ` ) ;
2019-01-05 11:30:37 +01:00
this . createButtons ( headerbar ) ;
2019-01-17 13:46:11 +01:00
let headerbaricon = document . querySelector ( BDFDB . dotCNS . channelheaderheaderbardrag + BDFDB . dotCN . flex + " > " + BDFDB . dotCN . channelheadericonmargin ) ;
if ( headerbaricon ) headerbaricon . parentElement . appendChild ( headerbar ) ;
this . changeMaximizeButtons ( ) ;
2019-01-05 11:30:37 +01:00
}
}
2019-01-26 22:45:19 +01:00
2019-01-05 11:30:37 +01:00
addSettingsTitleBar ( settingspane ) {
BDFDB . removeEles ( ".settingsTitlebarOTB" ) ;
if ( BDFDB . getData ( "addToSettings" , this , "settings" ) ) {
2019-01-17 13:46:11 +01:00
BDFDB . addClass ( document . body , "settingsTitlebarOTB-added" ) ;
var settingsbar = BDFDB . htmlToElement ( ` <div class="settingsTitlebarOTB"></div> ` ) ;
2019-01-05 11:30:37 +01:00
this . createButtons ( settingsbar ) ;
settingspane . parentElement . appendChild ( settingsbar ) ;
2019-01-17 13:46:11 +01:00
this . changeMaximizeButtons ( ) ;
2019-01-05 11:30:37 +01:00
}
}
2019-01-26 22:45:19 +01:00
2019-01-05 11:30:37 +01:00
createButtons ( bar ) {
2019-01-17 13:46:11 +01:00
var settings = BDFDB . containsClass ( bar , "settingsTitlebarOTB" ) ;
2019-01-05 11:30:37 +01:00
if ( BDFDB . getData ( "reloadButton" , this , "settings" ) ) {
2019-01-17 13:46:11 +01:00
if ( ! settings ) bar . appendChild ( BDFDB . htmlToElement ( this . dividerMarkup ) ) ;
var reloadbutton = BDFDB . htmlToElement ( this . reloadButtonMarkup ) ;
bar . appendChild ( reloadbutton ) ;
var reloadbuttonicon = reloadbutton . querySelector ( BDFDB . dotCN . channelheadericon ) ;
reloadbuttonicon . addEventListener ( "click" , ( ) => { this . window . reload ( ) ; } ) ;
reloadbuttonicon . addEventListener ( "mouseenter" , e => {
BDFDB . createTooltip ( "Reload" , reloadbuttonicon , { type : "bottom" , selector : "reload-button-tooltip" } ) ;
2018-10-11 10:21:26 +02:00
} ) ;
2019-01-17 13:46:11 +01:00
}
if ( ! settings ) bar . appendChild ( BDFDB . htmlToElement ( this . dividerMarkup ) ) ;
var minbutton = BDFDB . htmlToElement ( this . minButtonMarkup ) ;
bar . appendChild ( minbutton ) ;
minbutton . querySelector ( BDFDB . dotCN . channelheadericon ) . addEventListener ( "click" , ( ) => { this . window . minimize ( ) ; } ) ;
var maxbutton = BDFDB . htmlToElement ( this . maxButtonMarkup ) ;
bar . appendChild ( maxbutton ) ;
maxbutton . querySelector ( BDFDB . dotCN . channelheadericon ) . addEventListener ( "click" , ( ) => {
if ( this . window . isMaximized ( ) ) this . window . unmaximize ( ) ;
else this . window . maximize ( ) ;
this . changeMaximizeButtons ( ) ;
} ) ;
var closebutton = BDFDB . htmlToElement ( this . closeButtonMarkup ) ;
bar . appendChild ( closebutton ) ;
closebutton . querySelector ( BDFDB . dotCN . channelheadericon ) . addEventListener ( "click" , ( ) => { this . window . close ( ) ; } ) ;
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2019-01-17 13:46:11 +01:00
changeMaximizeButtons ( ) {
var innerHTML = this . window . isMaximized ( ) ? this . maxButtonInnerMax : this . maxButtonInnerMin ;
document . querySelectorAll ( ".maxButtonOTB g" ) . forEach ( g => { g . innerHTML = innerHTML ; } ) ;
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
patchMainScreen ( enable ) {
2018-10-19 11:40:39 +02:00
if ( BdApi . getWindowPreference ( "frame" ) != enable ) {
BdApi . setWindowPreference ( "frame" , enable ) ;
2018-10-11 10:21:26 +02:00
return true ;
}
return false ;
}
}