2019-09-20 22:32:52 +02:00
//META{"name":"MessageUtilities","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/MessageUtilities","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/MessageUtilities/MessageUtilities.plugin.js"}*//
2018-10-11 10:21:26 +02:00
class MessageUtilities {
2019-01-17 23:48:29 +01:00
getName ( ) { return "MessageUtilities" ; }
2019-10-22 16:17:48 +02:00
getVersion ( ) { return "1.5.9" ; }
2019-01-17 23:48:29 +01:00
getAuthor ( ) { return "DevilBro" ; }
getDescription ( ) { return "Offers a number of useful message options. Remap the keybindings in the settings." ; }
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
constructor ( ) {
2019-09-28 10:27:59 +02:00
this . patchModules = {
"MessageContextMenu" : [ "componentDidMount" , "componentDidUpdate" ]
2019-02-28 17:07:39 +01:00
} ;
2019-09-04 12:34:02 +02:00
}
initConstructor ( ) {
2018-10-11 10:21:26 +02:00
this . bindings = { } ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . firedEvents = [ ] ;
2019-01-26 22:45:19 +01:00
2018-12-29 11:32:07 +01:00
this . clickMap = [ "CLICK" /*[0]*/ , "DBLCLICK" /*[1]*/ ] ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . keyboardMap = [
"NONE" /*[0]*/ , "" /*[1]*/ , "" /*[2]*/ , "CANCEL" /*[3]*/ , "" /*[4]*/ , "" /*[5]*/ , "HELP" /*[6]*/ , "" /*[7]*/ , "BACK_SPACE" /*[8]*/ , "TAB" /*[9]*/ , "" /*[10]*/ , "" /*[11]*/ , "CLEAR" /*[12]*/ , "ENTER" /*[13]*/ , "ENTER_SPECIAL" /*[14]*/ , "" /*[15]*/ , "SHIFT" /*[16]*/ , "CONTROL" /*[17]*/ , "ALT" /*[18]*/ , "PAUSE" /*[19]*/ , "CAPS_LOCK" /*[20]*/ , "KANA" /*[21]*/ , "EISU" /*[22]*/ , "JUNJA" /*[23]*/ , "FINAL" /*[24]*/ , "HANJA" /*[25]*/ , "" /*[26]*/ , "ESCAPE" /*[27]*/ , "CONVERT" /*[28]*/ , "NONCONVERT" /*[29]*/ , "ACCEPT" /*[30]*/ , "MODECHANGE" /*[31]*/ , "SPACE" /*[32]*/ , "PAGE_UP" /*[33]*/ , "PAGE_DOWN" /*[34]*/ , "END" /*[35]*/ , "HOME" /*[36]*/ , "LEFT" /*[37]*/ , "UP" /*[38]*/ , "RIGHT" /*[39]*/ , "DOWN" /*[40]*/ , "SELECT" /*[41]*/ , "PRINT" /*[42]*/ , "EXECUTE" /*[43]*/ , "PRINTSCREEN" /*[44]*/ , "INSERT" /*[45]*/ , "DELETE" /*[46]*/ , "" /*[47]*/ , "0" /*[48]*/ , "1" /*[49]*/ , "2" /*[50]*/ , "3" /*[51]*/ , "4" /*[52]*/ , "5" /*[53]*/ , "6" /*[54]*/ , "7" /*[55]*/ , "8" /*[56]*/ , "9" /*[57]*/ , "COLON" /*[58]*/ , "SEMICOLON" /*[59]*/ , "LESS_THAN" /*[60]*/ , "EQUALS" /*[61]*/ , "GREATER_THAN" /*[62]*/ , "QUESTION_MARK" /*[63]*/ , "AT" /*[64]*/ , "A" /*[65]*/ , "B" /*[66]*/ , "C" /*[67]*/ , "D" /*[68]*/ , "E" /*[69]*/ , "F" /*[70]*/ , "G" /*[71]*/ , "H" /*[72]*/ , "I" /*[73]*/ , "J" /*[74]*/ , "K" /*[75]*/ , "L" /*[76]*/ , "M" /*[77]*/ , "N" /*[78]*/ , "O" /*[79]*/ , "P" /*[80]*/ , "Q" /*[81]*/ , "R" /*[82]*/ , "S" /*[83]*/ , "T" /*[84]*/ , "U" /*[85]*/ , "V" /*[86]*/ , "W" /*[87]*/ , "X" /*[88]*/ , "Y" /*[89]*/ , "Z" /*[90]*/ , "OS_KEY" /*[91]*/ , "" /*[92]*/ , "CONTEXT_MENU" /*[93]*/ , "" /*[94]*/ , "SLEEP" /*[95]*/ , "NUMPAD0" /*[96]*/ , "NUMPAD1" /*[97]*/ , "NUMPAD2" /*[98]*/ , "NUMPAD3" /*[99]*/ , "NUMPAD4" /*[100]*/ , "NUMPAD5" /*[101]*/ , "NUMPAD6" /*[102]*/ , "NUMPAD7" /*[103]*/ , "NUMPAD8" /*[104]*/ , "NUMPAD9" /*[105]*/ , "MULTIPLY" /*[106]*/ , "ADD" /*[107]*/ , "SEPARATOR" /*[108]*/ , "SUBTRACT" /*[109]*/ , "DECIMAL" /*[110]*/ , "DIVIDE" /*[111]*/ , "F1" /*[112]*/ , "F2" /*[113]*/ , "F3" /*[114]*/ , "F4" /*[115]*/ , "F5" /*[116]*/ , "F6" /*[117]*/ , "F7" /*[118]*/ , "F8" /*[119]*/ , "F9" /*[120]*/ , "F10" /*[121]*/ , "F11" /*[122]*/ , "F12" /*[123]*/ , "F13" /*[124]*/ , "F14" /*[125]*/ , "F15" /*[126]*/ , "F16" /*[127]*/ , "F17" /*[128]*/ , "F18" /*[129]*/ , "F19" /*[130]*/ , "F20" /*[131]*/ , "F21" /*[132]*/ , "F22" /*[133]*/ , "F23" /*[134]*/ , "F24" /*[135]*/ , "" /*[136]*/ , "" /*[137]*/ , "" /*[138]*/ , "" /*[139]*/ , "" /*[140]*/ , "" /*[141]*/ , "" /*[142]*/ , "" /*[143]*/ , "NUM_LOCK" /*[144]*/ , "SCROLL_LOCK" /*[145]*/ , "WIN_OEM_FJ_JISHO" /*[146]*/ , "WIN_OEM_FJ_MASSHOU" /*[147]*/ , "WIN_OEM_FJ_TOUROKU" /*[148]*/ , "WIN_OEM_FJ_LOYA" /*[149]*/ , "WIN_OEM_FJ_ROYA" /*[150]*/ , "" /*[151]*/ , "" /*[152]*/ , "" /*[153]*/ , "" /*[154]*/ , "" /*[155]*/ , "" /*[156]*/ , "" /*[157]*/ , "" /*[158]*/ , "" /*[159]*/ , "CIRCUMFLEX" /*[160]*/ , "EXCLAMATION" /*[161]*/ , "DOUBLE_QUOTE" /*[162]*/ , "HASH" /*[163]*/ , "DOLLAR" /*[164]*/ , "PERCENT" /*[165]*/ , "AMPERSAND" /*[166]*/ , "UNDERSCORE" /*[167]*/ , "OPEN_PAREN" /*[168]*/ , "CLOSE_PAREN" /*[169]*/ , "ASTERISK" /*[170]*/ , "PLUS" /*[171]*/ , "PIPE" /*[172]*/ , "HYPHEN_MINUS" /*[173]*/ , "OPEN_CURLY_BRACKET" /*[174]*/ , "CLOSE_CURLY_BRACKET" /*[175]*/ , "TILDE" /*[176]*/ , "" /*[177]*/ , "" /*[178]*/ , "" /*[179]*/ , "" /*[180]*/ , "VOLUME_MUTE" /*[181]*/ , "VOLUME_DOWN" /*[182]*/ , "VOLUME_UP" /*[183]*/ , "" /*[184]*/ , "" /*[185]*/ , "SEMICOLON" /*[186]*/ , "EQUALS" /*[187]*/ , "COMMA" /*[188]*/ , "MINUS" /*[189]*/ , "PERIOD" /*[190]*/ , "SLASH" /*[191]*/ , "BACK_QUOTE" /*[192]*/ , "" /*[193]*/ , "" /*[194]*/ , "" /*[195]*/ , "" /*[196]*/ , "" /*[197]*/ , "" /*[198]*/ , "" /*[199]*/ , "" /*[200]*/ , "" /*[201]*/ , "" /*[202]*/ , "" /*[203]*/ , "" /*[204]*/ , "" /*[205]*/ , "" /*[206]*/ , "" /*[207]*/ , "" /*[208]*/ , "" /*[209]*/ , "" /*[210]*/ , "" /*[211]*/ , "" /*[212]*/ , "" /*[213]*/ , "" /*[214]*/ , "" /*[215]*/ , "" /*[216]*/ , "" /*[217]*/ , "" /*[218]*/ , "OPEN_BRACKET" /*[219]*/ , "BACK_SLASH" /*[220]*/ , "CLOSE_BRACKET" /*[221]*/ , "QUOTE" /*[222]*/ , "" /*[223]*/ , "META" /*[224]*/ , "ALTGR" /*[225]*/ , "" /*[226]*/ , "WIN_ICO_HELP" /*[227]*/ , "WIN_ICO_00" /*[228]*/ , "" /*[229]*/ , "WIN_ICO_CLEAR" /*[230]*/ , "" /*[231]*/ , "" /*[232]*/ , " WIN _O
] ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . keys = [ "key1" , "key2" ] ;
this . defaults = {
settings : {
2019-09-28 10:27:59 +02:00
"addHints" : { value : true , description : "Add keycombo hints to contextmenus:" } ,
2019-09-26 20:09:46 +02:00
"clearOnEscape" : { value : true , description : "Clear chat input when Escape is pressed:" }
2018-10-11 10:21:26 +02:00
} ,
2019-09-26 20:09:46 +02:00
toasts : { } ,
2018-10-11 10:21:26 +02:00
bindings : {
"Edit_Message" : { name : "Edit Message" , func : this . doEdit , value : { click : 1 , key1 : 0 , key2 : 0 } } ,
"Delete_Message" : { name : "Delete Message" , func : this . doDelete , value : { click : 0 , key1 : 46 , key2 : 0 } } ,
"Pin/Unpin_Message" : { name : "Pin/Unpin Message" , func : this . doPinUnPin , value : { click : 0 , key1 : 17 , key2 : 0 } } ,
2019-09-26 16:18:55 +02:00
"React_to_Message" : { name : "React to Message" , func : this . doOpenReact , value : { click : 0 , key1 : 17 , key2 : 83 } } ,
"Copy_Raw" : { name : "Copy raw Message" , func : this . doCopyRaw , value : { click : 0 , key1 : 17 , key2 : 68 } } ,
"Copy_Link" : { name : "Copy Message Link" , func : this . doCopyLink , value : { click : 0 , key1 : 17 , key2 : 81 } } ,
2019-01-17 23:48:29 +01:00
"__Note_Message" : { name : "Note Message (Pesonal Pins)" , func : this . doNote , value : { click : 0 , key1 : 16 , key2 : 0 } , plugin : "PersonalPins" } ,
"__Translate_Message" : { name : "Translate Message (Google Translate Option)" , func : this . doTranslate , value : { click : 0 , key1 : 20 , key2 : 0 } , plugin : "GoogleTranslateOption" } ,
2019-09-26 16:18:55 +02:00
"__Quote_Message" : { name : "Quote Message (Quoter)" , func : this . doQuote , value : { click : 0 , key1 : 17 , key2 : 87 } , plugin : "Quoter" } ,
"__Citate_Message" : { name : "Quote Message (Citador)" , func : this . doCitate , value : { click : 0 , key1 : 17 , key2 : 78 } , plugin : "Citador" } ,
2019-09-26 20:09:46 +02:00
"__Reveal_Spoilers" : { name : "Reveal All Spoilers (RevealAllSpoilersOption)" , func : this . doReveal , value : { click : 0 , key1 : 17 , key2 : 74 } , plugin : "RevealAllSpoilersOption" }
2018-10-11 10:21:26 +02:00
}
} ;
2019-09-26 20:09:46 +02:00
for ( let type in this . defaults . bindings ) {
let nativeaction = type . indexOf ( "__" ) != 0 ;
this . defaults . settings [ type ] = { value : nativeaction } ;
if ( nativeaction ) this . defaults . toasts [ type ] = { value : type != "Edit_Message" && type != "React_to_Message" } ;
}
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-10-22 19:49:57 +02:00
let settings = BDFDB . DataUtils . get ( this , "settings" ) ;
let toasts = BDFDB . DataUtils . get ( this , "toasts" ) ;
let bindings = BDFDB . DataUtils . get ( this , "bindings" ) ;
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"> ` ;
2018-10-11 10:21:26 +02:00
for ( let key in settings ) {
2019-10-09 14:18:28 +02:00
if ( this . defaults . settings [ key ] . description ) 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> ` ;
2018-10-11 10:21:26 +02:00
}
for ( let action in bindings ) {
2019-10-23 11:10:01 +02:00
if ( ! this . defaults . bindings [ action ] . plugin || BDFDB . BDUtils . isPluginEnabled ( this . defaults . bindings [ action ] . plugin ) ) {
2019-10-15 11:46:37 +02:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . divider + BDFDB . disCN . marginbottom4 } "></div> ` ;
2019-10-09 14:18:28 +02:00
settingshtml += ` <div class=" ${ action } -key-settings"><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 . bindings [ action ] . name } :</h3> ${ toasts [ action ] != undefined ? ` <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;">Toast:</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" value="toasts ${ action } " class=" ${ BDFDB . disCNS . switchinnerenabled + BDFDB . disCN . switchinner } settings-switch" ${ toasts [ action ] ? " checked" : "" } ></div> ` : '' } <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;">Enabled:</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" value="settings ${ action } " class=" ${ BDFDB . disCNS . switchinnerenabled + BDFDB . disCN . switchinner } settings-switch" ${ settings [ action ] ? " checked" : "" } ></div></div><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;"> ` ;
settingshtml += ` <div class=" ${ BDFDB . disCN . flexchild } " style="flex: 1 1 20%;"><h5 class=" ${ BDFDB . disCNS . h5 + BDFDB . disCNS . title + BDFDB . disCNS . titlesize12 + BDFDB . disCNS . height16 + BDFDB . disCNS . weightsemibold + BDFDB . disCNS . h5defaultmargin + BDFDB . disCN . marginbottom4 } ">Click:</h5> ${ BDFDB . createSelectMenu ( this . createSelectChoice ( bindings [ action ] . click ) , bindings [ action ] . click , action + " click" ) } </div> ` ;
2019-01-17 23:48:29 +01:00
for ( let key of this . keys ) {
2019-10-19 11:41:39 +02:00
settingshtml += ` <div class=" ${ BDFDB . disCN . flexchild } " style="flex: 1 1 40%;"><h5 class=" ${ BDFDB . disCNS . h5 + BDFDB . disCNS . title + BDFDB . disCNS . titlesize12 + BDFDB . disCNS . height16 + BDFDB . disCNS . weightsemibold + BDFDB . disCNS . h5defaultmargin + BDFDB . disCN . marginbottom4 } "> ${ key } :<label class="reset-recorder" style="float: right; padding-right: 5px; cursor: pointer;">✖</label></h5><div type=" ${ action } " option=" ${ key } " value=" ${ bindings [ action ] [ key ] } " class=" ${ BDFDB . disCNS . hotkeycontainer + BDFDB . disCNS . hotkeycontainer2 + BDFDB . disCN . hotkeyhasvalue } "><div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . alignstretch + BDFDB . disCNS . nowrap + BDFDB . disCNS . hotkeylayout + BDFDB . disCN . hotkeylayout2 } " style="flex: 1 1 auto;"><input type="text" placeholder=" ${ this . keyboardMap [ bindings [ action ] [ key ] ] } " readonly="" value=" ${ this . keyboardMap [ bindings [ action ] [ key ] ] } " class=" ${ BDFDB . disCNS . hotkeyinput + BDFDB . disCNS . hotkeyinput2 + BDFDB . disCN . hotkeybase } " style="flex: 1 1 auto;"></input><div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . horizontal + BDFDB . disCNS . justifystart + BDFDB . disCNS . alignstretch + BDFDB . disCN . nowrap } " style="flex: 0 1 auto; margin: 0px;"><button type="button" class=" ${ BDFDB . disCNS . hotkeybutton + BDFDB . disCNS . hotkeybutton2 + BDFDB . disCNS . button + BDFDB . disCNS . buttonlookghost + BDFDB . disCNS . buttoncolorgrey + BDFDB . disCNS . buttonsizemin + BDFDB . disCN . buttongrow } "><div class=" ${ BDFDB . disCN . buttoncontents } "><span class=" ${ BDFDB . disCN . hotkeytext } "> ${ BDFDB . LanguageUtils . LanguageStrings . SHORTCUT _RECORDER _BUTTON _EDIT } </span><span class=" ${ BDFDB . disCN . hotkeyediticon } "/></div></button></div></div></div></div> ` ;
2019-01-17 23:48:29 +01:00
}
settingshtml += ` </div></div> ` ;
2018-10-11 10:21:26 +02:00
}
}
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;">Reset all key bindings.</h3><button type="button" class=" ${ BDFDB . disCNS . flexchild + BDFDB . disCNS . button + BDFDB . disCNS . buttonlookfilled + BDFDB . disCNS . buttoncolorred + BDFDB . disCNS . buttonsizemedium + BDFDB . disCN . buttongrow } reset-button" style="flex: 0 0 auto;"><div class=" ${ BDFDB . disCN . buttoncontents } ">Reset</div></button></div> ` ;
2018-10-11 10:21:26 +02:00
settingshtml += ` </div></div> ` ;
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 ) ;
2019-01-26 22:45:19 +01:00
2019-10-22 19:49:57 +02:00
BDFDB . ListenerUtils . add ( this , settingspanel , "click" , BDFDB . dotCN . hotkeycontainer , e => { this . startRecording ( settingspanel , e ) ; } ) ;
BDFDB . ListenerUtils . add ( this , settingspanel , "click" , ".reset-recorder" , e => { this . resetRecorder ( settingspanel , e ) ; } ) ;
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , settingspanel , "click" , ".reset-button" , ( ) => { this . resetAll ( settingspanel ) ; } ) ;
BDFDB . ListenerUtils . add ( this , settingspanel , "click" , BDFDB . dotCN . selectcontrol , e => {
2019-09-24 12:48:53 +02:00
BDFDB . openDropdownMenu ( e , this . saveSelectChoice . bind ( this ) , this . createSelectChoice . bind ( this ) , this . clickMap ) ;
2019-04-27 18:45:01 +02:00
} ) ;
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-01-17 23:48:29 +01: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-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , document , "click" , BDFDB . dotCN . messagegroup + "> [aria-disabled]," + BDFDB . dotCN . messagegroup + "> * > [aria-disabled]," + BDFDB . dotCN . messagesystem , e => {
2019-09-28 10:27:59 +02:00
this . onClick ( e , 0 , "onSglClick" ) ;
2019-01-17 23:48:29 +01:00
} )
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , document , "dblclick" , BDFDB . dotCN . messagegroup + "> [aria-disabled]," + BDFDB . dotCN . messagegroup + "> * > [aria-disabled]," + BDFDB . dotCN . messagesystem , e => {
2019-09-28 10:27:59 +02:00
this . onClick ( e , 1 , "onDblClick" ) ;
2019-01-17 23:48:29 +01:00
} ) ;
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , document , "keydown" , BDFDB . dotCN . textareawrapchat , e => {
2019-09-28 10:27:59 +02:00
this . onKeyDown ( e , e . which , "onKeyDown" ) ;
2019-01-17 23:48:29 +01:00
} ) ;
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-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-28 10:27:59 +02:00
processMessageContextMenu ( instance , menu , returnvalue ) {
if ( instance . props && instance . props . message && instance . props . channel && instance . props . target ) {
let changed = false ;
for ( let itemlabel of menu . querySelectorAll ( BDFDB . dotCN . contextmenulabel ) ) {
2019-09-30 09:16:14 +02:00
let hint = itemlabel . parentElement . querySelector ( BDFDB . dotCN . contextmenuhint ) ;
2019-10-23 11:10:01 +02:00
if ( hint && ! BDFDB . DOMUtils . containsClass ( hint , "BDFDB-contextMenuItemHint" ) ) {
2019-09-30 09:16:14 +02:00
let action = null ;
switch ( itemlabel . innerText ) {
2019-10-19 11:41:39 +02:00
case BDFDB . LanguageUtils . LanguageStrings . COPY _MESSAGE _LINK :
2019-09-30 09:16:14 +02:00
action = "Copy_Link" ;
break ;
2019-10-19 11:41:39 +02:00
case BDFDB . LanguageUtils . LanguageStrings . EDIT _MESSAGE :
2019-09-30 09:16:14 +02:00
action = "Edit_Message" ;
break ;
2019-10-19 11:41:39 +02:00
case BDFDB . LanguageUtils . LanguageStrings . PIN _MESSAGE :
case BDFDB . LanguageUtils . LanguageStrings . UNPIN _MESSAGE :
2019-09-30 09:16:14 +02:00
action = "Pin/Unpin_Message" ;
break ;
2019-10-19 11:41:39 +02:00
case BDFDB . LanguageUtils . LanguageStrings . DELETE _MESSAGE :
2019-09-30 09:16:14 +02:00
action = "Delete_Message" ;
break ;
}
if ( action ) {
let hintlabel = this . getActiveShortcutString ( action ) ;
if ( hintlabel ) {
2019-10-22 16:17:48 +02:00
hint . style . setProperty ( "width" , "42px" ) ;
hint . style . setProperty ( "max-width" , "42px" ) ;
hint . style . setProperty ( "margin-left" , "8px" ) ;
BDFDB . ReactUtils . render ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextScroller , { speed : 2 , children : hintlabel } ) , hint ) ;
2019-09-30 09:16:14 +02:00
}
2019-09-28 10:27:59 +02:00
}
}
}
if ( changed ) BDFDB . initElements ( menu ) ;
}
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
resetAll ( settingspanel ) {
2019-10-30 13:27:14 +01:00
BDFDB . ModalUtils . confirm ( this , "Are you sure you want to delete all key bindings?" , ( ) => {
2019-10-22 19:49:57 +02:00
BDFDB . DataUtils . remove ( this , "bindings" ) ;
let bindings = BDFDB . DataUtils . get ( this , "bindings" ) ;
2019-09-15 10:21:32 +02:00
settingspanel . querySelectorAll ( BDFDB . dotCN . select ) . forEach ( wrap => {
let type = wrap . getAttribute ( "type" ) . split ( " " ) ;
wrap . setAttribute ( "value" , bindings [ type [ 0 ] ] [ type [ 1 ] ] ) ;
wrap . querySelector ( BDFDB . dotCN . title ) . innerText = this . clickMap [ bindings [ type [ 0 ] ] [ type [ 1 ] ] ] ;
2018-10-11 10:21:26 +02:00
} ) ;
2019-09-15 10:21:32 +02:00
settingspanel . querySelectorAll ( BDFDB . dotCN . hotkeycontainer ) . forEach ( wrap => {
2019-01-03 00:35:05 +01:00
let action = wrap . getAttribute ( "type" ) ;
let option = wrap . getAttribute ( "option" ) ;
2018-10-11 10:21:26 +02:00
wrap . setAttribute ( "value" , bindings [ action ] [ option ] ) ;
wrap . querySelector ( "input" ) . setAttribute ( "value" , this . keyboardMap [ bindings [ action ] [ option ] ] ) ;
2019-01-03 00:35:05 +01:00
} ) ;
2019-01-06 23:37:28 +01:00
} ) ;
2018-10-11 10:21:26 +02:00
}
2019-09-04 12:34:02 +02:00
2019-04-27 18:45:01 +02:00
saveSelectChoice ( selectWrap , type , choice ) {
if ( type && choice ) {
selectWrap . querySelector ( BDFDB . dotCN . title ) . innerText = this . clickMap [ choice ] ;
type = type . split ( " " ) ;
2019-10-22 20:16:05 +02:00
let binding = BDFDB . DataUtils . get ( this , "bindings" , type [ 0 ] ) ;
2019-04-27 18:45:01 +02:00
binding [ type [ 1 ] ] = parseInt ( choice ) ;
2019-10-22 20:16:05 +02:00
BDFDB . DataUtils . save ( binding , this , "bindings" , type [ 0 ] ) ;
2018-10-11 10:21:26 +02:00
}
2019-04-27 18:45:01 +02:00
}
2019-09-04 12:34:02 +02:00
2019-04-27 18:45:01 +02:00
createSelectChoice ( key ) {
2019-09-11 12:14:43 +02:00
return ` <div class=" ${ BDFDB . disCNS . title + BDFDB . disCNS . medium + BDFDB . disCNS . primary + BDFDB . disCNS . weightnormal + BDFDB . disCN . cursorpointer } " style="padding: 0;"> ${ this . clickMap [ key ] } </div> ` ;
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
startRecording ( settingspanel , e ) {
2019-01-03 00:35:05 +01:00
let recorderWrap = e . currentTarget ;
2019-10-23 11:10:01 +02:00
if ( BDFDB . DOMUtils . containsClass ( recorderWrap , BDFDB . disCN . hotkeyrecording ) ) return ;
2019-01-26 22:45:19 +01:00
2019-01-03 00:35:05 +01:00
let recorderInput = recorderWrap . querySelector ( "input" ) ;
let recorderText = recorderWrap . querySelector ( BDFDB . dotCN . hotkeytext ) ;
let action = recorderWrap . getAttribute ( "type" ) ;
let option = recorderWrap . getAttribute ( "option" ) ;
2019-01-26 22:45:19 +01:00
2019-10-23 11:10:01 +02:00
BDFDB . DOMUtils . addClass ( recorderWrap , BDFDB . disCN . hotkeyrecording ) ;
BDFDB . DOMUtils . removeClass ( recorderWrap , BDFDB . disCN . hotkeyhasvalue ) ;
2019-10-19 11:41:39 +02:00
recorderText . innerText = BDFDB . LanguageUtils . LanguageStrings . SHORTCUT _RECORDER _BUTTON _RECORDING ;
2019-01-26 22:45:19 +01:00
2019-01-17 23:48:29 +01:00
var saveRecording = e => {
2018-10-11 10:21:26 +02:00
recorderWrap . setAttribute ( "value" , e . which ) ;
recorderInput . setAttribute ( "value" , this . keyboardMap [ e . which ] ) ;
2019-01-17 23:48:29 +01:00
} ;
2019-01-26 22:45:19 +01:00
2019-01-17 23:48:29 +01:00
var stopRecording = e => {
document . removeEventListener ( "mousedown" , stopRecording ) ;
document . removeEventListener ( "keydown" , saveRecording ) ;
2019-10-22 20:16:05 +02:00
let binding = BDFDB . DataUtils . get ( this , "bindings" , action ) ;
2018-10-11 10:21:26 +02:00
binding [ option ] = parseInt ( recorderWrap . getAttribute ( "value" ) ) ;
2019-10-22 20:16:05 +02:00
BDFDB . DataUtils . save ( binding , this , "bindings" , action ) ;
2019-11-01 11:09:32 +01:00
BDFDB . TimeUtils . timeout ( ( ) => {
2019-10-23 11:10:01 +02:00
BDFDB . DOMUtils . removeClass ( recorderWrap , BDFDB . disCN . hotkeyrecording ) ;
BDFDB . DOMUtils . addClass ( recorderWrap , BDFDB . disCN . hotkeyhasvalue ) ;
2019-10-19 11:41:39 +02:00
recorderText . innerText = BDFDB . LanguageUtils . LanguageStrings . SHORTCUT _RECORDER _BUTTON _EDIT ;
2018-10-11 10:21:26 +02:00
} , 100 ) ;
2019-01-17 23:48:29 +01:00
} ;
2019-01-26 22:45:19 +01:00
2019-01-17 23:48:29 +01:00
document . addEventListener ( "mousedown" , stopRecording ) ;
document . addEventListener ( "keydown" , saveRecording ) ;
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
resetRecorder ( settingspanel , e ) {
2019-01-03 00:35:05 +01:00
let resetButton = e . currentTarget ;
let recorderWrap = e . currentTarget . parentElement . parentElement . querySelector ( BDFDB . dotCN . hotkeycontainer ) ;
let recorderInput = recorderWrap . querySelector ( "input" ) ;
let action = recorderWrap . getAttribute ( "type" ) ;
let option = recorderWrap . getAttribute ( "option" ) ;
2018-10-11 10:21:26 +02:00
recorderWrap . setAttribute ( "value" , 0 ) ;
recorderInput . setAttribute ( "value" , this . keyboardMap [ 0 ] ) ;
2019-10-22 20:16:05 +02:00
let binding = BDFDB . DataUtils . get ( this , "bindings" , action ) ;
2018-10-11 10:21:26 +02:00
binding [ option ] = parseInt ( recorderWrap . getAttribute ( "value" ) ) ;
2019-10-22 20:16:05 +02:00
BDFDB . DataUtils . save ( binding , this , "bindings" , action ) ;
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2019-09-28 10:27:59 +02:00
onClick ( e , click , name ) {
2018-10-11 10:21:26 +02:00
if ( ! this . isEventFired ( name ) ) {
this . fireEvent ( name ) ;
2019-10-22 19:49:57 +02:00
let settings = BDFDB . DataUtils . get ( this , "settings" ) ;
let bindings = BDFDB . ObjectUtils . filter ( BDFDB . DataUtils . get ( this , "bindings" ) , action => { return settings [ action ] } , true ) ;
2019-09-27 08:36:43 +02:00
let priorityaction = null ;
for ( let action in bindings ) {
2019-09-26 16:18:55 +02:00
let binding = bindings [ action ] ;
2019-09-27 08:36:43 +02:00
let prioritybinding = bindings [ priorityaction ] ;
2019-09-28 10:27:59 +02:00
if ( this . checkIfBindingIsValid ( binding , click ) && ( ! bindings [ priorityaction ] || binding . click > prioritybinding . click || binding . key2 != 0 && prioritybinding . key2 == 0 ) ) priorityaction = action ;
2019-09-26 16:18:55 +02:00
}
if ( priorityaction ) {
let { messagediv , pos , message } = this . getMessageData ( e . currentTarget ) ;
if ( messagediv && pos > - 1 && message ) {
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . stopEvent ( e ) ;
2019-11-01 11:09:32 +01:00
BDFDB . TimeUtils . clear ( this . clickTimeout ) ;
2019-09-28 10:27:59 +02:00
if ( ! this . hasDoubleClickOverwrite ( bindings , bindings [ priorityaction ] ) ) {
this . defaults . bindings [ priorityaction ] . func . bind ( this ) ( { messagediv , pos , message } , priorityaction ) ;
}
2019-11-01 11:09:32 +01:00
else this . clickTimeout = BDFDB . TimeUtils . timeout ( ( ) => {
2019-09-28 10:27:59 +02:00
this . defaults . bindings [ priorityaction ] . func . bind ( this ) ( { messagediv , pos , message } , priorityaction ) ;
} , 500 ) ;
2018-10-11 10:21:26 +02:00
}
}
this . cancelEvent ( name ) ;
}
}
2019-01-26 22:45:19 +01:00
2019-09-28 10:27:59 +02:00
checkIfBindingIsValid ( binding , doneclick ) {
2019-01-03 00:35:05 +01:00
let valid = true ;
2019-09-28 10:27:59 +02:00
if ( binding . click != doneclick ) valid = false ;
for ( let key of this . keys ) if ( ! BDFDB . pressedKeys . includes ( binding [ key ] ) && binding [ key ] != 0 ) valid = false ;
2018-10-11 10:21:26 +02:00
return valid ;
}
2019-01-26 22:45:19 +01:00
2019-09-28 10:27:59 +02:00
hasDoubleClickOverwrite ( bindings , binding ) {
if ( binding . click == 1 ) return false ;
2019-10-22 18:55:25 +02:00
let dblbindings = BDFDB . ObjectUtils . filter ( bindings , bndg => { return bndg . click == 1 } ) ;
2019-09-28 10:27:59 +02:00
for ( let dblaction in dblbindings ) {
let dblbndg = dblbindings [ dblaction ] ;
let overwrite = true ;
for ( let key of this . keys ) if ( binding [ key ] != dblbndg [ key ] ) overwrite = false ;
if ( overwrite ) return true ;
}
return false ;
}
2019-09-26 20:09:46 +02:00
doDelete ( { messagediv , pos , message } , action ) {
2019-03-01 21:25:48 +01:00
let deletelink = messagediv . parentElement . querySelector ( BDFDB . dotCNS . messagelocalbotmessage + BDFDB . dotCN . anchor ) ;
if ( deletelink ) deletelink . click ( ) ;
else {
2019-09-11 12:14:43 +02:00
let channel = BDFDB . LibraryModules . ChannelStore . getChannel ( message . channel _id ) ;
2019-10-22 18:55:25 +02:00
if ( ( channel && BDFDB . UserUtils . can ( "MANAGE_MESSAGES" ) ) || message . author . id == BDFDB . UserUtils . me . id && message . type != 1 && message . type != 2 && message . type != 3 ) {
2019-09-11 12:14:43 +02:00
BDFDB . LibraryModules . MessageUtils . deleteMessage ( message . channel _id , message . id , message . state != "SENT" ) ;
2019-10-22 23:04:35 +02:00
if ( BDFDB . DataUtils . get ( this , "toasts" , action ) ) BDFDB . NotificationUtils . toast ( "Message has been deleted." , { type : "success" } ) ;
2019-03-01 21:25:48 +01:00
}
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2019-09-26 20:09:46 +02:00
doEdit ( { messagediv , pos , message } , action ) {
2019-10-22 18:55:25 +02:00
if ( message . author . id == BDFDB . UserUtils . me . id && ! messagediv . querySelector ( "textarea" ) ) {
2019-09-11 12:14:43 +02:00
BDFDB . LibraryModules . MessageUtils . startEditMessage ( message . channel _id , message . id , message . content ) ;
2019-10-22 23:04:35 +02:00
if ( BDFDB . DataUtils . get ( this , "toasts" , action ) ) BDFDB . NotificationUtils . toast ( "Started editing." , { type : "success" } ) ;
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2019-09-26 20:09:46 +02:00
doOpenReact ( { messagediv , pos , message } , action ) {
2019-01-03 00:35:05 +01:00
let reactButton = messagediv . querySelector ( BDFDB . dotCN . emojipickerbutton ) ;
2019-09-26 20:09:46 +02:00
if ( reactButton ) {
reactButton . click ( ) ;
2019-10-22 23:04:35 +02:00
if ( BDFDB . DataUtils . get ( this , "toasts" , action ) ) BDFDB . NotificationUtils . toast ( "Reaction popout has been opened." , { type : "success" } ) ;
2019-09-26 20:09:46 +02:00
}
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2019-09-26 20:09:46 +02:00
doPinUnPin ( { messagediv , pos , message } , action ) {
2019-03-01 21:25:48 +01:00
if ( message . state == "SENT" ) {
2019-09-11 12:14:43 +02:00
let channel = BDFDB . LibraryModules . ChannelStore . getChannel ( message . channel _id ) ;
2019-10-22 18:55:25 +02:00
if ( channel && ( channel . type == 1 || channel . type == 3 || BDFDB . UserUtils . can ( "MANAGE_MESSAGES" ) ) && message . type == 0 ) {
2019-09-26 20:09:46 +02:00
if ( message . pinned ) {
BDFDB . LibraryModules . MessagePinUtils . unpinMessage ( channel , message . id ) ;
2019-10-22 23:04:35 +02:00
if ( BDFDB . DataUtils . get ( this , "toasts" , action ) ) BDFDB . NotificationUtils . toast ( "Message has been unpinned." , { type : "error" } ) ;
2019-09-26 20:09:46 +02:00
}
else {
BDFDB . LibraryModules . MessagePinUtils . pinMessage ( channel , message . id ) ;
2019-10-22 23:04:35 +02:00
if ( BDFDB . DataUtils . get ( this , "toasts" , action ) ) BDFDB . NotificationUtils . toast ( "Message has been pinned." , { type : "success" } ) ;
2019-09-26 20:09:46 +02:00
}
2019-03-01 21:25:48 +01:00
}
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2019-09-26 20:09:46 +02:00
doCopyRaw ( { messagediv , pos , message } , action ) {
if ( message . content ) {
BDFDB . LibraryRequires . electron . clipboard . write ( { text : message . content } ) ;
2019-10-22 23:04:35 +02:00
if ( BDFDB . DataUtils . get ( this , "toasts" , action ) ) BDFDB . NotificationUtils . toast ( "Raw message content has been copied." , { type : "success" } ) ;
2019-09-26 20:09:46 +02:00
}
2019-09-26 16:18:55 +02:00
}
2019-09-26 20:09:46 +02:00
doCopyLink ( { messagediv , pos , message } , action ) {
2019-09-26 16:18:55 +02:00
let channel = BDFDB . LibraryModules . ChannelStore . getChannel ( message . channel _id ) ;
2019-09-26 20:09:46 +02:00
if ( channel ) {
BDFDB . LibraryRequires . electron . clipboard . write ( { text : ` https://discordapp.com/channels/ ${ channel . guild _id } / ${ channel . id } / ${ message . id } ` } ) ;
2019-10-22 23:04:35 +02:00
if ( BDFDB . DataUtils . get ( this , "toasts" , action ) ) BDFDB . NotificationUtils . toast ( "Messagelink has been copied." , { type : "success" } ) ;
2019-09-26 20:09:46 +02:00
}
2019-09-26 16:18:55 +02:00
}
2019-09-26 20:09:46 +02:00
doNote ( { messagediv , pos , message } , action ) {
2019-10-23 11:10:01 +02:00
if ( BDFDB . BDUtils . isPluginEnabled ( this . defaults . bindings . _ _Note _Message . plugin ) ) {
2019-09-11 12:14:43 +02:00
let channel = BDFDB . LibraryModules . ChannelStore . getChannel ( message . channel _id ) ;
2019-10-23 11:10:01 +02:00
if ( channel ) BDFDB . BDUtils . getPlugin ( this . defaults . bindings . _ _Note _Message . plugin ) . addMessageToNotes ( message , messagediv , channel ) ;
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2019-09-26 20:09:46 +02:00
doTranslate ( { messagediv , pos , message } , action ) {
2019-10-23 11:10:01 +02:00
if ( BDFDB . BDUtils . isPluginEnabled ( this . defaults . bindings . _ _Translate _Message . plugin ) ) {
2019-09-11 12:14:43 +02:00
let channel = BDFDB . LibraryModules . ChannelStore . getChannel ( message . channel _id ) ;
2019-10-23 11:10:01 +02:00
if ( channel ) BDFDB . BDUtils . getPlugin ( this . defaults . bindings . _ _Translate _Message . plugin ) . translateMessage ( message , messagediv , channel ) ;
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2019-09-26 20:09:46 +02:00
doQuote ( { messagediv , pos , message } , action ) {
2019-10-23 11:10:01 +02:00
if ( BDFDB . BDUtils . isPluginEnabled ( this . defaults . bindings . _ _Quote _Message . plugin ) ) {
2019-01-03 00:35:05 +01:00
let quoteButton = messagediv . querySelector ( ".btn-quote" ) ;
2018-10-11 10:21:26 +02:00
if ( quoteButton ) quoteButton . click ( ) ;
}
}
2019-01-26 22:45:19 +01:00
2019-09-26 20:09:46 +02:00
doCitate ( { messagediv , pos , message } , action ) {
2019-10-23 11:10:01 +02:00
if ( BDFDB . BDUtils . isPluginEnabled ( this . defaults . bindings . _ _Citate _Message . plugin ) ) {
2019-01-03 00:35:05 +01:00
let citarButton = messagediv . parentElement . querySelector ( ".citar-btn" ) ;
2018-10-11 10:21:26 +02:00
if ( citarButton ) citarButton . click ( ) ;
}
}
2019-01-26 22:45:19 +01:00
2019-09-26 20:09:46 +02:00
doReveal ( { messagediv , pos , message } , action ) {
2019-10-23 11:10:01 +02:00
if ( BDFDB . BDUtils . isPluginEnabled ( this . defaults . bindings . _ _Reveal _Spoilers . plugin ) ) {
BDFDB . BDUtils . getPlugin ( this . defaults . bindings . _ _Reveal _Spoilers . plugin ) . revealAllSpoilers ( messagediv ) ;
2019-02-01 12:34:20 +01:00
}
}
2019-01-31 21:40:52 +01:00
onKeyDown ( e , key , name ) {
2018-10-11 10:21:26 +02:00
if ( ! this . isEventFired ( name ) ) {
this . fireEvent ( name ) ;
2019-10-22 20:16:05 +02:00
if ( key == 27 && BDFDB . DataUtils . get ( this , "settings" , "clearOnEscape" ) ) {
2019-10-23 11:10:01 +02:00
let instance = BDFDB . ReactUtils . findOwner ( BDFDB . DOMUtils . getParent ( BDFDB . dotCNS . chat + "form" , e . currentTarget ) , { name : "ChannelTextAreaForm" , up : true } ) ;
2019-02-25 08:45:46 +01:00
if ( instance ) instance . setState ( { textValue : "" } ) ;
2018-10-11 10:21:26 +02:00
}
this . cancelEvent ( name ) ;
}
}
2019-01-26 22:45:19 +01:00
2018-12-29 11:32:07 +01:00
getActiveShortcutString ( action ) {
2019-09-28 10:27:59 +02:00
if ( ! action ) return null ;
2019-10-22 19:49:57 +02:00
let str = "" , settings = BDFDB . DataUtils . get ( this , "settings" ) ;
2019-09-28 10:27:59 +02:00
if ( settings . addHints && settings [ action ] ) {
2019-10-22 20:16:05 +02:00
let binding = BDFDB . DataUtils . get ( this , "bindings" , action ) ;
2018-12-29 11:32:07 +01:00
if ( binding ) for ( let type in binding ) {
2019-09-28 10:27:59 +02:00
let typename = type == "click" ? this . clickMap [ binding [ type ] ] : this . keyboardMap [ binding [ type ] ] ;
2018-12-29 11:32:32 +01:00
if ( typename && typename != "NONE" ) str += typename + "+" ;
2018-12-29 11:32:07 +01:00
}
}
return str ? str . slice ( 0 , - 1 ) : null ;
}
2019-01-26 22:45:19 +01:00
2019-01-03 00:35:05 +01:00
getMessageData ( target ) {
2019-10-23 11:10:01 +02:00
let messagediv = BDFDB . DOMUtils . getParent ( BDFDB . dotCN . messagegroup + "> [aria-disabled]" , target ) || BDFDB . DOMUtils . getParent ( BDFDB . dotCN . messagegroup + "> * > [aria-disabled]" , target ) || BDFDB . DOMUtils . getParent ( BDFDB . dotCN . messagesystem , target ) ;
2019-09-11 12:14:43 +02:00
let pos = messagediv ? Array . from ( messagediv . parentElement . childNodes ) . filter ( n => n . nodeType != Node . TEXT _NODE ) . indexOf ( messagediv ) : - 1 ;
2019-10-22 18:55:25 +02:00
let instance = BDFDB . ReactUtils . getInstance ( messagediv ) ;
2019-10-22 19:49:57 +02:00
let message = instance ? BDFDB . ReactUtils . findValue ( instance , "message" , { up : true } ) : null ;
2019-01-03 00:35:05 +01:00
return { messagediv , pos , message } ;
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
fireEvent ( name ) {
this . firedEvents . push ( name ) ;
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
isEventFired ( name ) {
return this . firedEvents . includes ( name ) ;
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
cancelEvent ( name ) {
2019-11-01 11:09:32 +01:00
BDFDB . TimeUtils . timeout ( ( ) => { BDFDB . ArrayUtils . remove ( this . firedEvents , name ) } ) ;
2018-10-11 10:21:26 +02:00
}
}