2021-01-09 20:54:44 +01:00
/ * *
* @ name CustomStatusPresets
* @ authorId 278543574059057154
* @ invite Jx3TjNS
* @ donate https : //www.paypal.me/MircoWittrien
* @ patreon https : //www.patreon.com/MircoWittrien
* @ website https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/CustomStatusPresets
* @ source https : //raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/CustomStatusPresets/CustomStatusPresets.plugin.js
* @ updateUrl https : //raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/CustomStatusPresets/CustomStatusPresets.plugin.js
* /
module . exports = ( _ => {
const config = {
"info" : {
"name" : "CustomStatusPresets" ,
"author" : "DevilBro" ,
2021-01-09 23:17:20 +01:00
"version" : "1.0.4" ,
2021-01-09 20:54:44 +01:00
"description" : "Allows you to save custom statuses as quick select"
2021-01-09 22:07:56 +01:00
} ,
"changeLog" : {
"fixed" : {
2021-01-09 23:17:20 +01:00
"First Bugs" : "All bugs in the first test phase should be fixed" ,
"Server Emotes" : "Properly shows server emotes in the context menu now" ,
"Textless Statuses" : "Now also works with textless statuses"
2021-01-09 22:07:56 +01:00
}
2021-01-09 20:54:44 +01:00
}
} ;
return ! window . BDFDB _Global || ( ! window . BDFDB _Global . loaded && ! window . BDFDB _Global . started ) ? class {
getName ( ) { return config . info . name ; }
getAuthor ( ) { return config . info . author ; }
getVersion ( ) { return config . info . version ; }
2021-01-14 16:14:44 +01:00
getDescription ( ) { return ` The Library Plugin needed for ${ config . info . name } is missing. Open the Plugin Settings to download it. \n \n ${ config . info . description } ` ; }
2021-01-09 20:54:44 +01:00
load ( ) {
if ( ! window . BDFDB _Global || ! Array . isArray ( window . BDFDB _Global . pluginQueue ) ) window . BDFDB _Global = Object . assign ( { } , window . BDFDB _Global , { pluginQueue : [ ] } ) ;
if ( ! window . BDFDB _Global . downloadModal ) {
window . BDFDB _Global . downloadModal = true ;
2021-01-14 16:14:44 +01:00
BdApi . showConfirmationModal ( "Library Missing" , ` The Library Plugin needed for ${ config . info . name } is missing. Please click "Download Now" to install it. ` , {
2021-01-09 20:54:44 +01:00
confirmText : "Download Now" ,
cancelText : "Cancel" ,
onCancel : _ => { delete window . BDFDB _Global . downloadModal ; } ,
onConfirm : _ => {
delete window . BDFDB _Global . downloadModal ;
require ( "request" ) . get ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" , ( e , r , b ) => {
if ( ! e && b && b . indexOf ( ` * @name BDFDB ` ) > - 1 ) require ( "fs" ) . writeFile ( require ( "path" ) . join ( BdApi . Plugins . folder , "0BDFDB.plugin.js" ) , b , _ => { } ) ;
2021-01-14 16:14:44 +01:00
else BdApi . alert ( "Error" , "Could not download BDFDB Library Plugin, try again later or download it manually from GitHub: https://github.com/mwittrien/BetterDiscordAddons/tree/master/Library/" ) ;
2021-01-09 20:54:44 +01:00
} ) ;
}
} ) ;
}
if ( ! window . BDFDB _Global . pluginQueue . includes ( config . info . name ) ) window . BDFDB _Global . pluginQueue . push ( config . info . name ) ;
}
start ( ) { this . load ( ) ; }
stop ( ) { }
getSettingsPanel ( ) {
let template = document . createElement ( "template" ) ;
2021-01-14 16:14:44 +01:00
template . innerHTML = ` <div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${ config . info . name } is missing. \n Please click <a style="font-weight: 500;">Download Now</a> to install it.</div> ` ;
2021-01-09 20:54:44 +01:00
template . content . firstElementChild . querySelector ( "a" ) . addEventListener ( "click" , _ => {
require ( "request" ) . get ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" , ( e , r , b ) => {
if ( ! e && b && b . indexOf ( ` * @name BDFDB ` ) > - 1 ) require ( "fs" ) . writeFile ( require ( "path" ) . join ( BdApi . Plugins . folder , "0BDFDB.plugin.js" ) , b , _ => { } ) ;
2021-01-14 16:14:44 +01:00
else BdApi . alert ( "Error" , "Could not download BDFDB Library Plugin, try again later or download it manually from GitHub: https://github.com/mwittrien/BetterDiscordAddons/tree/master/Library/" ) ;
2021-01-09 20:54:44 +01:00
} ) ;
} ) ;
return template . content . firstElementChild ;
}
} : ( ( [ Plugin , BDFDB ] ) => {
var presets = { } ;
return class CustomStatusPresets extends Plugin {
onLoad ( ) {
this . patchedModules = {
before : {
Menu : "default"
} ,
after : {
Account : "render" ,
CustomStatusModal : "render"
}
} ;
this . css = `
$ { BDFDB . dotCN . customstatusmodal } {
min - width : 440 px ;
width : unset ;
}
$ { BDFDB . dotCN . animationcontainerscale + BDFDB . dotCN . animationcontainerrender } {
transform : unset ! important ;
}
# status - picker$ { BDFDB . dotCN . menu } # status - picker - custom - status$ { BDFDB . dotCN . menulabelcontainer } {
padding : 0 ;
}
# status - picker$ { BDFDB . dotCN . menu } # status - picker - custom - status $ { BDFDB . dotCN . menulabel } {
overflow : visible ;
white - space : unset ;
}
# status - picker$ { BDFDB . dotCN . menu } # status - picker - custom - status $ { BDFDB . dotCN . customstatusitemcustom } ,
# status - picker$ { BDFDB . dotCN . menu } # status - picker - custom - status $ { BDFDB . dotCN . customstatusitemcustomwithemoji } {
display : flex ;
padding - right : 0 ;
padding - left : 0 ;
}
# status - picker$ { BDFDB . dotCN . menu } # status - picker - custom - status $ { BDFDB . dotCNS . customstatusitemcustomwithemoji + BDFDB . dotCN . customstatusitememoji } {
margin - left : 4 px ;
order : 3 ;
}
# status - picker$ { BDFDB . dotCN . menu } # status - picker - custom - status $ { BDFDB . dotCN . customstatusitemcustomtext } {
flex : 1 1 auto ;
max - width : 126 px ;
overflow : hidden ;
order : 2 ;
}
# status - picker$ { BDFDB . dotCN . menu } # status - picker - custom - status $ { BDFDB . dotCN . customstatusitemclearbutton } {
margin - right : 10 px ;
margin - left : 2 px ;
order : 1 ;
}
$ { BDFDB . dotCN . _customstatuspresetscustomstatusitem } {
display : flex ;
align - items : center ;
}
$ { BDFDB . dotCN . _customstatuspresetsdeletebutton } {
display : flex ;
margin - right : 6 px ;
}
` ;
}
onStart ( ) {
this . forceUpdateAll ( ) ;
}
onStop ( ) {
this . forceUpdateAll ( ) ;
}
forceUpdateAll ( ) {
presets = BDFDB . DataUtils . load ( this , "presets" ) ;
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
}
processMenu ( e ) {
if ( e . instance . props . navId == "status-picker" && Object . keys ( presets ) . length ) {
let [ children , index ] = BDFDB . ContextMenuUtils . findItem ( e . instance , { id : "custom-status" } ) ;
if ( index > - 1 && children [ index ] . props && ! children [ index ] . props . children ) {
let render = children [ index ] . props . render ;
delete children [ index ] . props . render ;
children [ index ] = BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , Object . assign ( { } , children [ index ] . props , {
label : render ( ) ,
children : Object . keys ( BDFDB . ObjectUtils . sort ( presets , "pos" ) ) . map ( key => BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "custom-status-preset" , key ) ,
label : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . _customstatuspresetscustomstatusitem ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , {
text : BDFDB . LanguageUtils . LanguageStrings . CUSTOM _STATUS _CLEAR _CUSTOM _STATUS ,
tooltipConfig : {
zIndex : 2001
} ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Clickable , {
className : BDFDB . disCN . _customstatuspresetsdeletebutton ,
onClick : _ => {
delete presets [ key ] ;
let pos = 0 , sortedPresets = BDFDB . ObjectUtils . sort ( presets , "pos" ) ;
for ( let key in sortedPresets ) presets [ key ] . pos = pos ++ ;
BDFDB . DataUtils . save ( presets , this , "presets" ) ;
} ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . _customstatuspresetsdeleteicon ,
name : BDFDB . LibraryComponents . SvgIcon . Names . CLOSE _CIRCLE ,
width : 14 ,
height : 14
} )
} )
} ) ,
presets [ key ] . text
]
} ) ,
2021-01-09 22:48:15 +01:00
imageUrl : presets [ key ] . emojiInfo && ( presets [ key ] . emojiInfo . id ? BDFDB . LibraryModules . IconUtils . getEmojiURL ( presets [ key ] . emojiInfo ) : BDFDB . LibraryModules . EmojiStateUtils . getURL ( presets [ key ] . emojiInfo . name ) ) ,
2021-01-09 21:51:38 +01:00
hint : ! presets [ key ] . clearAfter ? BDFDB . LanguageUtils . LanguageStrings . DISPLAY _OPTION _NEVER : presets [ key ] . clearAfter == BDFDB . LibraryModules . CustomStatusConstants . ClearAfterValues . TODAY ? BDFDB . LanguageUtils . LanguageStrings . CUSTOM _STATUS _TODAY : BDFDB . LanguageUtils . LanguageStringsFormat ( "CUSTOM_STATUS_HOURS" , presets [ key ] . clearAfter / 3600000 ) ,
2021-01-09 20:54:44 +01:00
action : _ => {
if ( ! presets [ key ] ) return ;
let expiresAt = presets [ key ] . clearAfter ? presets [ key ] . clearAfter : null ;
2021-01-09 21:51:38 +01:00
if ( presets [ key ] . clearAfter === BDFDB . LibraryModules . CustomStatusConstants . ClearAfterValues . TODAY ) {
2021-01-09 20:54:44 +01:00
let date = new Date ;
expiresAt = new Date ( date . getFullYear ( ) , date . getMonth ( ) , date . getDate ( ) + 1 ) . getTime ( ) - date . getTime ( ) ;
}
BDFDB . LibraryModules . SettingsUtils . updateRemoteSettings ( {
customStatus : {
2021-01-09 23:17:20 +01:00
text : presets [ key ] . text && presets [ key ] . text . length > 0 ? presets [ key ] . text : null ,
2021-01-09 22:07:56 +01:00
expiresAt : expiresAt ? BDFDB . DiscordObjects . Timestamp ( ) . add ( expiresAt , "ms" ) . toISOString ( ) : null ,
2021-01-09 20:54:44 +01:00
emojiId : presets [ key ] . emojiInfo ? presets [ key ] . emojiInfo . id : null ,
emojiName : presets [ key ] . emojiInfo ? presets [ key ] . emojiInfo . name : null
}
} ) ;
}
} ) )
} ) ) ;
}
}
}
processCustomStatusModal ( e ) {
let id = BDFDB . NumberUtils . generateId ( Object . keys ( presets ) ) ;
let footer = BDFDB . ReactUtils . findChild ( e . returnvalue , { name : [ "ModalFooter" , "Footer" ] } ) ;
if ( footer ) footer . props . children . splice ( 1 , 0 , BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Button , {
color : BDFDB . disCN . modalcancelbutton ,
look : BDFDB . LibraryComponents . Button . Looks . LINK ,
onClick : event => {
presets [ id ] = Object . assign ( { pos : Object . keys ( presets ) . length } , BDFDB . ObjectUtils . extract ( e . instance . state , "clearAfter" , "emojiInfo" , "text" ) ) ;
BDFDB . DataUtils . save ( presets , this , "presets" ) ;
if ( ! event . shiftKey ) e . instance . props . onClose ( ) ;
else id = BDFDB . NumberUtils . generateId ( Object . keys ( presets ) ) ;
} ,
children : this . labels . modal _savepreset
} ) ) ;
}
setLabelsByLanguage ( ) {
switch ( BDFDB . LanguageUtils . getLanguage ( ) . id ) {
case "bg" : // Bulgarian
return {
modal _savepreset : "Запазване като бърз избор"
} ;
case "da" : // Danish
return {
modal _savepreset : "Gem som hurtigvalg"
} ;
case "de" : // German
return {
modal _savepreset : "Als Schnellauswahl speichern"
} ;
case "el" : // Greek
return {
modal _savepreset : "Αποθήκευση ως γρήγορη επιλογή"
} ;
case "es" : // Spanish
return {
modal _savepreset : "Guardar como selección rápida"
} ;
case "fi" : // Finnish
return {
modal _savepreset : "Tallenna pikavalintana"
} ;
case "fr" : // French
return {
modal _savepreset : "Enregistrer en tant que sélection rapide"
} ;
case "hr" : // Croatian
return {
modal _savepreset : "Spremi kao brzi odabir"
} ;
case "hu" : // Hungarian
return {
modal _savepreset : "Mentés gyorsválasztásként"
} ;
case "it" : // Italian
return {
modal _savepreset : "Salva come selezione rapida"
} ;
case "ja" : // Japanese
return {
modal _savepreset : "クイック選択として保存"
} ;
case "ko" : // Korean
return {
modal _savepreset : "빠른 선택으로 저장"
} ;
case "lt" : // Lithuanian
return {
modal _savepreset : "Išsaugoti kaip greitą pasirinkimą"
} ;
case "nl" : // Dutch
return {
modal _savepreset : "Opslaan als snel selecteren"
} ;
case "no" : // Norwegian
return {
modal _savepreset : "Lagre som hurtigvalg"
} ;
case "pl" : // Polish
return {
modal _savepreset : "Zapisz jako Szybki wybór"
} ;
case "pt-BR" : // Portuguese (Brazil)
return {
modal _savepreset : "Salvar como seleção rápida"
} ;
case "ro" : // Romanian
return {
modal _savepreset : "Salvați ca selecție rapidă"
} ;
case "ru" : // Russian
return {
modal _savepreset : "Сохранить как быстрый выбор"
} ;
case "sv" : // Swedish
return {
modal _savepreset : "Spara som snabbval"
} ;
case "th" : // Thai
return {
modal _savepreset : "บันทึกเป็น เลือกด่วน"
} ;
case "tr" : // Turkish
return {
modal _savepreset : "Hı zlı Seçim olarak kaydet"
} ;
case "uk" : // Ukrainian
return {
modal _savepreset : "Зберегти як швидкий вибір"
} ;
case "vi" : // Vietnamese
return {
modal _savepreset : "Lưu dưới dạng Chọn nhanh"
} ;
2021-01-15 17:54:22 +01:00
case "zh-CN" : // Chinese (China)
2021-01-09 20:54:44 +01:00
return {
modal _savepreset : "另存为快速选择"
} ;
2021-01-15 17:54:22 +01:00
case "zh-TW" : // Chinese (Taiwan)
2021-01-09 20:54:44 +01:00
return {
modal _savepreset : "另存為快速選擇"
} ;
default : // English
return {
modal _savepreset : "Save as Quick Select"
} ;
}
}
} ;
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( config ) ) ;
} ) ( ) ;