2019-09-20 22:32:52 +02: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-11-23 20:43:17 +01:00
getVersion ( ) { return "1.3.4" ; }
2019-01-17 23:48:29 +01:00
getAuthor ( ) { return "DevilBro" ; }
2019-08-22 16:17:21 +02:00
getDescription ( ) { return "Notifies you when a Friend or a User your choose to observe changing his online status, can be configured individually in the settings." ; }
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
constructor ( ) {
2019-05-01 21:02:25 +02:00
this . changelog = {
2019-11-23 20:43:17 +01:00
"fixed" : [ [ "Non Friends" , "Fixed issue where you are unable to add non friends to the observer list" ] ]
2019-05-01 21:02:25 +02:00
} ;
2019-09-11 12:14:43 +02:00
2019-11-14 17:56:26 +01:00
this . patchedModules = {
after : {
"StandardSidebarView" : "componentWillUnmount"
}
2019-01-03 10:20:41 +01:00
} ;
2019-09-04 12:34:02 +02:00
}
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
initConstructor ( ) {
2019-08-22 16:17:21 +02:00
this . userStatusStore = { } ;
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}" >
2019-10-08 11:51:41 +02:00
< div class = "${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.modalheader}" style = "flex: 0 0 auto;" >
2018-10-11 10:21:26 +02:00
< div class = "${BDFDB.disCN.flexchild}" style = "flex: 1 1 auto;" >
2019-09-11 12:14:43 +02:00
< h4 class = "${BDFDB.disCNS.h4 + BDFDB.disCNS.defaultcolor + BDFDB.disCN.h4defaultmargin}" > Friends LogIn / - Out Timelog < / h 4 >
2018-10-11 10:21:26 +02:00
< / 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 >
2019-10-09 14:18:28 +02:00
< div class = "${BDFDB.disCNS.scrollerwrap + BDFDB.disCNS.modalcontent + BDFDB.disCNS.scrollerthemed + BDFDB.disCN.scrollerthemeghosthairline}" >
2018-10-11 10:21:26 +02:00
< div class = "${BDFDB.disCNS.scroller + BDFDB.disCN.modalsubinner} entries" >
< / d i v >
< / d i v >
2019-09-18 10:19:56 +02:00
< div class = "${BDFDB.disCNS.flex + BDFDB.disCNS.horizontalreverse + BDFDB.disCNS.horizontalreverse2 + BDFDB.disCNS.directionrowreverse + BDFDB.disCNS.justifystart + BDFDB.disCNS.alignstretch + BDFDB.disCNS.nowrap + BDFDB.disCN.modalfooter}" >
2018-10-11 10:21:26 +02:00
< 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 =
2019-10-08 11:51:41 +02:00
` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCNS . margintop4 + BDFDB . disCN . marginbottom4 } entry" style="flex: 1 1 auto;">
2019-10-09 14:18:28 +02:00
< h3 class = "${BDFDB.disCNS.titledefault + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCNS.height24 + BDFDB.disCNS.flexchild + BDFDB.disCNS.overflowellipsis} log-time" style = "flex: 0 0 auto;" > < / h 3 >
2018-10-11 10:21:26 +02:00
< div class = "log-avatar" > < / d i v >
2019-10-09 14:18:28 +02:00
< h3 class = "${BDFDB.disCNS.titledefault + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCNS.height24 + BDFDB.disCNS.flexchild + BDFDB.disCNS.overflowellipsis} log-description" style = "flex: 1 1 auto;" > < / h 3 >
2018-10-11 10:21:26 +02:00
< / d i v > ` ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . css = `
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 . 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 ;
2019-08-22 16:17:21 +02:00
width : 35 px ;
height : 35 px ;
2018-10-11 10:21:26 +02:00
background - size : cover ;
background - position : center ;
2019-08-22 16:17:21 +02:00
border : 3 px solid # 7289 DA ;
2018-10-11 10:21:26 +02:00
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 % ) ;
2019-08-22 16:17:21 +02:00
}
. $ { this . name } - settings . settings - avatar . disabled ~ * {
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 : {
2019-09-19 16:02:12 +02:00
disableForNew : { value : false , description : "Disable Notifications for newly added Friends:" } ,
2018-10-11 10:21:26 +02:00
muteOnDND : { value : false , description : "Do not notify me when I am DnD:" } ,
openOnClick : { value : false , description : "Open the DM when you click a Notification:" }
2018-11-23 14:37:30 +01:00
} ,
2019-08-27 13:07:48 +02:00
notificationstrings : {
2019-09-19 16:02:12 +02:00
online : { value : "$user changed status to '$status'" , libstring : "STATUS_ONLINE" , init : true } ,
mobile : { value : "$user changed status to '$status'" , libstring : "STATUS_ONLINE_MOBILE" , init : true } ,
idle : { value : "$user changed status to '$status'" , libstring : "STATUS_IDLE" , init : false } ,
dnd : { value : "$user changed status to '$status'" , libstring : "STATUS_DND" , init : false } ,
playing : { value : "$user started playing '$game'" , statusname : "Playing" , init : false } ,
listening : { value : "$user started listening to '$song'" , statusname : "Listening" , init : false } ,
streaming : { value : "$user started streaming '$game'" , libstring : "STATUS_STREAMING" , init : false } ,
offline : { value : "$user changed status to '$status'" , libstring : "STATUS_OFFLINE" , init : true }
2019-08-27 13:07:48 +02:00
} ,
2019-09-19 19:32:29 +02:00
notificationsounds : { } ,
2019-08-22 16:17:21 +02:00
amounts : {
2019-10-02 12:53:51 +02:00
toastTime : { value : 5 , min : 1 , description : "Amount of seconds a toast notification stays on screen:" } ,
desktopTime : { value : 5 , min : 1 , description : "Amount of seconds a desktop notification stays on screen:" } ,
2019-08-22 16:17:21 +02:00
checkInterval : { value : 10 , min : 5 , description : "Check Users every X seconds:" }
2018-10-11 10:21:26 +02:00
}
} ;
2019-09-19 19:32:29 +02:00
for ( let type in this . defaults . notificationstrings ) {
this . defaults . notificationsounds [ "toast" + type ] = { value : { url : null , song : null , mute : false } } ;
this . defaults . notificationsounds [ "desktop" + type ] = { value : { url : null , song : null , mute : false } } ;
}
2019-09-19 16:02:12 +02:00
this . activityTypes = { } ;
for ( let type in BDFDB . DiscordConstants . ActivityTypes ) this . activityTypes [ BDFDB . DiscordConstants . ActivityTypes [ type ] ] = type ;
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-09-04 12:34:02 +02:00
2019-10-22 19:49:57 +02:00
let settings = BDFDB . DataUtils . get ( this , "settings" ) ;
let notificationstrings = BDFDB . DataUtils . get ( this , "notificationstrings" ) ;
let notificationsounds = BDFDB . DataUtils . get ( this , "notificationsounds" ) ;
let amounts = BDFDB . DataUtils . get ( this , "amounts" ) ;
2019-09-04 12:34:02 +02:00
2019-09-11 12:14:43 +02:00
let friendIDs = BDFDB . LibraryModules . FriendUtils . getFriendIDs ( ) ;
2019-10-22 19:49:57 +02:00
let friends = BDFDB . DataUtils . load ( this , "friends" ) ;
let nonfriends = BDFDB . DataUtils . load ( this , "nonfriends" ) ;
2019-09-04 12:34:02 +02:00
2019-10-09 14:18:28 +02:00
let settingshtml = ` <div class=" ${ this . name } -settings BDFDB-settings"><div class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . titlesize18 + BDFDB . disCNS . height24 + BDFDB . disCNS . weightnormal + BDFDB . disCN . marginbottom8 } "> ${ this . name } </div><div class="BDFDB-settings-inner"> ` ;
2019-08-22 16:17:21 +02:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . h2 + BDFDB . disCNS . cursorpointer + BDFDB . disCNS . margintop4 + BDFDB . disCN . marginbottom4 } BDFDB-containertext"><span class="BDFDB-containerarrow closed"></span>General Settings</div><div class="BDFDB-collapsecontainer"> ` ;
2019-10-09 14:18:28 +02:00
for ( let key in settings ) settingshtml += ` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } " style="flex: 1 1 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . marginreset + BDFDB . disCNS . weightmedium + BDFDB . disCNS . titlesize16 + 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> ` ;
for ( let key in amounts ) if ( key . indexOf ( "desktop" ) == - 1 || "Notification" in window ) settingshtml += ` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } " style="flex: 1 1 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . weightmedium + BDFDB . disCNS . titlesize16 + BDFDB . disCN . flexchild } " style="flex: 0 0 80%;"> ${ this . defaults . amounts [ key ] . description } </h3><div class=" ${ BDFDB . disCN . inputwrapper } inputNumberWrapper ${ BDFDB . disCNS . vertical } " style="flex: 1 1 auto;"><span class="numberinput-buttons-zone"><span class="numberinput-button-up"></span><span class="numberinput-button-down"></span></span><input type="number" ${ ( ! isNaN ( this . defaults . amounts [ key ] . min ) && this . defaults . amounts [ key ] . min !== null ? ' min="' + this . defaults . amounts [ key ] . min + '"' : '' ) + ( ! isNaN ( this . defaults . amounts [ key ] . max ) && this . defaults . amounts [ key ] . max !== null ? ' max="' + this . defaults . amounts [ key ] . max + '"' : '' ) } option=" ${ key } " value=" ${ amounts [ key ] } " class=" ${ BDFDB . disCNS . inputdefault + BDFDB . disCNS . input + BDFDB . disCN . titlesize16 } amount-input"></div></div> ` ;
2019-10-15 11:46:37 +02:00
settingshtml += ` </div><div class=" ${ BDFDB . disCNS . divider + BDFDB . disCN . marginbottom4 } "></div> ` ;
2019-08-22 16:17:21 +02:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . h2 + BDFDB . disCNS . cursorpointer + BDFDB . disCNS . margintop4 + BDFDB . disCN . marginbottom4 } BDFDB-containertext"><span class="BDFDB-containerarrow closed"></span>Friend-List</div><div class="BDFDB-collapsecontainer"> ` ;
2019-10-09 14:18:28 +02:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } " style="flex: 1 1 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . marginreset + BDFDB . disCNS . weightmedium + BDFDB . disCNS . titlesize16 + BDFDB . disCNS . height24 + BDFDB . disCN . flexchild } " style="flex: 0 0 auto;">Click on an 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 . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } " style="flex: 1 1 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . marginreset + BDFDB . disCNS . weightmedium + BDFDB . disCNS . titlesize16 + BDFDB . disCNS . height24 + BDFDB . disCN . flexchild } " style="flex: 0 0 auto;">Rightclick on an Icon to toggle <label class="type-desktop">Desktop</label> Notifications for that User:</h3></div> ` ;
settingshtml += ` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } " style="flex: 1 1 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . marginreset + BDFDB . disCNS . weightmedium + BDFDB . disCNS . titlesize16 + BDFDB . disCNS . height24 + BDFDB . disCN . flexchild } " style="flex: 0 0 auto;">Click/Rightclick on the table headers to batch set all Friends</h3></div> ` ;
2019-11-08 15:53:36 +01:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } BDFDB-tableheader" table-id="friends" style="flex: 0 0 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . marginreset + BDFDB . disCNS . weightmedium + BDFDB . disCNS . titlesize16 + BDFDB . disCNS . height24 + BDFDB . disCN . flexchild } BDFDB-tableheadertext"><div class=" ${ BDFDB . disCNS . margintop8 + BDFDB . disCNS . settingstableheadersize + BDFDB . disCNS . titlesize10 + BDFDB . disCNS . primary + BDFDB . disCNS . weightbold + BDFDB . disCN . cursorpointer } btn-batch" group="friends" config="desktop" style="display: inline-block; margin: 0 25px;">TYPE</div><div class=" ${ BDFDB . disCNS . margintop8 + BDFDB . disCNS . settingstableheadersize + BDFDB . disCNS . titlesize10 + BDFDB . disCNS . primary + BDFDB . disCNS . weightbold + BDFDB . disCN . cursorpointer } btn-batch" group="friends" config="disabled" style="display: inline-block;">DISABLE</div></h3><div class=" ${ BDFDB . disCNS . flex2 + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifycenter + BDFDB . disCNS . alignend + BDFDB . disCN . nowrap } BDFDB-tableheadercolumns"> ` ;
for ( let config in this . defaults . notificationstrings ) settingshtml += ` <div class=" ${ BDFDB . disCNS . margintop8 + BDFDB . disCNS . settingstableheadersize + BDFDB . disCNS . titlesize10 + BDFDB . disCNS . primary + BDFDB . disCNS . weightbold + BDFDB . disCN . cursorpointer } BDFDB-tableheadercolumn" config=" ${ config } " group="friends"> ${ config . toUpperCase ( ) } </div> ` ;
2019-08-22 16:17:21 +02:00
settingshtml += ` </div></div><div class="BDFDB-settings-inner-list friend-list ${ BDFDB . disCN . marginbottom8 } "> ` ;
for ( let id of friendIDs ) {
2019-09-11 12:14:43 +02:00
let user = BDFDB . LibraryModules . UserStore . getUser ( id ) ;
2019-08-22 16:17:21 +02:00
if ( user ) {
2019-09-19 16:02:12 +02:00
let friend = null ;
if ( friends [ id ] ) { }
else if ( nonfriends [ id ] ) {
friends [ id ] = Object . assign ( { } , nonfriends [ id ] ) ;
delete nonfriends [ id ] ;
}
else friends [ id ] = this . createDefaultConfig ( ) ;
settingshtml += this . createHoverCard ( user , friends [ id ] , "friends" ) ;
2019-08-22 16:17:21 +02:00
}
2018-11-23 14:37:30 +01:00
}
2019-08-22 16:17:21 +02:00
settingshtml += ` </div> ` ;
2019-10-15 11:46:37 +02:00
settingshtml += ` </div><div class=" ${ BDFDB . disCNS . divider + BDFDB . disCN . marginbottom4 } "></div> ` ;
2019-08-22 16:17:21 +02:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . h2 + BDFDB . disCNS . cursorpointer + BDFDB . disCNS . margintop4 + BDFDB . disCN . marginbottom4 } BDFDB-containertext"><span class="BDFDB-containerarrow closed"></span>Non-Friend-List</div><div class="BDFDB-collapsecontainer"> ` ;
2019-10-09 14:18:28 +02:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } " style="flex: 1 1 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . marginreset + BDFDB . disCNS . weightmedium + BDFDB . disCNS . titlesize16 + 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 . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } " style="flex: 1 1 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . marginreset + BDFDB . disCNS . weightmedium + BDFDB . disCNS . titlesize16 + 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=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } " style="flex: 1 1 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . marginreset + BDFDB . disCNS . weightmedium + BDFDB . disCNS . titlesize16 + BDFDB . disCNS . height24 + BDFDB . disCN . flexchild } " style="flex: 0 0 auto;">Click/Rightclick on the table headers to batch set all Non-Friends</h3></div> ` ;
settingshtml += ` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } " style="flex: 1 1 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . weightmedium + BDFDB . disCNS . titlesize16 + BDFDB . disCN . flexchild } " style="flex: 0 0 50%;">Add Non-Friend:</h3><div class=" ${ BDFDB . disCNS . inputwrapper + BDFDB . disCNS . vertical + BDFDB . disCNS . flex2 + BDFDB . disCN . directioncolumn } " style="flex: 1 1 auto;"><input type="text" value="" placeholder="UserID" class=" ${ BDFDB . disCNS . inputdefault + BDFDB . disCNS . input + BDFDB . disCN . titlesize16 } " id="input-userid"></div><button type="button" class=" ${ BDFDB . disCNS . flexchild + BDFDB . disCNS . button + BDFDB . disCNS . buttonlookfilled + BDFDB . disCNS . buttoncolorbrand + BDFDB . disCNS . buttonsizemedium + BDFDB . disCN . buttongrow } btn-add btn-adduser" style="flex: 0 0 auto;"><div class=" ${ BDFDB . disCN . buttoncontents } "></div></button></div> ` ;
2019-11-08 15:53:36 +01:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } BDFDB-tableheader" table-id="nonfriends" style="flex: 0 0 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . marginreset + BDFDB . disCNS . weightmedium + BDFDB . disCNS . titlesize16 + BDFDB . disCNS . height24 + BDFDB . disCN . flexchild } BDFDB-tableheadertext"><div class=" ${ BDFDB . disCNS . margintop8 + BDFDB . disCNS . settingstableheadersize + BDFDB . disCNS . titlesize10 + BDFDB . disCNS . primary + BDFDB . disCNS . weightbold + BDFDB . disCN . cursorpointer } btn-batch" group="nonfriends" config="desktop" style="display: inline-block; margin: 0 25px;">TYPE</div><div class=" ${ BDFDB . disCNS . margintop8 + BDFDB . disCNS . settingstableheadersize + BDFDB . disCNS . titlesize10 + BDFDB . disCNS . primary + BDFDB . disCNS . weightbold + BDFDB . disCN . cursorpointer } btn-batch" group="nonfriends" config="disabled" style="display: inline-block;">DISABLE</div></h3><div class=" ${ BDFDB . disCNS . flex2 + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifycenter + BDFDB . disCNS . alignend + BDFDB . disCN . nowrap } BDFDB-tableheadercolumns"> ` ;
for ( let config in this . defaults . notificationstrings ) settingshtml += ` <div class=" ${ BDFDB . disCNS . margintop8 + BDFDB . disCNS . settingstableheadersize + BDFDB . disCNS . titlesize10 + BDFDB . disCNS . primary + BDFDB . disCNS . weightbold + BDFDB . disCN . cursorpointer } BDFDB-tableheadercolumn" config=" ${ config } " group="nonfriends"> ${ config . toUpperCase ( ) } </div> ` ;
2019-08-22 16:17:21 +02:00
settingshtml += ` </div></div><div class="BDFDB-settings-inner-list nonfriend-list ${ BDFDB . disCN . marginbottom8 } "> ` ;
for ( let id in nonfriends ) if ( ! friendIDs . includes ( id ) ) {
2019-09-11 12:14:43 +02:00
let user = BDFDB . LibraryModules . UserStore . getUser ( id ) ;
2018-10-11 10:21:26 +02:00
if ( user ) {
2019-09-19 16:02:12 +02:00
delete friends [ id ] ;
settingshtml += this . createHoverCard ( user , nonfriends [ id ] || ( nonfriends [ id ] = this . createDefaultConfig ( ) ) , "nonfriends" ) ;
2018-10-11 10:21:26 +02:00
}
}
settingshtml += ` </div> ` ;
2019-10-15 11:46:37 +02:00
settingshtml += ` </div><div class=" ${ BDFDB . disCNS . divider + BDFDB . disCN . marginbottom4 } "></div> ` ;
2019-08-22 16:17:21 +02:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . h2 + BDFDB . disCNS . cursorpointer + BDFDB . disCNS . margintop4 + BDFDB . disCN . marginbottom4 } BDFDB-containertext"><span class="BDFDB-containerarrow closed"></span>Timelog</div><div class="BDFDB-collapsecontainer"> ` ;
2019-10-09 14:18:28 +02:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom20 } " style="flex: 0 0 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . marginreset + BDFDB . disCNS . weightmedium + BDFDB . disCNS . titlesize16 + 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> ` ;
2019-10-15 11:46:37 +02:00
settingshtml += ` </div><div class=" ${ BDFDB . disCNS . divider + BDFDB . disCN . marginbottom4 } "></div> ` ;
2019-08-27 13:07:48 +02:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . h2 + BDFDB . disCNS . cursorpointer + BDFDB . disCNS . margintop4 + BDFDB . disCN . marginbottom4 } BDFDB-containertext"><span class="BDFDB-containerarrow closed"></span>Notification Message Settings</div><div class="BDFDB-collapsecontainer"> ` ;
2019-10-09 14:18:28 +02:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } " style="flex: 1 1 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . marginreset + BDFDB . disCNS . weightmedium + BDFDB . disCNS . titlesize16 + BDFDB . disCNS . height24 + BDFDB . disCN . flexchild } ">Allows you to configure your own message strings for the different statuses. <strong> $ user</strong> is the placeholder for the username, <strong> $ status</strong> for the statusname, <strong> $ game</strong> for the gamename, <strong> $ song</strong> for the songname and <strong> $ artist</strong> for the songartist.</h3></div> ` ;
2019-08-27 13:07:48 +02:00
for ( let config in notificationstrings ) {
2019-10-09 14:18:28 +02:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } " style="flex: 1 1 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . weightmedium + BDFDB . disCNS . titlesize16 + BDFDB . disCN . flexchild } " style="flex: 0 0 30%;"> ${ config . charAt ( 0 ) . toUpperCase ( ) + config . slice ( 1 ) } Message:</h3><div class=" ${ BDFDB . disCNS . inputwrapper + BDFDB . disCNS . vertical + BDFDB . disCNS . flex2 + BDFDB . disCN . directioncolumn } " style="flex: 1 1 auto;"><input type="text" config=" ${ config } " value=" ${ notificationstrings [ config ] } " placeholder=" ${ this . defaults . notificationstrings [ config ] . value } " class=" ${ BDFDB . disCNS . inputdefault + BDFDB . disCNS . input + BDFDB . disCN . titlesize16 } input-notificationstring"></div></div> ` ;
2019-08-27 13:07:48 +02:00
}
2019-10-15 11:46:37 +02:00
settingshtml += ` </div><div class=" ${ BDFDB . disCNS . divider + BDFDB . disCN . marginbottom4 } "></div> ` ;
2019-08-27 13:07:48 +02:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . h2 + BDFDB . disCNS . cursorpointer + BDFDB . disCNS . margintop4 + BDFDB . disCN . marginbottom4 } BDFDB-containertext"><span class="BDFDB-containerarrow closed"></span>Notification Sound Settings</div><div class="BDFDB-collapsecontainer"> ` ;
2019-10-09 14:18:28 +02:00
for ( let config in notificationsounds ) if ( config . 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 . horizontal + 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 . titlesize12 + BDFDB . disCNS . height16 + BDFDB . disCNS . weightsemibold + BDFDB . disCNS . h5defaultmargin } " style="flex: 1 1 auto;"> ${ config } notification sound:</h5><h5 class=" ${ BDFDB . disCNS . flexchild + BDFDB . disCNS . h5 + BDFDB . disCNS . title + BDFDB . disCNS . titlesize12 + 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" config=" ${ config } " class=" ${ BDFDB . disCNS . switchinnerenabled + BDFDB . disCN . switchinner } mute-checkbox" ${ notificationsounds [ config ] . mute ? " checked" : "" } ></div></div><div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCN . nowrap } " style="flex: 1 1 auto;"><div class=" ${ BDFDB . disCNS . inputwrapper + BDFDB . disCNS . vertical + BDFDB . disCNS . flex2 + BDFDB . disCN . flexchild } " style="flex: 1 1 auto;"><input type="text" config=" ${ config } " value=" ${ notificationsounds [ config ] . url ? notificationsounds [ config ] . url : "" } " placeholder="Url or Filepath" class=" ${ BDFDB . disCNS . inputdefault + BDFDB . disCNS . input + BDFDB . disCN . titlesize16 } "></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" 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> ` ;
2019-08-22 16:17:21 +02:00
settingshtml += ` </div> ` ;
2018-10-11 10:21:26 +02:00
settingshtml += ` </div></div> ` ;
2019-09-04 12:34:02 +02:00
2019-10-22 19:49:57 +02:00
BDFDB . DataUtils . save ( friends , this , "friends" ) ;
BDFDB . DataUtils . save ( nonfriends , this , "nonfriends" ) ;
2019-01-26 22:45:19 +01:00
2019-10-23 11:10:01 +02:00
let settingspanel = BDFDB . DOMUtils . create ( 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-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , settingspanel , "keyup" , ".input-notificationstring" , e => { this . saveNotificationString ( e . currentTarget ) ; } ) ;
BDFDB . ListenerUtils . add ( this , settingspanel , "click" , ".btn-savesong" , e => { this . saveNotificationSound ( e . currentTarget . parentElement . querySelector ( BDFDB . dotCN . input ) ) ; } ) ;
BDFDB . ListenerUtils . add ( this , settingspanel , "click" , ".mute-checkbox" , e => {
2019-08-28 10:06:31 +02:00
let config = e . currentTarget . getAttribute ( "config" ) ;
if ( config ) {
2019-10-22 20:16:05 +02:00
let notificationsound = BDFDB . DataUtils . get ( this , "notificationsounds" , config ) ;
2019-08-28 10:06:31 +02:00
notificationsound . mute = e . currentTarget . checked ;
2019-10-22 20:16:05 +02:00
BDFDB . DataUtils . save ( notificationsound , this , "notificationsounds" , config ) ;
2019-08-28 10:06:31 +02:00
}
2019-01-17 23:48:29 +01:00
} ) ;
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , settingspanel , "click" , ".settings-avatar" , e => {
2019-10-23 11:10:01 +02:00
this . changeNotificationType ( e . currentTarget , false , ! BDFDB . DOMUtils . containsClass ( e . currentTarget , "disabled" , "desktop" , false ) ) ;
2019-01-17 23:48:29 +01:00
} ) ;
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , settingspanel , "contextmenu" , ".settings-avatar" , e => {
2019-01-17 23:48:29 +01:00
if ( ! ( "Notification" in window ) ) return ;
2019-10-23 11:10:01 +02:00
this . changeNotificationType ( e . currentTarget , true , ! ( BDFDB . DOMUtils . containsClass ( e . currentTarget , "disabled" ) || ! BDFDB . DOMUtils . containsClass ( e . currentTarget , "desktop" ) ) ) ;
2019-01-17 23:48:29 +01:00
} ) ;
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , settingspanel , "click" , ".btn-batch" , e => {
2019-08-22 16:17:21 +02:00
this . changeAllNotificationTypes ( settingspanel , e . currentTarget , true ) ;
} ) ;
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , settingspanel , "contextmenu" , ".btn-batch" , e => {
2019-08-22 16:17:21 +02:00
this . changeAllNotificationTypes ( settingspanel , e . currentTarget , false ) ;
} ) ;
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , settingspanel , "click" , BDFDB . dotCN . checkboxinput , e => {
2019-10-23 11:10:01 +02:00
if ( BDFDB . DOMUtils . containsClass ( e . target , "remove-user" ) ) return ;
2019-08-22 16:17:21 +02:00
this . changeNotificationConfig ( e . currentTarget ) ;
} ) ;
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , settingspanel , "click" , ".BDFDB-tableheadercolumn" , e => {
2019-08-22 16:17:21 +02:00
this . changeAllNotificationConfigs ( settingspanel , e . currentTarget , true ) ;
} ) ;
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , settingspanel , "contextmenu" , ".BDFDB-tableheadercolumn" , e => {
2019-08-22 16:17:21 +02:00
this . changeAllNotificationConfigs ( settingspanel , e . currentTarget , false ) ;
} ) ;
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , settingspanel , "click" , ".remove-user" , e => {
2019-01-17 23:48:29 +01:00
let id = e . currentTarget . getAttribute ( "user-id" ) ;
2019-08-22 16:17:21 +02:00
let group = e . currentTarget . getAttribute ( "group" ) ;
if ( id && group ) {
2019-10-22 20:16:05 +02:00
BDFDB . DataUtils . remove ( this , group , id ) ;
2019-10-23 11:10:01 +02:00
BDFDB . DOMUtils . remove ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . hovercard , e . currentTarget ) ) ;
2019-08-22 22:39:09 +02:00
this . SettingsUpdated = true ;
2019-08-22 16:17:21 +02:00
}
2019-01-17 23:48:29 +01:00
} ) ;
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , settingspanel , "click" , ".btn-adduser" , e => {
2019-08-22 16:17:21 +02:00
let idinput = settingspanel . querySelector ( "#input-userid" ) ;
let id = idinput . value ;
idinput . value = "" ;
2019-10-22 18:55:25 +02:00
if ( friendIDs . includes ( id ) ) BDFDB . NotificationUtils . toast ( "User is already a friend of yours. Please use the 'Friends' area to configure him/her." , { type : "error" } ) ;
2019-11-23 20:43:17 +01:00
else if ( BDFDB . DataUtils . load ( this , "nonfriends" , id ) ) BDFDB . NotificationUtils . toast ( "User is already being observed as a 'Non-Friend'." , { type : "error" } ) ;
2019-08-22 16:17:21 +02:00
else {
2019-09-11 12:14:43 +02:00
let user = BDFDB . LibraryModules . UserStore . getUser ( id ) ;
2019-08-22 16:17:21 +02:00
if ( user ) {
let data = this . createDefaultConfig ( ) ;
2019-10-22 20:16:05 +02:00
BDFDB . DataUtils . save ( data , this , "nonfriends" , user . id ) ;
2019-10-23 11:10:01 +02:00
let hovercard = BDFDB . DOMUtils . create ( this . createHoverCard ( user , data , "nonfriends" ) ) ;
2019-08-22 16:17:21 +02:00
settingspanel . querySelector ( ".nonfriend-list" ) . appendChild ( hovercard ) ;
BDFDB . initElements ( hovercard ) ;
2019-08-22 22:39:09 +02:00
this . SettingsUpdated = true ;
2019-08-22 16:17:21 +02:00
}
2019-10-22 18:55:25 +02:00
else if ( /.+#[0-9]{4}/ . test ( id ) ) BDFDB . NotificationUtils . toast ( "A UserID does not consist of the username and discriminator." , { type : "error" } ) ;
else BDFDB . NotificationUtils . toast ( "Please enter a valid UserID of a user that has been loaded in your client." , { type : "error" } ) ;
2019-08-22 16:17:21 +02:00
}
2019-01-17 23:48:29 +01:00
} ) ;
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( 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" ) ;
2019-10-18 10:56:41 +02:00
libraryScript . setAttribute ( "src" , "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.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
}
else if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) this . initialize ( ) ;
2019-11-01 10:27:07 +01:00
this . startTimeout = setTimeout ( ( ) => {
try { return this . initialize ( ) ; }
catch ( err ) { console . error ( ` %c[ ${ this . getName ( ) } ]%c ` , "color: #3a71c1; font-weight: 700;" , "" , "Fatal Error: Could not initiate plugin! " + err ) ; }
} , 30000 ) ;
2018-10-11 10:21:26 +02:00
}
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 ;
2019-10-22 18:55:25 +02:00
BDFDB . PluginUtils . init ( this ) ;
2019-01-26 22:45:19 +01:00
2019-05-01 21:02:25 +02:00
this . startInterval ( ) ;
2019-10-22 18:55:25 +02:00
BDFDB . ModuleUtils . forceAllUpdates ( this ) ;
2018-10-11 10:21:26 +02:00
}
2019-11-01 10:14:50 +01:00
else 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-10-22 11:37:23 +02:00
this . stopping = true ;
2019-11-01 11:09:32 +01:00
BDFDB . TimeUtils . clear ( this . checkInterval ) ;
2019-10-22 18:55:25 +02:00
BDFDB . PluginUtils . clear ( this ) ;
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
// begin of own functions
2019-09-04 12:34:02 +02:00
2019-08-22 16:17:21 +02:00
createHoverCard ( user , data , group ) {
2019-10-22 20:16:05 +02:00
let EUdata = BDFDB . DataUtils . load ( "EditUsers" , "users" , user . id ) || { } ;
2019-10-23 11:10:01 +02:00
var hovercardhtml = ` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . vertical + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCNS . margintop4 + BDFDB . disCNS . marginbottom4 + BDFDB . disCN . hovercard } "><div class=" ${ BDFDB . disCN . hovercardinner } "><div class="settings-avatar ${ data . desktop ? " desktop" : "" } ${ data . disabled ? " disabled" : "" } " group=" ${ group } " user-id=" ${ user . id } " style="flex: 0 0 auto; background-image: url( ${ EUdata . removeIcon ? "" : ( EUdata . url ? EUdata . url : BDFDB . UserUtils . getAvatar ( user . id ) ) } );"></div><div class="BDFDB-textscrollwrapper" style="flex: 1 1 auto;"><div class="BDFDB-textscroll"> ${ BDFDB . StringUtils . htmlEscape ( EUdata . name || user . username ) } </div></div> ` ;
2019-08-27 13:07:48 +02:00
for ( let config in this . defaults . notificationstrings ) {
2019-09-18 10:19:56 +02:00
hovercardhtml += ` <div class=" ${ BDFDB . disCNS . checkboxcontainer + BDFDB . disCN . marginreset } BDFDB-tablecheckbox" table-id=" ${ group } " style="flex: 0 0 auto;"><label class=" ${ BDFDB . disCN . checkboxwrapper } "><input user-id=" ${ user . id } " group=" ${ group } " config=" ${ config } " type="checkbox" class=" ${ BDFDB . disCN . checkboxinputdefault } " ${ data [ config ] ? " checked" : "" } ><div class=" ${ BDFDB . disCNS . checkbox + BDFDB . disCNS . flexcenter + BDFDB . disCNS . flex2 + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCN . checkboxround } "><svg name="Checkmark" width="18" height="18" viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><polyline stroke="transparent" stroke-width="2" points="3.5 9.5 7 13 15 5"></polyline></g></svg></div></label></div> ` ;
2019-08-22 16:17:21 +02:00
}
return hovercardhtml + ` </div> ${ group == "nonfriends" ? ` <div class=" ${ BDFDB . disCN . hovercardbutton } remove-user" group=" ${ group } " user-id=" ${ user . id } "></div> ` : '' } </div> `
}
2019-09-04 12:34:02 +02:00
2019-08-22 16:17:21 +02:00
changeNotificationType ( avatar , desktopon , disableon ) {
let id = avatar . getAttribute ( "user-id" ) ;
let group = avatar . getAttribute ( "group" ) ;
if ( id && group ) {
2019-10-22 20:23:43 +02:00
let data = BDFDB . DataUtils . load ( this , group , id ) || this . createDefaultConfig ( ) ;
2019-08-22 16:17:21 +02:00
data . desktop = desktopon ;
data . disabled = disableon ;
2019-10-23 11:10:01 +02:00
BDFDB . DOMUtils . toggleClass ( avatar , "desktop" , desktopon ) ;
BDFDB . DOMUtils . toggleClass ( avatar , "disabled" , disableon ) ;
2019-10-22 20:16:05 +02:00
BDFDB . DataUtils . save ( data , this , group , id ) ;
2019-08-22 22:39:09 +02:00
this . SettingsUpdated = true ;
2019-08-22 16:17:21 +02:00
}
}
2019-09-04 12:34:02 +02:00
2019-08-22 16:17:21 +02:00
changeAllNotificationTypes ( settingspanel , tableheader , enable ) {
let config = tableheader . getAttribute ( "config" ) ;
let group = tableheader . getAttribute ( "group" ) ;
if ( config && group ) {
2019-10-22 19:49:57 +02:00
let data = BDFDB . DataUtils . load ( this , group ) ;
2019-08-22 16:17:21 +02:00
if ( config == "desktop" ) {
enable = ! enable ;
for ( let id in data ) data [ id ] . disabled = false ;
2019-10-23 11:10:01 +02:00
for ( let avatar of settingspanel . querySelectorAll ( ` .settings-avatar[group=" ${ group } "] ` ) ) BDFDB . DOMUtils . removeClass ( avatar , "disabled" ) ;
2019-08-22 16:17:21 +02:00
}
for ( let id in data ) data [ id ] [ config ] = enable ;
2019-10-23 11:10:01 +02:00
for ( let avatar of settingspanel . querySelectorAll ( ` .settings-avatar[group=" ${ group } "] ` ) ) BDFDB . DOMUtils . toggleClass ( avatar , config , enable ) ;
2019-10-22 19:49:57 +02:00
BDFDB . DataUtils . save ( data , this , group ) ;
2019-08-22 22:39:09 +02:00
this . SettingsUpdated = true ;
2019-08-22 16:17:21 +02:00
}
}
2019-09-04 12:34:02 +02:00
2019-08-22 16:17:21 +02:00
changeNotificationConfig ( checkbox ) {
let id = checkbox . getAttribute ( "user-id" ) ;
let config = checkbox . getAttribute ( "config" ) ;
let group = checkbox . getAttribute ( "group" ) ;
if ( id && config && group ) {
2019-10-22 20:23:43 +02:00
let data = BDFDB . DataUtils . load ( this , group , id ) || this . createDefaultConfig ( ) ;
2019-08-22 16:17:21 +02:00
data [ config ] = checkbox . checked ;
2019-10-22 20:16:05 +02:00
BDFDB . DataUtils . save ( data , this , group , id ) ;
2019-08-22 22:39:09 +02:00
this . SettingsUpdated = true ;
2019-08-22 16:17:21 +02:00
}
}
2019-09-04 12:34:02 +02:00
2019-08-22 16:17:21 +02:00
changeAllNotificationConfigs ( settingspanel , tableheader , enable ) {
let config = tableheader . getAttribute ( "config" ) ;
let group = tableheader . getAttribute ( "group" ) ;
if ( config && group ) {
2019-10-22 19:49:57 +02:00
let data = BDFDB . DataUtils . load ( this , group ) ;
2019-08-22 16:17:21 +02:00
for ( let id in data ) data [ id ] [ config ] = enable ;
2019-10-22 19:49:57 +02:00
BDFDB . DataUtils . save ( data , this , group ) ;
2019-08-22 16:17:21 +02:00
for ( let checkbox of settingspanel . querySelectorAll ( ` ${ BDFDB . dotCN . checkboxinput } [config=" ${ config } "][group=" ${ group } "] ` ) ) {
checkbox . checked = enable ;
if ( typeof checkbox . BDFDBupdateElement == "function" ) checkbox . BDFDBupdateElement ( ) ;
}
2019-08-22 22:39:09 +02:00
this . SettingsUpdated = true ;
2019-08-22 16:17:21 +02:00
}
}
2019-09-04 12:34:02 +02:00
2019-08-22 16:17:21 +02:00
createDefaultConfig ( ) {
2019-10-22 23:04:58 +02:00
return Object . assign ( { desktop : false , disabled : BDFDB . DataUtils . get ( this , "settings" , "disableForNew" ) } , BDFDB . ObjectUtils . map ( this . defaults . notificationstrings , "init" ) ) ;
2019-08-27 13:07:48 +02:00
}
2019-09-04 12:34:02 +02:00
2019-08-27 13:07:48 +02:00
saveNotificationString ( input ) {
let config = input . getAttribute ( "config" ) ;
if ( config ) {
2019-10-22 20:16:05 +02:00
BDFDB . DataUtils . save ( input . value , this , "notificationstrings" , config ) ;
2019-08-27 13:07:48 +02:00
this . SettingsUpdated = true ;
}
2019-08-22 16:17:21 +02:00
}
2019-01-26 22:45:19 +01:00
2019-08-27 13:07:48 +02:00
saveNotificationSound ( input ) {
let config = input . getAttribute ( "config" ) ;
if ( config ) {
let successSavedAudio = ( parsedurl , parseddata ) => {
2019-10-22 18:55:25 +02:00
if ( parsedurl && parseddata ) BDFDB . NotificationUtils . toast ( ` Sound was saved successfully. ` , { type : "success" } ) ;
2019-10-22 20:16:05 +02:00
let notificationsound = BDFDB . DataUtils . get ( this , "notificationsounds" , config ) ;
2019-08-27 13:07:48 +02:00
notificationsound . url = parsedurl ;
notificationsound . song = parseddata ;
2019-10-22 20:16:05 +02:00
BDFDB . DataUtils . save ( notificationsound , this , "notificationsounds" , config ) ;
2019-08-27 13:07:48 +02:00
this . SettingsUpdated = true ;
} ;
2019-01-26 22:45:19 +01:00
2019-08-27 13:07:48 +02:00
let url = input . value ;
if ( url . length == 0 ) {
2019-10-22 18:55:25 +02:00
BDFDB . NotificationUtils . toast ( ` Sound file was removed. ` , { type : "warn" } ) ;
2019-08-27 13:07:48 +02:00
successSavedAudio ( url , url ) ;
}
else if ( url . indexOf ( "http" ) == 0 ) {
2019-09-11 12:14:43 +02:00
BDFDB . LibraryRequires . request ( url , ( error , response , result ) => {
2019-08-27 13:07:48 +02:00
if ( response ) {
let type = response . headers [ "content-type" ] ;
if ( type && ( type . indexOf ( "octet-stream" ) > - 1 || type . indexOf ( "audio" ) > - 1 || type . indexOf ( "video" ) > - 1 ) ) {
successSavedAudio ( url , url ) ;
return ;
}
2018-10-11 10:21:26 +02:00
}
2019-10-22 18:55:25 +02:00
BDFDB . NotificationUtils . toast ( "Use a valid direct link to a video or audio source. They usually end on something like .mp3, .mp4 or .wav." , { type : "danger" } ) ;
2019-08-27 13:07:48 +02:00
} ) ;
}
else {
2019-09-11 12:14:43 +02:00
BDFDB . LibraryRequires . fs . readFile ( url , ( error , response ) => {
2019-10-22 18:55:25 +02:00
if ( error ) BDFDB . NotificationUtils . toast ( "Could not fetch file. Please make sure the file exists." , { type : "danger" } ) ;
2019-08-27 13:07:48 +02:00
else successSavedAudio ( url , ` data:audio/mpeg;base64, ${ response . toString ( "base64" ) } ` ) ;
} ) ;
}
2019-01-03 10:20:41 +01:00
}
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
processStandardSidebarView ( instance , wrapper , returnvalue ) {
2019-08-22 16:17:21 +02:00
if ( this . SettingsUpdated ) {
delete this . SettingsUpdated ;
this . startInterval ( ) ;
}
2019-05-01 21:02:25 +02:00
}
2019-09-04 12:34:02 +02:00
2019-09-19 16:02:12 +02:00
getStatusWithMobileAndActivity ( id , config ) {
2019-10-22 18:55:25 +02:00
let statusname = BDFDB . UserUtils . getStatus ( id ) ;
2019-09-19 16:02:12 +02:00
let status = { statusname , isactivity : false } ;
2019-11-01 11:32:38 +01:00
let activity = BDFDB . UserUtils . getActivitiy ( id ) ;
2019-09-19 16:02:12 +02:00
if ( activity && this . activityTypes [ activity . type ] ) {
let activityname = this . activityTypes [ activity . type ] . toLowerCase ( ) ;
if ( this . defaults . notificationstrings [ activityname ] && config [ activityname ] ) {
status = Object . assign ( { statusname : activityname , isactivity : true } , activity ) ;
2019-10-04 12:02:26 +02:00
if ( activityname == "listening" || activityname == "streaming" ) delete status . name ;
2019-09-19 16:02:12 +02:00
}
}
if ( status . statusname == "online" && BDFDB . LibraryModules . StatusMetaUtils . isMobileOnline ( id ) ) status . statusname = "mobile" ;
return status ;
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 ( ) {
2019-11-01 11:09:32 +01:00
BDFDB . TimeUtils . clear ( this . checkInterval ) ;
2019-10-22 19:49:57 +02:00
let settings = BDFDB . DataUtils . get ( this , "settings" ) ;
let amounts = BDFDB . DataUtils . get ( this , "amounts" ) ;
let notificationstrings = BDFDB . DataUtils . get ( this , "notificationstrings" ) ;
let notificationsounds = BDFDB . DataUtils . get ( this , "notificationsounds" ) ;
let users = Object . assign ( { } , BDFDB . DataUtils . load ( this , "nonfriends" ) , BDFDB . DataUtils . load ( this , "friends" ) ) ;
2019-09-19 19:32:29 +02:00
for ( let id in users ) this . userStatusStore [ id ] = this . getStatusWithMobileAndActivity ( id , users [ id ] ) . statusname ;
2019-10-02 12:53:51 +02:00
let toasttime = ( amounts . toastTime > amounts . checkInterval ? amounts . checkInterval : amounts . toastTime ) * 1000 ;
let desktoptime = ( amounts . desktopTime > amounts . checkInterval ? amounts . checkInterval : amounts . desktopTime ) * 1000 ;
2019-11-01 11:09:32 +01:00
this . checkInterval = BDFDB . TimeUtils . interval ( ( ) => {
2019-08-22 16:17:21 +02:00
for ( let id in users ) if ( ! users [ id ] . disabled ) {
2019-09-11 12:14:43 +02:00
let user = BDFDB . LibraryModules . UserStore . getUser ( id ) ;
2019-09-19 16:02:12 +02:00
let status = this . getStatusWithMobileAndActivity ( id , users [ id ] ) ;
if ( user && this . userStatusStore [ id ] != status . statusname && users [ id ] [ status . statusname ] ) {
2019-10-22 20:16:05 +02:00
let EUdata = BDFDB . DataUtils . load ( "EditUsers" , "users" , user . id ) || { } ;
2019-10-19 11:41:39 +02:00
let libstring = ( this . defaults . notificationstrings [ status . statusname ] . libstring ? BDFDB . LanguageUtils . LanguageStrings [ this . defaults . notificationstrings [ status . statusname ] . libstring ] : ( this . defaults . notificationstrings [ status . statusname ] . statusname || "" ) ) . toLowerCase ( ) ;
2019-09-19 16:02:12 +02:00
let string = notificationstrings [ status . statusname ] || "$user changed status to $status" ;
2019-10-23 11:10:01 +02:00
let toaststring = BDFDB . StringUtils . htmlEscape ( string ) . replace ( /'{0,1}\$user'{0,1}/g , ` <strong> ${ BDFDB . StringUtils . htmlEscape ( EUdata . name || user . username ) } </strong> ` ) . replace ( /'{0,1}\$status'{0,1}/g , ` <strong> ${ libstring } </strong> ` ) ;
2019-10-04 12:02:26 +02:00
if ( status . isactivity ) toaststring = toaststring . replace ( /'{0,1}\$song'{0,1}|'{0,1}\$game'{0,1}/g , ` <strong> ${ status . name || status . details } </strong> ` ) . replace ( /'{0,1}\$artist'{0,1}/g , ` <strong> ${ status . state } </strong> ` ) ;
2019-10-22 18:55:25 +02:00
let avatar = EUdata . removeIcon ? "" : ( EUdata . url ? EUdata . url : BDFDB . UserUtils . getAvatar ( user . id ) ) ;
2019-08-27 13:07:48 +02:00
this . timeLog . push ( { string : toaststring , avatar , time : new Date ( ) } ) ;
2019-10-22 18:55:25 +02:00
if ( ! ( settings . muteOnDND && BDFDB . UserUtils . getStatus ( ) == "dnd" ) ) {
2019-08-22 16:17:21 +02:00
let openChannel = ( ) => {
if ( settings . openOnClick ) {
2019-10-22 23:04:58 +02:00
let DMid = BDFDB . LibraryModules . ChannelStore . getDMFromUserId ( user . id )
2019-09-11 12:14:43 +02:00
if ( DMid ) BDFDB . LibraryModules . SelectChannelUtils . selectPrivateChannel ( DMid ) ;
2019-10-22 18:55:25 +02:00
else BDFDB . LibraryModules . DirectMessageUtils . openPrivateChannel ( BDFDB . UserUtils . me . id , user . id ) ;
2019-09-11 12:14:43 +02:00
BDFDB . LibraryRequires . electron . remote . getCurrentWindow ( ) . maximize ( ) ;
2019-08-22 16:17:21 +02:00
}
} ;
if ( ! users [ id ] . desktop ) {
2019-10-02 12:53:51 +02:00
if ( ! document . querySelector ( ` .friendnotifications- ${ id } -toast ` ) ) {
2019-10-22 18:55:25 +02:00
let toast = BDFDB . NotificationUtils . toast ( ` <div class="toast-inner"><div class="toast-avatar" style="background-image:url( ${ avatar } );"></div><div> ${ toaststring } </div></div> ` , { html : true , timeout : toasttime , color : BDFDB . UserUtils . getStatusColor ( status . statusname ) , icon : false , selector : ` friendnotifications- ${ status . statusname } -toast friendnotifications- ${ id } -toast ` } ) ;
2019-10-02 12:53:51 +02:00
toast . addEventListener ( "click" , openChannel ) ;
let notificationsound = notificationsounds [ "toast" + status . statusname ] || { } ;
if ( ! notificationsound . mute && notificationsound . song ) {
let audio = new Audio ( ) ;
audio . src = notificationsound . song ;
audio . play ( ) ;
}
2019-08-22 16:17:21 +02:00
}
}
else {
2019-08-27 13:07:48 +02:00
let desktopstring = string . replace ( /\$user/g , EUdata . name || user . username ) . replace ( /\$status/g , libstring ) ;
2019-09-19 16:02:12 +02:00
if ( status . isactivity ) desktopstring = desktopstring . replace ( /\$song|\$game/g , status . name || status . details ) . replace ( /\$artist/g , status . state ) ;
let notificationsound = notificationsounds [ "desktop" + status . statusname ] || { } ;
2019-10-22 18:55:25 +02:00
BDFDB . NotificationUtils . desktop ( desktopstring , { icon : avatar , timeout : desktoptime , click : openChannel , silent : notificationsound . mute , sound : notificationsound . song } ) ;
2019-08-22 16:17:21 +02:00
}
}
}
2019-09-19 16:02:12 +02:00
this . userStatusStore [ id ] = status . statusname ;
2019-05-01 21:02:25 +02:00
}
2019-10-02 12:53:51 +02:00
} , amounts . checkInterval * 1000 ) ;
2019-05-01 21:02:25 +02:00
}
2019-01-17 23:48:29 +01:00
showTimeLog ( ) {
2019-10-23 11:10:01 +02:00
let timeLogModal = BDFDB . DOMUtils . create ( this . timeLogModalMarkup ) ;
2019-01-17 23:48:29 +01:00
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-10-23 11:10:01 +02:00
if ( container . childElementCount ) container . appendChild ( BDFDB . DOMUtils . create ( ` <div class=" ${ BDFDB . disCNS . divider + BDFDB . disCN . marginbottom4 } "></div> ` ) ) ;
let entry = BDFDB . DOMUtils . create ( this . logEntryMarkup ) ;
2019-01-17 23:48:29 +01:00
entry . querySelector ( ".log-time" ) . innerText = ` [ ${ log . time . toLocaleTimeString ( ) } ] ` ;
2019-08-23 09:40:07 +02:00
entry . querySelector ( ".log-avatar" ) . style . setProperty ( "background-image" , ` url( ${ log . avatar } ) ` ) ;
2019-08-26 21:02:35 +02:00
entry . querySelector ( ".log-description" ) . innerHTML = log . string ;
2019-10-22 23:04:58 +02:00
container . appendChild ( entry )
2018-10-11 10:21:26 +02:00
}
BDFDB . appendModal ( timeLogModal ) ;
}
}