2019-01-31 17:06:48 +01:00
//META{"name":"FriendNotifications","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/FriendNotifications","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/FriendNotifications/FriendNotifications.plugin.js"}*//
2018-10-11 10:21:26 +02:00
class FriendNotifications {
2019-01-17 23:48:29 +01:00
getName ( ) { return "FriendNotifications" ; }
2019-05-01 21:02:25 +02:00
getVersion ( ) { return "1.1.9" ; }
2019-01-17 23:48:29 +01:00
getAuthor ( ) { return "DevilBro" ; }
getDescription ( ) { return "Notifies you when a friend either logs in or out. Click the Online Friend-Counter to display a timelog of the current session." ; }
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
initConstructor ( ) {
2019-05-01 21:02:25 +02:00
this . changelog = {
"fixed" : [ [ "Missing Friend Counter" , "Falls back to a check interval if the Online Counter isn't rendered. Timelog can now also be viewed in the settings" ] ]
} ;
2019-01-03 10:20:41 +01:00
this . patchModules = {
2019-02-22 20:12:38 +01:00
"FriendsOnline" : [ "componentDidMount" , "componentDidUpdate" ]
2019-01-03 10:20:41 +01:00
} ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . friendsOnlineList = { } ;
2019-01-26 22:45:19 +01:00
2019-05-01 21:02:25 +02:00
this . checkInterval = null ;
2018-10-11 10:21:26 +02:00
this . timeLog = [ ] ;
this . timeLogModalMarkup =
2019-04-18 09:28:20 +02:00
` <span class=" ${ this . name } -modal BDFDB-modal">
2018-10-11 10:21:26 +02:00
< div class = "${BDFDB.disCN.backdrop}" > < / d i v >
< div class = "${BDFDB.disCN.modal}" >
< div class = "${BDFDB.disCN.modalinner}" >
< div class = "${BDFDB.disCNS.modalsub + BDFDB.disCN.modalsizemedium}" >
< 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.modalheader}" style = "flex: 0 0 auto;" >
< div class = "${BDFDB.disCN.flexchild}" style = "flex: 1 1 auto;" >
< h4 class = "${BDFDB.disCNS.h4 + BDFDB.disCNS.headertitle + BDFDB.disCNS.size16 + BDFDB.disCNS.height20 + BDFDB.disCNS.weightsemibold + BDFDB.disCNS.defaultcolor + BDFDB.disCNS.h4defaultmargin + BDFDB.disCN.marginreset}" > Friends LogIn / - Out Timelog < / h 4 >
< / d i v >
2019-01-22 20:15:31 +01:00
< button type = "button" class = "${BDFDB.disCNS.modalclose + BDFDB.disCNS.flexchild + BDFDB.disCNS.button + BDFDB.disCNS.buttonlookblank + BDFDB.disCNS.buttoncolorbrand + BDFDB.disCN.buttongrow}" >
< div class = "${BDFDB.disCN.buttoncontents}" >
< svg name = "Close" width = "18" height = "18" viewBox = "0 0 12 12" style = "flex: 0 1 auto;" >
< g fill = "none" fill - rule = "evenodd" >
< path d = "M0 0h12v12H0" > < / p a t h >
< path class = "fill" fill = "currentColor" d = "M9.5 3.205L8.795 2.5 6 5.295 3.205 2.5l-.705.705L5.295 6 2.5 8.795l.705.705L6 6.705 8.795 9.5l.705-.705L6.705 6" > < / p a t h >
< / g >
< / s v g >
< / d i v >
< / b u t t o n >
2018-10-11 10:21:26 +02:00
< / d i v >
< div class = "${BDFDB.disCNS.scrollerwrap + BDFDB.disCNS.modalcontent + BDFDB.disCNS.scrollerthemed + BDFDB.disCN.themeghosthairline}" >
< div class = "${BDFDB.disCNS.scroller + BDFDB.disCN.modalsubinner} entries" >
< / d i v >
< / d i v >
< div class = "${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontalreverse + BDFDB.disCNS.horizontalreverse2 + BDFDB.disCNS.directionrowreverse + BDFDB.disCNS.justifystart + BDFDB.disCNS.alignstretch + BDFDB.disCNS.nowrap + BDFDB.disCN.modalfooter}" >
< button type = "button" class = "btn-ok ${BDFDB.disCNS.button + BDFDB.disCNS.buttonlookfilled + BDFDB.disCNS.buttoncolorbrand + BDFDB.disCNS.buttonsizemedium + BDFDB.disCN.buttongrow}" >
< div class = "${BDFDB.disCN.buttoncontents}" > < / d i v >
< / b u t t o n >
< / d i v >
< / d i v >
< / d i v >
< / d i v >
< / s p a n > ` ;
this . logEntryMarkup =
` <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 . disCNS . margintop4 + BDFDB . disCN . marginbottom4 } entry" 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.disCNS.flexchild + BDFDB.disCNS.overflowellipsis} log-time" style = "flex: 0 0 auto;" > < / h 3 >
< div class = "log-avatar" > < / d i v >
< h3 class = "${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCNS.flexchild + BDFDB.disCNS.overflowellipsis} log-description" style = "flex: 1 1 auto;" > < / h 3 >
< / d i v > ` ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . css = `
$ { BDFDB . dotCN . guilds } > $ { BDFDB . dotCN . friendsonline } {
cursor : pointer ;
}
2019-01-24 13:37:08 +01:00
. $ { this . name } - modal . log - time {
2018-10-11 10:21:26 +02:00
width : 110 px ;
}
2019-01-24 13:37:08 +01:00
. $ { this . name } - modal . log - avatar {
2018-10-11 10:21:26 +02:00
width : 35 px ;
height : 35 px ;
background - size : cover ;
background - position : center ;
border - radius : 50 % ;
}
2019-01-24 13:37:08 +01:00
. $ { this . name } - settings . avatar - list {
2018-10-11 10:21:26 +02:00
display : flex ;
align - items : center ;
flex - wrap : wrap ;
}
2019-01-24 13:37:08 +01:00
. $ { this . name } - settings . type - toast , . $ { this . name } - settings . type - desktop {
2018-10-11 10:21:26 +02:00
border - radius : 3 px ;
padding : 0 3 px ;
}
2019-01-24 13:37:08 +01:00
. $ { this . name } - settings . type - toast {
2018-10-11 10:21:26 +02:00
background - color : # 7289 DA ;
}
2019-01-24 13:37:08 +01:00
. $ { this . name } - settings . type - desktop {
2018-10-11 10:21:26 +02:00
background - color : # 43 B581 ;
}
2019-01-24 13:37:08 +01:00
. $ { this . name } - settings . settings - avatar . desktop {
2018-10-11 10:21:26 +02:00
border - color : # 43 B581 ;
}
2019-01-24 13:37:08 +01:00
. $ { this . name } - settings . settings - avatar {
2018-10-11 10:21:26 +02:00
margin : 5 px ;
width : 50 px ;
height : 50 px ;
background - size : cover ;
background - position : center ;
border : 5 px solid # 7289 DA ;
border - radius : 50 % ;
box - sizing : border - box ;
cursor : pointer ;
}
2019-01-24 13:37:08 +01:00
. $ { this . name } - settings . settings - avatar . desktop {
2018-10-11 10:21:26 +02:00
border - color : # 43 B581 ;
}
2019-01-24 13:37:08 +01:00
. $ { this . name } - settings . settings - avatar . disabled {
2018-10-11 10:21:26 +02:00
border - color : # 36393 F ;
filter : grayscale ( 100 % ) brightness ( 50 % ) ;
2018-11-19 14:54:44 +01:00
} ` ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . defaults = {
settings : {
muteOnDND : { value : false , description : "Do not notify me when I am DnD:" } ,
onlyOnOnline : { value : false , description : "Only notify me when a User logs in:" } ,
openOnClick : { value : false , description : "Open the DM when you click a Notification:" }
2018-11-23 14:37:30 +01:00
} ,
notificationsounds : {
toastonline : { value : { url : null , song : null , mute : false } } ,
toastoffline : { value : { url : null , song : null , mute : false } } ,
desktoponline : { value : { url : null , song : null , mute : false } } ,
desktopoffline : { value : { url : null , song : null , mute : false } }
2018-10-11 10:21:26 +02:00
}
} ;
}
2019-01-26 22:45:19 +01:00
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 ;
2019-01-03 10:20:41 +01:00
let settings = BDFDB . getAllData ( this , "settings" ) ;
let notificationsounds = BDFDB . getAllData ( this , "notificationsounds" ) ;
let desktop = BDFDB . loadAllData ( this , "desktop" ) ;
let disabled = BDFDB . loadAllData ( this , "disabled" ) ;
2019-04-18 09:28:20 +02:00
let settingshtml = ` <div class=" ${ this . name } -settings BDFDB-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="BDFDB-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" ${ settings [ key ] ? " checked" : "" } ></div></div> ` ;
2018-10-11 10:21:26 +02:00
}
2018-11-23 14:37:30 +01:00
for ( let key in notificationsounds ) {
if ( key . indexOf ( "desktop" ) == - 1 || "Notification" in window ) settingshtml += ` <div class=" ${ BDFDB . disCNS . flexchild + BDFDB . disCN . marginbottom8 } " style="flex: 1 1 auto;"><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;"><h5 class=" ${ BDFDB . disCNS . flexchild + BDFDB . disCNS . h5 + BDFDB . disCNS . title + BDFDB . disCNS . size12 + BDFDB . disCNS . height16 + BDFDB . disCNS . weightsemibold + BDFDB . disCNS . h5defaultmargin } " style="flex: 1 1 auto;"> ${ key } notification sound:</h5><h5 class=" ${ BDFDB . disCNS . flexchild + BDFDB . disCNS . h5 + BDFDB . disCNS . title + BDFDB . disCNS . size12 + BDFDB . disCNS . height16 + BDFDB . disCNS . weightsemibold + BDFDB . disCNS . h5defaultmargin } " style="flex: 0 0 auto;">Mute:</h5><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" option=" ${ key } " class=" ${ BDFDB . disCNS . switchinnerenabled + BDFDB . disCN . switchinner } mute-checkbox" ${ notificationsounds [ key ] . mute ? " checked" : "" } ></div></div><div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . flex2 + BDFDB . disCNS . horizontal + BDFDB . disCNS . horizontal2 + BDFDB . disCNS . directionrow + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCN . nowrap } " style="flex: 1 1 auto;"><div class=" ${ BDFDB . disCNS . inputwrapper + BDFDB . disCNS . vertical + BDFDB . disCNS . flex + BDFDB . disCNS . directioncolumn + BDFDB . disCN . flexchild } " style="flex: 1 1 auto;"><input type="text" option=" ${ key } " value=" ${ notificationsounds [ key ] . url ? notificationsounds [ key ] . url : "" } " placeholder="Url or Filepath" class=" ${ BDFDB . disCNS . inputdefault + BDFDB . disCNS . input + BDFDB . disCN . size16 } songInput"></div><button type="button" class=" ${ BDFDB . disCNS . flexchild + BDFDB . disCNS . button + BDFDB . disCNS . buttonlookfilled + BDFDB . disCNS . buttoncolorbrand + BDFDB . disCNS . buttonsizemedium + BDFDB . disCN . buttongrow } file-navigator" style="flex: 0 0 auto;"><div class=" ${ BDFDB . disCN . buttoncontents } "></div><input type="file" accept="audio/*,video/*" style="display:none!important;"></button><button type="button" option=" ${ key } " class=" ${ BDFDB . disCNS . flexchild + BDFDB . disCNS . button + BDFDB . disCNS . buttonlookfilled + BDFDB . disCNS . buttoncolorbrand + BDFDB . disCNS . buttonsizemedium + BDFDB . disCN . buttongrow } btn-save btn-savesong" style="flex: 0 0 auto;"><div class=" ${ BDFDB . disCN . buttoncontents } "></div></button></div></div> ` ;
}
2018-10-11 10:21:26 +02: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: 0 0 auto;">Click on a Icon to toggle <label class="type-toast">Toast</label> Notifications for that User:</h3></div> ` ;
if ( "Notification" in window ) 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: 0 0 auto;">Rightclick on a Icon to toggle <label class="type-desktop">Desktop</label> Notifications for that User:</h3></div> ` ;
settingshtml += ` <div class="avatar-list ${ BDFDB . disCN . marginbottom8 } "> ` ;
for ( let id of this . FriendUtils . getFriendIDs ( ) ) {
let user = this . UserUtils . getUser ( id ) ;
if ( user ) {
let data = BDFDB . loadData ( user . id , "EditUsers" , "users" ) || { } ;
settingshtml += ` <div class="settings-avatar ${ desktop [ id ] ? " desktop" : "" } ${ disabled [ id ] ? " disabled" : "" } " user-id=" ${ id } " style="background-image: url( ${ data . removeIcon ? "" : ( data . url ? data . url : BDFDB . getUserAvatar ( user . id ) ) } );"></div> ` ;
}
}
settingshtml += ` </div> ` ;
2018-11-19 14:54:44 +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 . marginbottom20 } " style="flex: 0 0 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;">Batch set Users:</h3><button type="button" do-disable=true class=" ${ BDFDB . disCNS . flexchild + BDFDB . disCNS . button + BDFDB . disCNS . buttoncolorprimary + BDFDB . disCNS . buttonlookfilled + BDFDB . disCNS . buttonsizemedium + BDFDB . disCN . buttongrow } disable-all" style="flex: 0 0 auto;"><div class=" ${ BDFDB . disCN . buttoncontents } ">Disable</div></button><button type="button" do-toast=true class=" ${ BDFDB . disCNS . flexchild + BDFDB . disCNS . button + BDFDB . disCNS . buttonlookfilled + BDFDB . disCNS . buttoncolorbrand + BDFDB . disCNS . buttonsizemedium + BDFDB . disCN . buttongrow } toast-all" style="flex: 0 0 auto;"><div class=" ${ BDFDB . disCN . buttoncontents } ">Toast</div></button> ${ "Notification" in window ? ` <button type="button" do-desktop=true class=" ${ BDFDB . disCNS . flexchild + BDFDB . disCNS . button + BDFDB . disCNS . buttonlookfilled + BDFDB . disCNS . buttoncolorgreen + BDFDB . disCNS . buttonsizemedium + BDFDB . disCN . buttongrow } desktop-all" style="flex: 0 0 auto;"><div class=" ${ BDFDB . disCN . buttoncontents } ">Desktop</div></button> ` : ` ` } </div> ` ;
2019-05-01 21:02:25 +02: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 . marginbottom20 } " style="flex: 0 0 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;">Timelog of LogIns/-Outs:</h3><button type="button" class=" ${ BDFDB . disCNS . flexchild + BDFDB . disCNS . button + BDFDB . disCNS . buttonlookfilled + BDFDB . disCNS . buttoncolorbrand + BDFDB . disCNS . buttonsizemedium + BDFDB . disCN . buttongrow } btn-timelog" style="flex: 0 0 auto;"><div class=" ${ BDFDB . disCN . buttoncontents } ">Timelog</div></button></div> ` ;
2018-10-11 10:21:26 +02:00
settingshtml += ` </div></div> ` ;
2019-01-26 22:45:19 +01:00
2019-01-17 23:48:29 +01:00
let settingspanel = BDFDB . htmlToElement ( settingshtml ) ;
2018-10-11 10:21:26 +02:00
2019-01-17 23:48:29 +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" , ".btn-savesong" , e => { this . saveAudio ( settingspanel , e . currentTarget . getAttribute ( "option" ) ) ; } ) ;
BDFDB . addEventListener ( this , settingspanel , "click" , ".mute-checkbox" , e => {
let option = e . currentTarget . getAttribute ( "option" ) ;
let notificationsound = BDFDB . getData ( option , this , "notificationsounds" ) ;
notificationsound . mute = e . currentTarget . checked ;
BDFDB . saveData ( option , notificationsound , this , "notificationsounds" ) ;
} ) ;
BDFDB . addEventListener ( this , settingspanel , "mouseenter" , ".settings-avatar" , e => {
let user = this . UserUtils . getUser ( e . currentTarget . getAttribute ( "user-id" ) ) ;
let data = BDFDB . loadData ( user . id , "EditUsers" , "users" ) || { } ;
BDFDB . createTooltip ( data . name ? data . name : user . username , e . currentTarget , { type : "top" } ) ;
} ) ;
BDFDB . addEventListener ( this , settingspanel , "contextmenu" , ".settings-avatar" , e => {
if ( ! ( "Notification" in window ) ) return ;
let desktopoff = ! BDFDB . containsClass ( e . currentTarget , "desktop" ) ;
let id = e . currentTarget . getAttribute ( "user-id" ) ;
BDFDB . removeClass ( e . currentTarget , "disabled" ) ;
BDFDB . toggleClass ( e . currentTarget , "desktop" , desktopoff ) ;
BDFDB . saveData ( id , desktopoff , this , "desktop" ) ;
BDFDB . removeData ( id , this , "disabled" ) ;
} ) ;
BDFDB . addEventListener ( this , settingspanel , "click" , ".settings-avatar" , e => {
let disableoff = ! BDFDB . containsClass ( e . currentTarget , "disabled" ) ;
let id = e . currentTarget . getAttribute ( "user-id" ) ;
BDFDB . removeClass ( e . currentTarget , "desktop" ) ;
BDFDB . toggleClass ( e . currentTarget , "disabled" , disableoff ) ;
BDFDB . saveData ( id , disableoff , this , "disabled" ) ;
BDFDB . removeData ( id , this , "desktop" ) ;
} ) ;
BDFDB . addEventListener ( this , settingspanel , "click" , ".disable-all, .toast-all, .desktop-all" , e => {
let disableon = e . currentTarget . getAttribute ( "do-disable" ) ;
let desktopon = e . currentTarget . getAttribute ( "do-desktop" ) ;
let disabledata = BDFDB . loadAllData ( this , "disabled" ) ;
let desktopdata = BDFDB . loadAllData ( this , "desktop" ) ;
settingspanel . querySelectorAll ( ".settings-avatar" ) . forEach ( avatar => {
let id = avatar . getAttribute ( "user-id" ) ;
BDFDB . toggleClass ( avatar , "disabled" , disableon ) ;
BDFDB . toggleClass ( avatar , "desktop" , desktopon ) ;
disableon ? disabledata [ id ] = true : delete disabledata [ id ] ;
desktopon ? desktopdata [ id ] = true : delete desktopdata [ id ] ;
2018-10-11 10:21:26 +02:00
} ) ;
2019-01-17 23:48:29 +01:00
BDFDB . saveAllData ( disabledata , this , "disabled" ) ;
BDFDB . saveAllData ( desktopdata , this , "desktop" ) ;
} ) ;
2019-05-01 21:02:25 +02:00
BDFDB . addEventListener ( this , settingspanel , "click" , ".btn-timelog" , ( ) => { this . showTimeLog ( ) ; } ) ;
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-05-26 13:55:26 +02:00
var libraryScript = document . querySelector ( 'head script#BDFDBLibraryScript' ) ;
if ( ! libraryScript || ( performance . now ( ) - libraryScript . getAttribute ( "date" ) ) > 600000 ) {
2018-10-11 10:21:26 +02:00
if ( libraryScript ) libraryScript . remove ( ) ;
libraryScript = document . createElement ( "script" ) ;
2019-05-26 13:55:26 +02:00
libraryScript . setAttribute ( "id" , "BDFDBLibraryScript" ) ;
2018-10-11 10:21:26 +02:00
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-05-26 13:55:26 +02:00
libraryScript . addEventListener ( "load" , ( ) => { this . initialize ( ) ; } ) ;
2018-10-11 10:21:26 +02:00
document . head . appendChild ( libraryScript ) ;
2019-05-26 13:55:26 +02:00
this . libLoadTimeout = setTimeout ( ( ) => {
libraryScript . remove ( ) ;
require ( "request" ) ( "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js" , ( error , response , body ) => {
if ( body ) {
libraryScript = document . createElement ( "script" ) ;
libraryScript . setAttribute ( "id" , "BDFDBLibraryScript" ) ;
libraryScript . setAttribute ( "type" , "text/javascript" ) ;
libraryScript . setAttribute ( "date" , performance . now ( ) ) ;
libraryScript . innerText = body ;
document . head . appendChild ( libraryScript ) ;
}
this . initialize ( ) ;
} ) ;
} , 15000 ) ;
}
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 23:48:29 +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
2018-12-20 22:54:42 +01:00
this . FriendUtils = BDFDB . WebModules . findByProperties ( "getFriendIDs" , "getRelationships" ) ;
this . ChannelUtils = BDFDB . WebModules . findByProperties ( "getDMFromUserId" ) ;
this . ChannelSwitchUtils = BDFDB . WebModules . findByProperties ( "selectPrivateChannel" ) ;
this . PrivateChannelUtils = BDFDB . WebModules . findByProperties ( "openPrivateChannel" ) ;
this . UserMetaStore = BDFDB . WebModules . findByProperties ( "getStatus" , "getOnlineFriendCount" ) ;
this . UserUtils = BDFDB . WebModules . findByProperties ( "getUsers" ) ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
for ( let id of this . FriendUtils . getFriendIDs ( ) ) {
this . friendsOnlineList [ id ] = this . UserMetaStore . getStatus ( id ) != "offline" ;
}
2019-01-26 22:45:19 +01:00
2019-05-01 21:02:25 +02:00
this . startInterval ( ) ;
2019-01-03 10:20:41 +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 23:48:29 +01:00
if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) {
2019-05-01 21:02:25 +02:00
clearInterval ( this . checkInterval ) ;
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
2018-11-23 14:37:30 +01:00
saveAudio ( settingspanel , option ) {
2019-01-03 10:20:41 +01:00
let successSavedAudio = ( parsedurl , parseddata ) => {
2018-10-11 10:21:26 +02:00
if ( parsedurl && parseddata ) BDFDB . showToast ( ` Sound was saved successfully. ` , { type : "success" } ) ;
2018-11-23 14:37:30 +01:00
let notificationsound = BDFDB . getData ( option , this , "notificationsounds" ) ;
2018-10-11 10:21:26 +02:00
notificationsound . url = parsedurl ;
notificationsound . song = parseddata ;
2018-11-23 14:37:30 +01:00
BDFDB . saveData ( option , notificationsound , this , "notificationsounds" ) ;
2018-10-11 10:21:26 +02:00
} ;
2019-01-26 22:45:19 +01:00
2019-01-03 10:20:41 +01:00
let url = settingspanel . querySelector ( ` .songInput[option=" ${ option } "] ` ) . value ;
2018-10-11 10:21:26 +02:00
if ( url . length == 0 ) {
2018-11-23 14:37:30 +01:00
BDFDB . showToast ( ` Sound file was removed. ` , { type : "warn" } ) ;
2018-10-11 10:21:26 +02:00
successSavedAudio ( url , url ) ;
}
else if ( url . indexOf ( "http" ) == 0 ) {
require ( "request" ) ( url , ( error , response , result ) => {
if ( response ) {
2019-01-03 10:20:41 +01:00
let type = response . headers [ "content-type" ] ;
2018-10-11 10:21:26 +02:00
if ( type && ( type . indexOf ( "octet-stream" ) > - 1 || type . indexOf ( "audio" ) > - 1 || type . indexOf ( "video" ) > - 1 ) ) {
successSavedAudio ( url , url ) ;
return ;
}
}
BDFDB . showToast ( "Use a valid direct link to a video or audio source. They usually end on something like .mp3, .mp4 or .wav." , { type : "danger" } ) ;
} ) ;
}
else {
require ( "fs" ) . readFile ( url , ( error , response ) => {
2019-01-03 10:20:41 +01:00
if ( error ) BDFDB . showToast ( "Could not fetch file. Please make sure the file exists." , { type : "danger" } ) ;
else successSavedAudio ( url , ` data:audio/mpeg;base64, ${ response . toString ( "base64" ) } ` ) ;
} ) ;
}
}
2019-01-26 22:45:19 +01:00
2019-02-22 20:12:38 +01:00
processFriendsOnline ( instance , wrapper ) {
2019-01-17 23:48:29 +01:00
BDFDB . addEventListener ( this , wrapper , "mouseenter" , ( ) => { BDFDB . createTooltip ( "Timelog" , wrapper , { type : "right" } ) ; } ) ;
BDFDB . addEventListener ( this , wrapper , "click" , ( ) => { this . showTimeLog ( ) ; } ) ;
2019-05-01 21:02:25 +02:00
clearInterval ( this . checkInterval ) ;
2019-01-26 22:45:19 +01:00
2019-05-01 21:02:25 +02:00
this . checkFriends ( ) ;
}
checkFriends ( ) {
2019-01-03 10:20:41 +01:00
let settings = BDFDB . getAllData ( this , "settings" ) ;
for ( let id of this . FriendUtils . getFriendIDs ( ) ) {
let online = this . UserMetaStore . getStatus ( id ) != "offline" ;
let user = this . UserUtils . getUser ( id ) ;
if ( user && this . friendsOnlineList [ id ] != online && ! BDFDB . loadData ( id , this , "disabled" ) ) {
this . timeLog . push ( { user , online , time : new Date ( ) } ) ;
if ( ! ( settings . onlyOnOnline && ! online ) && ! ( settings . muteOnDND && BDFDB . getUserStatus ( ) == "dnd" ) ) {
let data = BDFDB . loadData ( user . id , "EditUsers" , "users" ) || { } ;
let string = ` ${ BDFDB . encodeToHTML ( data . name ? data . name : user . username ) } is ${ online ? "online" : "offline" } . ` ;
let avatar = data . removeIcon ? "" : ( data . url ? data . url : BDFDB . getUserAvatar ( user . id ) ) ;
let openChannel = ( ) => {
if ( settings . openOnClick ) {
let DMid = this . ChannelUtils . getDMFromUserId ( user . id )
if ( DMid ) this . ChannelSwitchUtils . selectPrivateChannel ( DMid ) ;
else this . PrivateChannelUtils . openPrivateChannel ( BDFDB . myData . id , user . id ) ;
require ( "electron" ) . remote . getCurrentWindow ( ) . maximize ( ) ;
}
} ;
if ( ! BDFDB . loadData ( id , this , "desktop" ) ) {
2019-01-05 23:27:49 +01:00
let toast = BDFDB . showToast ( ` <div class="toast-inner"><div class="toast-avatar" style="background-image:url( ${ avatar } );"></div><div> ${ string } </div></div> ` , { html : true , timeout : 5000 , type : ( online ? "success" : null ) , icon : false , selector : ` friendnotifications- ${ online ? "online" : "offline" } -toast ` } ) ;
2019-01-17 23:48:29 +01:00
toast . addEventListener ( "click" , openChannel ) ;
2019-01-03 10:20:41 +01:00
let notificationsound = BDFDB . getData ( online ? "toastonline" : "toastoffline" , this , "notificationsounds" ) ;
if ( ! notificationsound . mute && notificationsound . song ) {
let audio = new Audio ( ) ;
audio . src = notificationsound . song ;
audio . play ( ) ;
}
}
else {
let notificationsound = BDFDB . getData ( online ? "desktoponline" : "desktopoffline" , this , "notificationsounds" ) ;
BDFDB . showDesktopNotification ( string , { icon : avatar , timeout : 5000 , click : openChannel , silent : notificationsound . mute , sound : notificationsound . song } ) ;
}
}
}
this . friendsOnlineList [ id ] = online ;
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2019-05-01 21:02:25 +02:00
startInterval ( ) {
clearInterval ( this . checkInterval ) ;
let oldcount = this . UserMetaStore . getOnlineFriendCount ( ) , newcount = 0 ;
this . checkInterval = setInterval ( ( ) => {
newcount = this . UserMetaStore . getOnlineFriendCount ( ) ;
if ( oldcount != newcount ) {
oldcount = newcount ;
this . checkFriends ( ) ;
}
} , 10000 ) ;
}
2019-01-17 23:48:29 +01:00
showTimeLog ( ) {
let timeLogModal = BDFDB . htmlToElement ( this . timeLogModalMarkup ) ;
let container = timeLogModal . querySelector ( ".entries" ) ;
if ( ! container ) return ;
2018-10-11 10:21:26 +02:00
let logs = this . timeLog . slice ( 0 ) . reverse ( ) ;
for ( let log of logs ) {
2019-01-17 23:48:29 +01:00
if ( container . childElementCount ) container . appendChild ( BDFDB . htmlToElement ( ` <div class=" ${ BDFDB . disCN . modaldivider } "></div> ` ) ) ;
2018-10-11 10:21:26 +02:00
let data = BDFDB . loadData ( log . user . id , "EditUsers" , "users" ) || { } ;
2019-01-17 23:48:29 +01:00
let entry = BDFDB . htmlToElement ( this . logEntryMarkup ) ;
entry . querySelector ( ".log-time" ) . innerText = ` [ ${ log . time . toLocaleTimeString ( ) } ] ` ;
entry . querySelector ( ".log-avatar" ) . style . setProperty ( "background-image" , ` url( ${ data . removeIcon ? "" : ( data . url ? data . url : BDFDB . getUserAvatar ( log . user . id ) ) } ) ` ) ;
entry . querySelector ( ".log-description" ) . innerText = ` ${ data . name || log . user . username } is ${ log . online ? "online" : "offline" } . ` ;
container . appendChild ( entry )
2018-10-11 10:21:26 +02:00
}
BDFDB . appendModal ( timeLogModal ) ;
}
}