2019-01-31 17:06:48 +01:00
//META{"name":"PersonalPins","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/PersonalPins","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/PersonalPins/PersonalPins.plugin.js"}*//
2018-12-28 14:28:50 +01:00
class PersonalPins {
2019-01-17 23:48:29 +01:00
getName ( ) { return "PersonalPins" ; }
getDescription ( ) { return "Similar to normal pins. Lets you save messages as notes for yourself." ; }
2019-04-23 13:53:19 +02:00
getVersion ( ) { return "1.7.7" ; }
2019-01-17 23:48:29 +01:00
getAuthor ( ) { return "DevilBro" ; }
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
initConstructor ( ) {
2019-02-03 19:02:15 +01:00
this . changelog = {
2019-04-23 13:53:19 +02:00
"fixed" : [ [ "Canary/PTB" , "Fixed the plugin for canary and ptb" ] ]
2019-02-03 19:02:15 +01:00
} ;
2018-12-28 14:28:50 +01:00
this . labels = { } ;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this . patchModules = {
"HeaderBar" : [ "componentDidMount" , "componentDidUpdate" ] ,
2019-04-23 14:03:21 +02:00
"HeaderBarContainer" : [ "componentDidMount" , "componentDidUpdate" ] ,
2018-12-28 14:28:50 +01:00
"Message" : "componentDidMount" ,
2019-01-06 23:37:28 +01:00
"MessageOptionPopout" : "componentDidMount"
2018-12-28 14:28:50 +01:00
} ;
2019-01-26 22:45:19 +01:00
2019-01-12 15:07:06 +01:00
this . notesButtonMarkup =
2019-04-24 08:08:33 +02:00
` <div class=" ${ BDFDB . disCNS . channelheadericonwrapper + BDFDB . disCN . channelheadericonclickable } notes-button">
2019-04-23 20:52:22 +02:00
< svg class = "${BDFDB.disCN.channelheadericon}" name = "Note" width = "24" height = "24" viewBox = "-1 -1 23 23" >
2019-04-23 13:53:19 +02:00
< path fill = "currentColor" d = "M 4.618, 0 c -0.316, 0 -0.573, 0.256 -0.573, 0.573 v 1.145 c 0, 0.316, 0.256, 0.573, 0.573, 0.573 s 0.573 -0.256, 0.573 -0.573 V 0.573 C 5.191, 0.256, 4.935, 0, 4.618, 0 z" / >
< path fill = "currentColor" d = "M 8.053, 0 c -0.316, 0 -0.573, 0.256 -0.573, 0.573 v 1.145 c 0, 0.316, 0.256, 0.573, 0.573, 0.573 s 0.573 -0.256, 0.573 -0.573 V 0.573 C 8.626, 0.256, 8.37, 0, 8.053, 0 z" / >
< path fill = "currentColor" d = "M 11.489, 0 c -0.316, 0 -0.573, 0.256 -0.573, 0.573 v 1.145 c 0, 0.316, 0.256, 0.573, 0.573, 0.573 c 0.316, 0, 0.573 -0.256, 0.573 -0.573 V 0.573 C 12.061, 0.256, 11.805, 0, 11.489, 0 z " / >
< path fill = "currentColor" d = "M 14.924, 0 c -0.316, 0 -0.573, 0.256 -0.573, 0.573 v 1.145 c 0, 0.316, 0.256, 0.573, 0.573, 0.573 c 0.316, 0, 0.573 -0.256, 0.573 -0.573 V 0.573 C 15.496, 0.256, 15.24, 0, 14.924, 0 z" / >
< path fill = "currentColor" d = "M 16.641, 1.25 V 1.718 c 0, 0.947 -0.77, 1.718 -1.718, 1.718 c -0.947, 0 -1.718 -0.77 -1.718 -1.718 c 0, 0.947 -0.77, 1.718 -1.718, 1.718 c -0.947, 0 -1.718 -0.77 -1.718 -1.718 c 0, 0.947 -0.77, 1.718 -1.718, 1.718 c -0.947, 0 -1.718 -0.77 -1.718 -1.718 c 0, 0.947 -0.77, 1.718 -1.718, 1.718 c -0.947, 0 -1.718 -0.77 -1.718 -1.718 V 1.25 C 2.236, 1.488, 1.756, 2.117, 1.756, 2.863 v 14.962 c 0, 0.947, 0.77, 1.718, 1.718, 1.718 h 12.595 c 0.947, 0, 1.718 -0.77, 1.718 -1.718 V 2.863 C 17.786, 2.117, 17.306, 1.488, 16.641, 1.25 z M 14.924, 16.679 H 4.618 c -0.316, 0 -0.573 -0.256 -0.573 -0.573 c 0 -0.316, 0.256 -0.573, 0.573 -0.573 h 10.305 c 0.316, 0, 0.573, 0.256, 0.573, 0.573 C 15.496, 16.423, 15.24, 16.679, 14.924, 16.679 z M 14.924, 13.244 H 4.618 c -0.316, 0 -0.573 -0.256 -0.573 -0.573 c 0 -0.316, 0.256 -0.573, 0.573 -0.573 h 10.305 c 0.316, 0, 0.573, 0.256, 0.573, 0.573 C 15.496, 12.988, 15.24, 13.244, 14.924, 13.244 z M 14.924, 9.733 H 4.618 c -0.316, 0 -0.573 -0.256 -0.573 -0.573 s 0.256 -0.573, 0.573 -0.573 h 10.305 c 0.316, 0, 0.573, 0.256, 0.573, 0.573 S 15.24, 9.733, 14.924, 9.733 z M 14.924, 6.298 H 4.618 c -0.316, 0 -0.573 -0.256 -0.573 -0.573 s 0.256 -0.573, 0.573 -0.573 h 10.305 c 0.316, 0, 0.573, 0.256, 0.573, 0.573 S 15.24, 6.298, 14.924, 6.298 z" / >
< / s v g >
< / d i v > ` ;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this . notesPopoutMarkup =
2019-04-18 09:28:20 +02:00
` <div class=" ${ BDFDB . disCNS . popout + BDFDB . disCNS . popoutbottomright + BDFDB . disCNS . popoutnoarrow + BDFDB . disCN . popoutnoshadow } popout-personalpins-notes BDFDB-modal" style="z-index: 1000; visibility: visible; left: 544.844px; top: 35.9896px; transform: translateX(-100%) translateY(0%) translateZ(0px);">
2018-12-28 14:28:50 +01:00
< div class = "${BDFDB.disCNS.messagespopoutwrap + BDFDB.disCNS.recentmentionspopout + BDFDB.disCN.popoutthemedpopout}" style = "max-height: 740px; width: 500px;" >
2019-01-22 10:50:42 +01:00
< div class = "${BDFDB.disCNS.recentmentionsheader + BDFDB.disCNS.popoutheader + BDFDB.disCN.messagespopoutheader}" style = "padding-bottom: 0;" >
2018-12-28 14:28:50 +01:00
< div class = "${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.margintop8}" style = "flex: 0 0 auto;" >
2019-01-22 10:50:42 +01:00
< div class = "${BDFDB.disCNS.popouttitle + BDFDB.disCN.messagespopouttitle}" > REPLACE _popout _note _text < / d i v >
2018-12-28 14:28:50 +01:00
< / d i v >
2019-01-12 15:07:06 +01:00
< div class = "${BDFDB.disCN.tabbarheadercontainer}" style = "flex: 0 0 auto;" >
< div class = "${BDFDB.disCNS.tabbarheader + BDFDB.disCN.tabbartop}" >
2019-04-23 08:26:48 +02:00
< div tab = "channel" class = "${BDFDB.disCNS.settingsitem + BDFDB.disCN.tabbarheaderitem}" > REPLACE _popout _channel _text < / d i v >
< div tab = "server" class = "${BDFDB.disCNS.settingsitem + BDFDB.disCN.tabbarheaderitem}" > REPLACE _popout _server _text < / d i v >
< div tab = "allservers" class = "${BDFDB.disCNS.settingsitem + BDFDB.disCN.tabbarheaderitem}" > REPLACE _popout _allservers _text < / d i v >
2019-01-12 15:07:06 +01:00
< / d i v >
< div class = "${BDFDB.disCN.recentmentionsmentionfilter}" style = "padding-right: 15px;" >
< div class = "${BDFDB.disCN.recentmentionsmentionfilterlabel}" > REPLACE _popout _sort _text : < / d i v >
< div option = "timestamp" class = "${BDFDB.disCN.recentmentionsmentionfiltervalue}" style = "text-transform: none;" > REPLACE _popout _messagesort _text < / d i v >
2018-12-28 14:28:50 +01:00
< / d i v >
< / d i v >
< / d i v >
< div class = "${BDFDB.disCN.scrollerwrap}" >
< div class = "${BDFDB.disCNS.messagespopout + BDFDB.disCN.scroller}" >
< div class = "${BDFDB.disCN.messagespopoutemptyplaceholder}" >
< div class = "${BDFDB.disCN.messagespopoutimage}" > < / d i v >
< div class = "${BDFDB.disCN.messagespopoutbody}" > < / d i v >
< / d i v >
< / d i v >
< / d i v >
< / d i v >
< / d i v > ` ;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this . sortPopoutMarkup =
` <div class=" ${ BDFDB . disCNS . popout + BDFDB . disCNS . popoutbottomright + BDFDB . disCN . popoutnoshadow } personalpins-sort-popout" style="z-index: 1100; visibility: visible; transform: translateX(-100%) translateY(0%) translateZ(0px);">
< div >
< div class = "${BDFDB.disCN.contextmenu} quickSelectPopout" >
< div class = "${BDFDB.disCN.contextmenuitemgroup}" >
< div option = "timestamp" class = "${BDFDB.disCN.contextmenuitem}" > REPLACE _popout _messagesort _text < / d i v >
< div option = "addedat" class = "${BDFDB.disCN.contextmenuitem}" > REPLACE _popout _datesort _text < / d i v >
< / d i v >
< / d i v >
< / d i v >
< / d i v > ` ;
2019-01-26 22:45:19 +01:00
2018-12-29 11:51:32 +01:00
this . messagePinContextEntryMarkup =
` <div class=" ${ BDFDB . disCN . contextmenuitemgroup } ">
2019-01-02 20:35:52 +01:00
< div class = "${BDFDB.disCN.contextmenuitem} personalpins-item personalpins-pin-item" >
2019-04-18 09:28:20 +02:00
< span class = "BDFDB-textscrollwrapper" speed = 3 > < div class = "BDFDB-textscroll" > REPLACE _context _pinoption _text < / d i v > < / s p a n >
2018-12-29 11:51:32 +01:00
< div class = "${BDFDB.disCN.contextmenuhint}" > < / d i v >
< / d i v >
< / d i v > ` ;
2019-01-26 22:45:19 +01:00
2018-12-29 11:51:32 +01:00
this . messageUnpinContextEntryMarkup =
` <div class=" ${ BDFDB . disCN . contextmenuitemgroup } ">
2019-01-02 20:35:52 +01:00
< div class = "${BDFDB.disCN.contextmenuitem} personalpins-item personalpins-unpin-item" >
2019-04-18 09:28:20 +02:00
< span class = "BDFDB-textscrollwrapper" speed = 3 > < div class = "BDFDB-textscroll" > REPLACE _context _unpinoption _text < / d i v > < / s p a n >
2018-12-29 11:51:32 +01:00
< div class = "${BDFDB.disCN.contextmenuhint}" > < / d i v >
< / d i v >
< / d i v > ` ;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this . popoutPinEntryMarkup =
2019-01-02 20:35:52 +01:00
` <button role="menuitem" type="button" class=" ${ BDFDB . disCNS . optionpopoutitem + BDFDB . disCNS . button + BDFDB . disCNS . buttonlookblank + BDFDB . disCNS . buttoncolorbrand + BDFDB . disCN . buttongrow } personalpins-itembtn personalpins-pin-itembtn">
2018-12-28 14:28:50 +01:00
< div class = "${BDFDB.disCN.buttoncontents}" > REPLACE _popout _pinoption _text < / d i v >
< / b u t t o n > ` ;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this . popoutUnpinEntryMarkup =
2019-01-02 20:35:52 +01:00
` <button role="menuitem" type="button" class=" ${ BDFDB . disCNS . optionpopoutitem + BDFDB . disCNS . button + BDFDB . disCNS . buttonlookblank + BDFDB . disCNS . buttoncolorbrand + BDFDB . disCN . buttongrow } personalpins-itembtn personalpins-unpin-itembtn">
2018-12-28 14:28:50 +01:00
< div class = "${BDFDB.disCN.buttoncontents}" > REPLACE _popout _unpinoption _text < / d i v >
< / b u t t o n > ` ;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this . messageDividerMarkup =
` <div class=" ${ BDFDB . disCN . messagespopoutchannelseparator } ">
< span tabindex = "0" class = "${BDFDB.disCN.messagespopoutchannelname}" role = "button" > < / s p a n >
< span class = $ { BDFDB . disCN . messagespopoutguildname } > < / s p a n >
< / d i v > ` ;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this . messageMarkup =
` <div class=" ${ BDFDB . disCN . messagespopoutmessagegroupwrapper } ">
< div class = "${BDFDB.disCN.messagespopoutmessagegroupwrapperoffsetcorrection}" >
< div class = "${BDFDB.disCNS.messagespopoutcontainercozybounded + BDFDB.disCNS.messagegroup + BDFDB.disCN.messagegroupcozy}" >
< div class = "${BDFDB.disCNS.messagespopoutmessagegroupcozy + BDFDB.disCNS.messagecozy + BDFDB.disCN.message}" aria - disabled = "true" >
< div class = "${BDFDB.disCN.messageheadercozy}" >
< div tabindex = "-1" aria - hidden = "true" class = "${BDFDB.disCNS.avatarwrapper + BDFDB.disCNS.avatarlarge + BDFDB.disCN.avatar}" role = "button" >
< div class = "${BDFDB.disCNS.avatarimage + BDFDB.disCN.avatarlarge}" > < / d i v >
< / d i v >
< h2 class = "${BDFDB.disCN.messageheadercozymeta}" >
< span class = "" >
< strong tabindex = "0" class = "${BDFDB.disCN.messageusername}" role = "button" > < / s t r o n g >
< / s p a n >
< time class = "${BDFDB.disCN.messagetimestampcozy}" > < / t i m e >
< / h 2 >
< / d i v >
< div class = "${BDFDB.disCNS.messagecontentcozy + BDFDB.disCN.messagecontent}" >
< div class = "${BDFDB.disCNS.messagebodycozy + BDFDB.disCN.messagebody}" >
< div class = "${BDFDB.disCN.messagemarkup}" > < / d i v >
< / d i v >
< div class = "${BDFDB.disCNS.messagespopoutaccessories + BDFDB.disCNS.messageaccessorycozy + BDFDB.disCN.messageaccessory}" > < / d i v >
< / d i v >
< / d i v >
< div class = "${BDFDB.disCNS.sinkinteractions + BDFDB.disCN.clickable}" > < / d i v >
< div class = "${BDFDB.disCN.messagespopoutactionbuttons}" >
< div tabindex = "0" class = "${BDFDB.disCN.messagespopoutjumpbutton} jump" role = "button" >
< div class = "${BDFDB.disCN.messagespopouttext}" > REPLACE _popout _jump _text < / d i v >
< / d i v >
< div tabindex = "0" class = "${BDFDB.disCN.messagespopoutjumpbutton} copy" aria - label = "Jump" role = "button" >
< div class = "${BDFDB.disCN.messagespopouttext}" > REPLACE _popout _copy _text < / d i v >
< / d i v >
< button type = "button" class = "${BDFDB.disCNS.button + BDFDB.disCNS.buttoncolorbrand + BDFDB.disCNS.buttonlookblank + BDFDB.disCN.buttongrow}" >
< div class = "${BDFDB.disCN.buttoncontents}" >
< div class = "${BDFDB.disCN.messagespopoutclosebutton}" > < / d i v >
< / d i v >
< / b u t t o n >
< / d i v >
< hr aria - hidden = "true" class = "${BDFDB.disCNS.messagedividerenabled + BDFDB.disCN.messagedivider}" >
< / d i v >
< / d i v >
< / d i v > ` ;
}
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
getSettingsPanel ( ) {
2019-01-22 11:28:32 +01:00
if ( ! global . BDFDB || typeof BDFDB != "object" || ! BDFDB . loaded || ! this . started ) return ;
2019-04-18 09:28:20 +02:00
let settingshtml = ` <div class=" ${ this . name } -settings BDFDB-settings"><div class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . title + BDFDB . disCNS . size18 + BDFDB . disCNS . height24 + BDFDB . disCNS . weightnormal + BDFDB . disCN . marginbottom8 } "> ${ this . name } </div><div class="BDFDB-settings-inner"> ` ;
2018-12-28 14:28:50 +01:00
settingshtml += ` <div class=" ${ BDFDB . disCNS . flex + BDFDB . disCNS . flex2 + BDFDB . disCNS . horizontal + BDFDB . disCNS . horizontal2 + BDFDB . disCNS . directionrow + BDFDB . disCNS . justifystart + BDFDB . disCNS . aligncenter + BDFDB . disCNS . nowrap + BDFDB . disCN . marginbottom8 } " style="flex: 0 0 auto;"><h3 class=" ${ BDFDB . disCNS . titledefault + BDFDB . disCNS . title + BDFDB . disCNS . marginreset + BDFDB . disCNS . weightmedium + BDFDB . disCNS . size16 + BDFDB . disCNS . height24 + BDFDB . disCN . flexchild } " style="flex: 1 1 auto;">Delete all Notes.</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> ` ;
settingshtml += ` </div></div> ` ;
2019-01-26 22:45:19 +01:00
2019-01-12 15:07:06 +01:00
let settingspanel = BDFDB . htmlToElement ( settingshtml ) ;
2018-12-28 14:28:50 +01:00
2019-01-17 23:48:29 +01:00
BDFDB . initElements ( settingspanel , this ) ;
2018-12-28 14:28:50 +01:00
2019-01-12 15:07:06 +01:00
settingspanel . querySelector ( ".reset-button" ) . addEventListener ( "click" , ( ) => {
BDFDB . openConfirmModal ( this , "Are you sure you want to delete all pinned notes?" , ( ) => {
BDFDB . removeAllData ( this , "pins" ) ;
2019-01-06 23:37:28 +01:00
} ) ;
2019-01-12 15:07:06 +01:00
} ) ;
2018-12-28 14:28:50 +01:00
return settingspanel ;
}
//legacy
load ( ) { }
start ( ) {
2019-02-04 09:13:15 +01:00
if ( ! global . BDFDB ) global . BDFDB = { myPlugins : { } } ;
if ( global . BDFDB && global . BDFDB . myPlugins && typeof global . BDFDB . myPlugins == "object" ) global . BDFDB . myPlugins [ this . getName ( ) ] = this ;
2019-01-17 23:48:29 +01:00
var libraryScript = document . querySelector ( 'head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]' ) ;
if ( ! libraryScript || performance . now ( ) - libraryScript . getAttribute ( "date" ) > 600000 ) {
2018-12-28 14:28:50 +01:00
if ( libraryScript ) libraryScript . remove ( ) ;
libraryScript = document . createElement ( "script" ) ;
libraryScript . setAttribute ( "type" , "text/javascript" ) ;
libraryScript . setAttribute ( "src" , "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js" ) ;
2019-01-17 23:48:29 +01:00
libraryScript . setAttribute ( "date" , performance . now ( ) ) ;
2019-01-30 21:23:49 +01:00
libraryScript . addEventListener ( "load" , ( ) => { if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) this . initialize ( ) ; } ) ;
2018-12-28 14:28:50 +01:00
document . head . appendChild ( libraryScript ) ;
}
2019-01-17 23:48:29 +01:00
else if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) this . initialize ( ) ;
2018-12-28 14:28:50 +01:00
this . startTimeout = setTimeout ( ( ) => { this . initialize ( ) ; } , 30000 ) ;
}
initialize ( ) {
2019-01-17 23:48:29 +01:00
if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) {
2019-01-22 11:05:54 +01:00
if ( this . started ) return ;
2018-12-28 14:28:50 +01:00
BDFDB . loadMessage ( this ) ;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this . SelectChannelUtils = BDFDB . WebModules . findByProperties ( "selectGuild" , "selectChannel" ) ;
2018-12-29 20:45:39 +01:00
this . GuildUtils = BDFDB . WebModules . findByProperties ( "getGuilds" , "getGuild" ) ;
this . ChannelUtils = BDFDB . WebModules . findByProperties ( "getChannels" , "getChannel" ) ;
this . UserUtils = BDFDB . WebModules . findByProperties ( "getUsers" , "getUser" ) ;
this . MemberUtils = BDFDB . WebModules . findByProperties ( "getMembers" , "getMember" ) ;
2018-12-28 14:28:50 +01:00
this . LastGuildStore = BDFDB . WebModules . findByProperties ( "getLastSelectedGuildId" ) ;
this . LastChannelStore = BDFDB . WebModules . findByProperties ( "getLastSelectedChannelId" ) ;
this . HistoryUtils = BDFDB . WebModules . findByProperties ( "transitionTo" , "replaceWith" , "getHistory" ) ;
2019-03-11 11:47:07 +01:00
this . DiscordConstants = BDFDB . WebModules . findByProperties ( "Permissions" , "ActivityTypes" , "StatusTypes" ) ;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
BDFDB . WebModules . forceAllUpdates ( this ) ;
}
else {
2019-02-12 21:56:34 +01:00
console . error ( ` %c[ ${ this . getName ( ) } ]%c ` , 'color: #3a71c1; font-weight: 700;' , '' , 'Fatal Error: Could not load BD functions!' ) ;
2018-12-28 14:28:50 +01:00
}
}
stop ( ) {
2019-01-17 23:48:29 +01:00
if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) {
2019-01-12 15:07:06 +01:00
BDFDB . removeEles ( ".popout-personalpins-notes" , ".personalpins-sort-popout" , ".notes-button" ) ;
2018-12-28 14:28:50 +01:00
BDFDB . unloadMessage ( this ) ;
}
}
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
// begin of own functions
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
changeLanguageStrings ( ) {
this . messagePinContextEntryMarkup = this . messagePinContextEntryMarkup . replace ( "REPLACE_context_pinoption_text" , this . labels . context _pinoption _text ) ;
this . messageUnpinContextEntryMarkup = this . messageUnpinContextEntryMarkup . replace ( "REPLACE_context_unpinoption_text" , this . labels . context _unpinoption _text ) ;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this . notesPopoutMarkup = this . notesPopoutMarkup . replace ( "REPLACE_popout_note_text" , this . labels . popout _note _text ) ;
this . notesPopoutMarkup = this . notesPopoutMarkup . replace ( "REPLACE_popout_channel_text" , this . labels . popout _channel _text ) ;
this . notesPopoutMarkup = this . notesPopoutMarkup . replace ( "REPLACE_popout_server_text" , this . labels . popout _server _text ) ;
this . notesPopoutMarkup = this . notesPopoutMarkup . replace ( "REPLACE_popout_allservers_text" , this . labels . popout _allservers _text ) ;
this . notesPopoutMarkup = this . notesPopoutMarkup . replace ( "REPLACE_popout_sort_text" , this . labels . popout _sort _text ) ;
this . notesPopoutMarkup = this . notesPopoutMarkup . replace ( "REPLACE_popout_messagesort_text" , this . labels . popout _messagesort _text ) ;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this . messageMarkup = this . messageMarkup . replace ( "REPLACE_popout_jump_text" , this . labels . popout _jump _text ) ;
this . messageMarkup = this . messageMarkup . replace ( "REPLACE_popout_copy_text" , this . labels . popout _copy _text ) ;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this . sortPopoutMarkup = this . sortPopoutMarkup . replace ( "REPLACE_popout_messagesort_text" , this . labels . popout _messagesort _text ) ;
this . sortPopoutMarkup = this . sortPopoutMarkup . replace ( "REPLACE_popout_datesort_text" , this . labels . popout _datesort _text ) ;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this . popoutPinEntryMarkup = this . popoutPinEntryMarkup . replace ( "REPLACE_popout_pinoption_text" , this . labels . popout _pinoption _text ) ;
this . popoutUnpinEntryMarkup = this . popoutUnpinEntryMarkup . replace ( "REPLACE_popout_unpinoption_text" , this . labels . context _unpinoption _text ) ;
}
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
onMessageContextMenu ( instance , menu ) {
2019-01-02 20:35:52 +01:00
if ( instance . props && instance . props . message && instance . props . channel && instance . props . target && ! menu . querySelector ( ".personalpins-item" ) ) {
2019-01-12 15:07:06 +01:00
let pinentry = BDFDB . React . findDOMNodeSafe ( BDFDB . getOwnerInstance ( { node : menu , name : "MessagePinItem" } ) ) ;
let messagePinContextEntry = BDFDB . htmlToElement ( this . getNoteData ( instance . props . message , instance . props . target , instance . props . channel ) ? this . messageUnpinContextEntryMarkup : this . messagePinContextEntryMarkup ) ;
if ( pinentry ) pinentry . parentElement . insertBefore ( messagePinContextEntry , pinentry . nextElementSibling ) ;
else menu . insertBefore ( messagePinContextEntry , menu . firstElementChild ) ;
let pinitem = messagePinContextEntry . querySelector ( ".personalpins-item" ) ;
pinitem . addEventListener ( "click" , ( ) => {
2019-03-01 21:26:41 +01:00
BDFDB . closeContextMenu ( menu ) ;
2019-01-12 15:07:06 +01:00
this . addMessageToNotes ( instance . props . message , instance . props . target , instance . props . channel ) ;
} ) ;
if ( BDFDB . isPluginEnabled ( "MessageUtilities" ) ) {
BDFDB . setContextHint ( pinitem , bdplugins . MessageUtilities . plugin . getActiveShortcutString ( "__Note_Message" ) ) ;
2018-12-28 14:28:50 +01:00
}
}
}
2019-04-23 14:03:21 +02:00
processHeaderBarContainer ( instance , wrapper ) {
this . processHeaderBar ( instance , wrapper ) ;
}
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
processHeaderBar ( instance , wrapper ) {
2019-01-12 15:07:06 +01:00
BDFDB . removeEles ( ".notes-button" ) ;
let search = wrapper . querySelector ( BDFDB . dotCN . channelheadersearch ) ;
if ( ! search ) return ;
let notesbutton = BDFDB . htmlToElement ( this . notesButtonMarkup ) ;
search . parentElement . insertBefore ( notesbutton , search ) ;
let icon = notesbutton . querySelector ( BDFDB . dotCN . channelheadericon ) ;
icon . addEventListener ( "click" , ( ) => {
2019-04-23 13:53:19 +02:00
this . openNotesPopout ( icon . parentElement ) ;
2019-01-12 15:07:06 +01:00
} ) ;
icon . addEventListener ( "mouseenter" , ( ) => {
BDFDB . createTooltip ( this . labels . popout _note _text , icon , { type : "bottom" , selector : "note-button-tooltip" } ) ;
} ) ;
2018-12-28 14:28:50 +01:00
}
2019-01-26 22:45:19 +01:00
2019-01-02 10:09:39 +01:00
processMessage ( instance , wrapper ) {
2019-03-01 21:26:41 +01:00
if ( instance . props && typeof instance . props . renderButtons == "function" && ! wrapper . querySelector ( BDFDB . dotCN . optionpopoutbutton ) && BDFDB . getReactValue ( instance , "props.message.author.id" ) != 1 ) {
2018-12-28 14:28:50 +01:00
let buttonwrap = wrapper . querySelector ( BDFDB . dotCN . messagebuttoncontainer ) ;
if ( buttonwrap ) {
2019-01-12 15:07:06 +01:00
let optionPopoutButton = BDFDB . htmlToElement ( ` <div class=" ${ BDFDB . disCN . optionpopoutbutton } "></div> ` ) ;
optionPopoutButton . addEventListener ( "click" , ( ) => { BDFDB . createMessageOptionPopout ( optionPopoutButton ) ; } ) ;
buttonwrap . appendChild ( optionPopoutButton ) ;
2018-12-28 14:28:50 +01:00
}
}
}
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
processMessageOptionPopout ( instance , wrapper ) {
2019-01-02 23:26:23 +01:00
if ( instance . props . message && instance . props . channel && instance . _reactInternalFiber . memoizedProps . target && ! wrapper . querySelector ( ".personalpins-itembtn" ) ) {
2019-01-17 23:48:29 +01:00
let { messagediv , pos } = this . getMessageAndPos ( instance . _reactInternalFiber . memoizedProps . target ) ;
if ( ! messagediv || pos == - 1 ) return ;
2019-01-12 15:07:06 +01:00
let popoutUnpinEntry = BDFDB . htmlToElement ( this . getNoteData ( instance . props . message , instance . _reactInternalFiber . memoizedProps . target , instance . props . channel ) ? this . popoutUnpinEntryMarkup : this . popoutPinEntryMarkup ) ;
wrapper . appendChild ( popoutUnpinEntry ) ;
popoutUnpinEntry . addEventListener ( "click" , ( ) => {
this . addMessageToNotes ( instance . props . message , instance . _reactInternalFiber . memoizedProps . target , instance . props . channel ) ;
instance . props . onClose ( ) ;
} ) ;
2018-12-28 14:28:50 +01:00
}
2019-04-23 13:53:19 +02:00
}
2019-01-26 22:45:19 +01:00
2019-01-12 15:07:06 +01:00
openNotesPopout ( button ) {
let container = document . querySelector ( BDFDB . dotCN . popouts ) ;
2019-04-23 13:53:19 +02:00
if ( ! container || BDFDB . containsClass ( button , BDFDB . disCN . channelheadericonselected ) ) return ;
BDFDB . addClass ( button , BDFDB . disCN . channelheadericonselected ) ;
2019-01-12 15:07:06 +01:00
let notespopout = BDFDB . htmlToElement ( this . notesPopoutMarkup ) ;
2019-04-23 13:53:19 +02:00
notespopout . querySelector ( BDFDB . dotCN . popoutheader ) . firstElementChild . appendChild ( BDFDB . createSearchBar ( "small" ) ) ;
2019-01-12 15:07:06 +01:00
container . appendChild ( notespopout ) ;
2019-01-26 22:45:19 +01:00
BDFDB . initElements ( notespopout , this ) ;
2019-01-17 23:48:29 +01:00
let buttonrects = BDFDB . getRects ( button ) ;
2019-01-12 15:07:06 +01:00
notespopout . style . setProperty ( "left" , buttonrects . left + buttonrects . width / 2 + "px" ) ;
notespopout . style . setProperty ( "top" , buttonrects . top + buttonrects . height + "px" )
notespopout . querySelectorAll ( BDFDB . dotCN . tabbarheaderitem ) . forEach ( tab => { tab . addEventListener ( "click" , ( ) => {
this . addNotes ( notespopout ) ;
} ) ; } ) ;
notespopout . querySelector ( BDFDB . dotCN . searchbarinput ) . addEventListener ( "keyup" , ( ) => {
clearTimeout ( notespopout . searchTimeout ) ;
notespopout . searchTimeout = setTimeout ( ( ) => { this . addNotes ( notespopout ) ; } , 1000 ) ;
2018-12-28 14:28:50 +01:00
} ) ;
2019-01-12 15:07:06 +01:00
notespopout . querySelector ( BDFDB . dotCN . searchbarclear ) . addEventListener ( "click" , e => {
clearTimeout ( notespopout . searchTimeout ) ;
notespopout . searchTimeout = setTimeout ( ( ) => { this . addNotes ( notespopout ) ; } , 1000 ) ;
2018-12-28 14:28:50 +01:00
} ) ;
2019-01-12 15:07:06 +01:00
notespopout . querySelector ( BDFDB . dotCN . recentmentionsmentionfilter ) . addEventListener ( "click" , e => {
BDFDB . createSortPopout ( e . currentTarget , this . sortPopoutMarkup , ( ) => { this . addNotes ( notespopout ) ; } ) ;
} ) ;
2019-01-26 22:45:19 +01:00
2019-01-17 23:48:29 +01:00
var removePopout = e => {
2019-01-12 15:07:06 +01:00
if ( ! notespopout . contains ( e . target ) && ! BDFDB . getParentEle ( ".personalpins-sort-popout" , e . target ) ) {
document . removeEventListener ( "mousedown" , removePopout ) ;
notespopout . remove ( ) ;
2019-04-23 13:53:19 +02:00
setTimeout ( ( ) => { BDFDB . removeClass ( button , BDFDB . disCN . channelheadericonselected ) ; } , 300 ) ;
2018-12-28 14:28:50 +01:00
}
} ;
2019-01-12 15:07:06 +01:00
document . addEventListener ( "mousedown" , removePopout ) ;
2019-01-26 22:45:19 +01:00
2019-01-12 15:07:06 +01:00
this . addNotes ( notespopout ) ;
2018-12-28 14:28:50 +01:00
}
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
addNotes ( notespopout ) {
2019-01-12 15:07:06 +01:00
BDFDB . removeEles ( notespopout . querySelectorAll ( BDFDB . dotCNC . messagegroupwrapper + BDFDB . dotCN . messagespopoutchannelseparator ) ) ;
let channel = BDFDB . getSelectedChannel ( ) ;
if ( channel ) {
let guild _id = channel . guild _id ? channel . guild _id : "@me" ;
2018-12-28 14:28:50 +01:00
let pins = BDFDB . loadAllData ( this , "pins" ) ;
if ( ! BDFDB . isObjectEmpty ( pins ) ) {
let container = notespopout . querySelector ( BDFDB . dotCN . messagespopout ) ;
let placeholder = notespopout . querySelector ( BDFDB . dotCN . messagespopoutemptyplaceholder ) ;
2019-01-12 15:07:06 +01:00
if ( ! container || ! placeholder ) return ;
2018-12-28 14:28:50 +01:00
placeholder . querySelector ( BDFDB . dotCN . messagespopoutimage ) . style . setProperty ( "background-image" , ` url( ${ BDFDB . getDiscordTheme ( ) == BDFDB . disCN . themelight ? "/assets/03c7541028afafafd1a9f6a81cb7f149.svg" : "/assets/6793e022dc1b065b21f12d6df02f91bd.svg" } ) ` ) ;
2019-01-12 15:07:06 +01:00
let notes = { } ;
switch ( notespopout . querySelector ( BDFDB . dotCN . tabbarheaderitem + BDFDB . dotCN . settingsitemselected ) . getAttribute ( "tab" ) ) {
2018-12-28 14:28:50 +01:00
case "channel" :
2019-01-12 15:07:06 +01:00
notes = pins [ guild _id ] && pins [ guild _id ] [ channel . id ] ? pins [ guild _id ] [ channel . id ] : { } ;
2018-12-28 14:28:50 +01:00
break ;
case "server" :
2019-01-12 15:07:06 +01:00
if ( pins [ guild _id ] ) for ( let channel in pins [ guild _id ] ) notes = Object . assign ( notes , pins [ guild _id ] [ channel ] ) ;
2018-12-28 14:28:50 +01:00
break ;
case "allservers" :
2019-01-12 15:07:06 +01:00
for ( let server in pins ) if ( pins [ server ] ) for ( let channel in pins [ server ] ) notes = Object . assign ( notes , pins [ server ] [ channel ] ) ;
2018-12-28 14:28:50 +01:00
break ;
}
2019-01-12 15:07:06 +01:00
let noteArray = [ ] ;
for ( let id in notes ) { noteArray . push ( notes [ id ] ) ; }
BDFDB . sortArrayByKey ( noteArray , notespopout . querySelector ( BDFDB . dotCN . recentmentionsmentionfiltervalue ) . getAttribute ( "option" ) ) ;
for ( let noteData of noteArray ) this . appendNote ( container , noteData , placeholder ) ;
let searchstring = notespopout . querySelector ( BDFDB . dotCN . searchbarinput ) . value . replace ( /[<|>]/g , "" ) ;
if ( searchstring ) for ( let note of notespopout . querySelectorAll ( BDFDB . dotCN . messagegroupwrapper ) ) {
note . innerHTML = BDFDB . highlightText ( note . innerHTML , searchstring ) ;
if ( ! note . querySelector ( BDFDB . dotCN . highlight ) ) {
note . previousSibling . remove ( ) ;
note . remove ( ) ;
2018-12-28 14:28:50 +01:00
}
2019-01-12 15:07:06 +01:00
}
2019-01-17 23:48:29 +01:00
BDFDB . toggleEles ( placeholder , container . firstElementChild == placeholder ) ;
2019-01-12 15:07:06 +01:00
}
}
}
2019-01-26 22:45:19 +01:00
2019-01-12 15:07:06 +01:00
appendNote ( container , noteData , placeholder ) {
if ( ! container || ! noteData ) return ;
let server = this . GuildUtils . getGuild ( noteData . guild _id ) || { } ;
let channel = this . ChannelUtils . getChannel ( noteData . channel _id ) || { } ;
let user = this . UserUtils . getUser ( noteData . author _id ) || { } ;
let member = this . MemberUtils . getMember ( noteData . guild _id , noteData . author _id ) || { } ;
let date = new Date ( noteData . timestamp ) ;
let message = BDFDB . htmlToElement ( this . messageMarkup ) ;
let messagedivider = BDFDB . htmlToElement ( this . messageDividerMarkup ) ;
container . insertBefore ( message , container . firstChild ) ;
container . insertBefore ( messagedivider , container . firstChild ) ;
let channelname = messagedivider . querySelector ( BDFDB . dotCN . messagespopoutchannelname ) ;
channelname . innerText = ( noteData . guild _id == "@me" ? " @" : " #" ) + ( channel . name || noteData . channel _name ) ;
if ( noteData . guild _id != "@me" && BDFDB . isPluginEnabled ( "EditChannels" ) ) {
bdplugins . EditChannels . plugin . changeChannel2 ( { id : noteData . channel _id , name : noteData . channel _name } , channelname ) ;
}
else if ( noteData . guild _id == "@me" && BDFDB . isPluginEnabled ( "EditUsers" ) ) {
let dmuser _id = channel && channel . type == 1 ? channel . recipients [ 0 ] : noteData . dmuser _id ;
if ( dmuser _id ) {
bdplugins . EditUsers . plugin . changeName2 ( { id : dmuser _id , username : noteData . channel _name } , channelname ) ;
if ( channelname . innerText . indexOf ( "@" ) != 0 ) channelname . innerText = "@" + channelname . innerText ;
}
}
let guildname = messagedivider . querySelector ( BDFDB . dotCN . messagespopoutguildname ) ;
guildname . innerText = server . name || noteData . guild _name ;
let avatar = message . querySelector ( BDFDB . dotCN . avatarimage ) ;
avatar . style . setProperty ( "background-image" , ` url( ${ user . id ? BDFDB . getUserAvatar ( user . id ) : noteData . avatar } ) ` ) ;
let username = message . querySelector ( BDFDB . dotCN . messageusername ) ;
username . innerText = user . username || noteData . author _name ;
username . style . setProperty ( "color" , member . colorString || noteData . color ) ;
if ( BDFDB . isPluginEnabled ( "EditUsers" ) ) {
bdplugins . EditUsers . plugin . changeName ( { id : noteData . author _id , username : noteData . author _name } , username , noteData . guild _id ) ;
if ( user . id ) bdplugins . EditUsers . plugin . changeAvatar ( { id : noteData . author _id , username : noteData . author _name } , avatar ) ;
bdplugins . EditUsers . plugin . addTag ( { id : noteData . author _id , username : noteData . author _name } , username . parentElement , " " + BDFDB . disCN . bottagnametag ) ;
}
let timestamp = message . querySelector ( BDFDB . dotCN . messagetimestampcozy ) ;
timestamp . innerText = date . toLocaleString ( BDFDB . getDiscordLanguage ( ) . id ) ;
timestamp . setAttribute ( "datetime" , date ) ;
2019-02-03 18:03:02 +01:00
if ( BDFDB . isPluginEnabled ( "CompleteTimestamps" ) && BDFDB . loadData ( "showInChat" , "CompleteTimestamps" , "settings" ) ) {
bdplugins . CompleteTimestamps . plugin . changeTimestamp ( timestamp ) ;
}
2019-01-12 15:07:06 +01:00
message . querySelector ( BDFDB . dotCN . messagemarkup ) . innerHTML = noteData . markup . replace ( ` <span class="edited"> ` , ` <span class=" ${ BDFDB . disCN . messageedited } "> ` ) ;
message . querySelector ( BDFDB . dotCN . messageaccessory ) . innerHTML = noteData . accessory ;
if ( noteData . accessory ) {
2019-01-22 10:50:42 +01:00
BDFDB . addChildEventListener ( message , "click" , BDFDB . dotCN . iconplay , e => { this . startYoutubeVideo ( e . currentTarget ) ; } ) ;
2019-01-12 15:07:06 +01:00
let ytvideo = message . querySelector ( BDFDB . dotCN . embed + " iframe[src*='https://www.youtube.com']" ) ;
if ( ytvideo ) {
let ytlink = ytvideo . parentElement . parentElement . querySelector ( BDFDB . dotCN . embedtitle ) . href ;
let wrapper = ytvideo . parentElement ;
ytvideo . remove ( ) ;
require ( "request" ) ( ytlink , ( error , response , result ) => {
if ( result ) {
2019-01-22 10:50:42 +01:00
wrapper . innerHTML = ` <div class=" ${ BDFDB . disCNS . imagewrapper + BDFDB . disCNS . imageclickable + BDFDB . disCN . embedvideoimagecomponent } " style="width: 400px; height: 225px;"><img alt="" src=" ${ result . split ( '<link itemprop="thumbnailUrl" href="' ) [ 1 ] . split ( '"' ) [ 0 ] } " style="width: 400px; height: 225px;"></div><div class=" ${ BDFDB . disCN . embedvideoactions } "><div class=" ${ BDFDB . disCN . embedcentercontent } "><div class=" ${ BDFDB . disCN . iconactionswrapper } "><div tabindex="0" class=" ${ BDFDB . disCNS . iconwrapper + BDFDB . disCN . iconwrapperactive } " role="button"><svg name="Play" class=" ${ BDFDB . disCNS . iconplay + BDFDB . disCN . icon } " width="16" height="16" viewBox="0 0 24 24"><polygon fill="currentColor" points="0 0 0 14 11 7" transform="translate(7 5)"></polygon></svg></div><a class=" ${ BDFDB . disCNS . anchor + BDFDB . disCNS . anchorunderlineonhover + BDFDB . disCNS . iconwrapper + BDFDB . disCN . iconwrapperactive } " href=" ${ ytlink } " rel="noreferrer noopener" target="_blank"><svg name="OpenExternal" class=" ${ BDFDB . disCNS . iconexternalmargins + BDFDB . disCN . icon } " width="16" height="16" viewBox="0 0 24 24"><path fill="currentColor" transform="translate(3.000000, 4.000000)" d="M16 0H2a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h4v-2H2V4h14v10h-4v2h4c1.1 0 2-.9 2-2V2a2 2 0 0 0-2-2zM9 6l-4 4h3v6h2v-6h3L9 6z"></path></svg></a></div></div></div> ` ;
wrapper . querySelector ( BDFDB . dotCN . iconplay ) . addEventListener ( "click" , e => { this . startYoutubeVideo ( e . currentTarget ) ; } ) ;
2018-12-28 14:28:50 +01:00
}
2019-01-12 15:07:06 +01:00
} ) ;
}
}
2019-01-17 23:48:29 +01:00
messagedivider . querySelector ( BDFDB . dotCN . messagespopoutchannelname ) . addEventListener ( "click" , e => {
2019-01-12 15:07:06 +01:00
if ( ! BDFDB . isObjectEmpty ( channel ) ) {
notespopout . remove ( ) ;
this . SelectChannelUtils . selectChannel ( server . id , channel . id ) ;
}
else BDFDB . shake ( ) ;
} ) ;
2019-01-17 23:48:29 +01:00
message . querySelector ( BDFDB . dotCN . messagespopoutclosebutton ) . addEventListener ( "click" , e => {
BDFDB . removeEles ( messagedivider , message ) ;
2019-01-12 15:07:06 +01:00
this . removeNoteData ( noteData ) ;
2019-01-17 23:48:29 +01:00
BDFDB . toggleEles ( placeholder , container . firstElementChild == placeholder ) ;
2019-01-12 15:07:06 +01:00
} ) ;
2019-01-17 23:48:29 +01:00
message . querySelector ( BDFDB . dotCN . messagespopoutjumpbutton + ".jump" ) . addEventListener ( "click" , e => {
2019-03-11 11:47:07 +01:00
this . HistoryUtils . transitionTo ( this . DiscordConstants . Routes . CHANNEL ( noteData . guild _id , noteData . channel _id , noteData . id ) ) ;
2019-01-12 15:07:06 +01:00
} ) ;
2019-01-17 23:48:29 +01:00
message . querySelector ( BDFDB . dotCN . messagespopoutjumpbutton + ".copy" ) . addEventListener ( "click" , e => {
2019-01-12 15:07:06 +01:00
let clipboard = require ( "electron" ) . clipboard ;
2019-02-03 19:02:15 +01:00
if ( noteData . content ) {
let text = noteData . content ;
for ( let file of message . querySelectorAll ( BDFDB . dotCN . filenamelink ) ) text += ( "\n" + file . href ) ;
clipboard . write ( { text } ) ;
}
2019-01-12 15:07:06 +01:00
else {
let image = message . querySelector ( BDFDB . dotCNS . imagewrapper + "img" ) ;
2019-02-03 19:02:15 +01:00
if ( image ) require ( "request" ) ( { url : image . src , encoding : null } , ( error , response , buffer ) => {
if ( buffer ) {
let platform = require ( "process" ) . platform ;
if ( platform === "win32" || platform === "darwin" ) {
clipboard . write ( { image : require ( "electron" ) . nativeImage . createFromBuffer ( buffer ) } ) ;
2019-01-12 15:07:06 +01:00
}
2019-02-03 19:02:15 +01:00
else {
let file = require ( "path" ) . join ( require ( "process" ) . env [ "HOME" ] , "personalpinstemp.png" ) ;
require ( "fs" ) . writeFileSync ( file , buffer , { encoding : null } ) ;
clipboard . write ( { image : file } ) ;
require ( "fs" ) . unlinkSync ( file ) ;
}
}
} ) ;
2019-01-12 15:07:06 +01:00
}
} ) ;
}
2019-01-26 22:45:19 +01:00
2019-01-22 10:50:42 +01:00
startYoutubeVideo ( button ) {
let embedwrapper = BDFDB . getParentEle ( BDFDB . dotCN . embedvideo , button ) ;
let ytlink = embedwrapper . parentElement . querySelector ( BDFDB . dotCN . embedtitle ) . href ;
require ( "request" ) ( ytlink , ( error , response , result ) => {
if ( result && response . headers && typeof response . headers . server == "string" && response . headers . server . toUpperCase ( ) == "YOUTUBE FRONTEND PROXY" ) {
while ( embedwrapper . firstChild ) embedwrapper . firstChild . remove ( ) ;
let width = 400 ;
let height = Math . round ( width * ( result . split ( '<meta itemprop="height" content="' ) [ 1 ] . split ( '"' ) [ 0 ] / result . split ( '<meta itemprop="width" content="' ) [ 1 ] . split ( '"' ) [ 0 ] ) ) ;
embedwrapper . appendChild ( BDFDB . htmlToElement ( ` <iframe src=" ${ result . split ( '<link itemprop="embedURL" href="' ) [ 1 ] . split ( '"' ) [ 0 ] } ?start=0&autoplay=1&auto_play=1" width=" ${ width } " height=" ${ height } " frameborder="0" allowfullscreen=""></iframe> ` ) ) ;
}
} ) ;
}
2019-01-26 22:45:19 +01:00
2019-01-12 15:07:06 +01:00
addMessageToNotes ( message , target , channel ) {
if ( ! message || ! target ) return ;
let { messagediv , pos } = this . getMessageAndPos ( target ) ;
if ( ! messagediv || pos == - 1 ) return ;
let pins = BDFDB . loadAllData ( this , "pins" ) ;
let guild = this . GuildUtils . getGuild ( channel . guild _id ) || { } ;
let guild _id = guild . id ? guild . id : "@me" ;
channel = channel ? channel : this . ChannelUtils . getChannel ( message . channel _id ) ;
pins [ guild _id ] = pins [ guild _id ] || { }
pins [ guild _id ] [ channel . id ] = pins [ guild _id ] [ channel . id ] || { }
if ( ! pins [ guild _id ] [ channel . id ] [ message . id + "_" + pos ] ) {
2019-02-03 19:02:15 +01:00
for ( let spoiler of messagediv . querySelectorAll ( BDFDB . dotCN . spoilerhidden ) ) spoiler . click ( ) ;
2019-01-12 15:07:06 +01:00
let channelname = channel . name ;
if ( ! channelname && channel . recipients . length > 0 ) {
for ( let dmuser _id of channel . recipients ) {
channelname = channelname ? channelname + ", @" : channelname ;
channelname = channelname + this . UserUtils . getUser ( dmuser _id ) . username ;
2018-12-28 14:28:50 +01:00
}
}
2019-01-12 15:07:06 +01:00
let markup = messagediv . querySelector ( BDFDB . dotCN . messagemarkup ) . cloneNode ( true ) ;
markup . querySelectorAll ( BDFDB . dotCN . messageheadercompact ) . forEach ( h2 => { h2 . remove ( ) ; } ) ;
pins [ guild _id ] [ channel . id ] [ message . id + "_" + pos ] = BDFDB . sortObject ( {
"guild_id" : guild _id ,
"guild_name" : guild . name ? guild . name : "Direct Messages" ,
"channel_id" : channel . id ,
"channel_name" : channelname ,
"dmuser_id" : channel . type == 1 ? channel . recipients [ 0 ] : null ,
"id" : message . id ,
"pos" : pos ,
"timestamp" : message . timestamp . _i . getTime ( ) ,
"addedat" : new Date ( ) . getTime ( ) ,
"color" : message . colorString ,
"author_id" : message . author . id ,
"author_name" : message . author . username ,
"avatar" : BDFDB . getUserAvatar ( message . author . id ) ,
"content" : message . content ,
"markup" : markup . innerHTML ,
"accessory" : messagediv . querySelector ( BDFDB . dotCN . messageaccessory ) . innerHTML
} ) ;
BDFDB . saveAllData ( pins , this , "pins" ) ;
BDFDB . showToast ( this . labels . toast _noteadd _text , { type : "success" } ) ;
2018-12-28 14:28:50 +01:00
}
2019-01-12 15:07:06 +01:00
else this . removeNoteData ( pins [ guild _id ] [ channel . id ] [ message . id + "_" + pos ] ) ;
2018-12-28 14:28:50 +01:00
}
2019-01-26 22:45:19 +01:00
2019-01-12 15:07:06 +01:00
getNoteData ( message , target , channel ) {
if ( ! message || ! target ) return ;
let { messagediv , pos } = this . getMessageAndPos ( target ) ;
if ( ! messagediv || pos == - 1 ) return ;
channel = channel ? channel : this . ChannelUtils . getChannel ( message . channel _id ) ;
2019-01-02 10:09:39 +01:00
let pins = BDFDB . loadAllData ( this , "pins" ) ;
let guildid = channel . guild _id ? channel . guild _id : "@me" ;
return pins [ guildid ] && pins [ guildid ] [ channel . id ] && pins [ guildid ] [ channel . id ] [ message . id + "_" + pos ] ? pins [ guildid ] [ channel . id ] [ message . id + "_" + pos ] : null ;
}
2019-01-26 22:45:19 +01:00
2019-01-12 15:07:06 +01:00
removeNoteData ( noteData ) {
2018-12-28 14:28:50 +01:00
let pins = BDFDB . loadAllData ( this , "pins" ) ;
2019-01-12 15:07:06 +01:00
delete pins [ noteData . guild _id ] [ noteData . channel _id ] [ noteData . id + "_" + noteData . pos ] ;
if ( BDFDB . isObjectEmpty ( pins [ noteData . guild _id ] [ noteData . channel _id ] ) ) {
delete pins [ noteData . guild _id ] [ noteData . channel _id ] ;
if ( BDFDB . isObjectEmpty ( pins [ noteData . guild _id ] ) ) delete pins [ noteData . guild _id ] ;
2018-12-28 14:28:50 +01:00
}
BDFDB . saveAllData ( pins , this , "pins" ) ;
BDFDB . showToast ( this . labels . toast _noteremove _text , { type : "danger" } ) ;
}
2019-01-26 22:45:19 +01:00
2019-01-12 15:07:06 +01:00
getMessageAndPos ( target ) {
let messagediv = BDFDB . getParentEle ( BDFDB . dotCN . message , target ) ;
2019-01-17 23:48:29 +01:00
let pos = messagediv ? Array . from ( messagediv . parentElement . querySelectorAll ( BDFDB . dotCN . message ) ) . indexOf ( messagediv ) : - 1 ;
2019-01-12 15:07:06 +01:00
return { messagediv , pos } ;
}
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
setLabelsByLanguage ( ) {
switch ( BDFDB . getDiscordLanguage ( ) . id ) {
case "hr" : //croatian
return {
popout _note _text : "Bilješke" ,
popout _channel _text : "Kanal" ,
popout _server _text : "Poslužavnik" ,
popout _allservers _text : "Svi poslužitelji" ,
popout _sort _text : "Poredaj po" ,
popout _messagesort _text : "Vijesti-Datum" ,
popout _datesort _text : "Bilješka-Datum" ,
popout _jump _text : "Skok" ,
popout _copy _text : "Kopija" ,
context _pinoption _text : "Napominjemo poruku" ,
context _unpinoption _text : "Uklonite bilješku" ,
popout _pinoption _text : "Bilješka" ,
toast _noteadd _text : "Poruka dodana u bilježnicu." ,
toast _noteremove _text : "Poruka uklonjena iz bilježnice."
} ;
case "da" : //danish
return {
popout _note _text : "Noter" ,
popout _channel _text : "Kanal" ,
popout _server _text : "Server" ,
popout _allservers _text : "Alle servere" ,
popout _sort _text : "Sorter efter" ,
popout _messagesort _text : "Meddelelse-Dato" ,
popout _datesort _text : "Note-Dato" ,
popout _jump _text : "Hop" ,
popout _copy _text : "Kopi" ,
context _pinoption _text : "Noter besked" ,
context _unpinoption _text : "Fjern notatet" ,
popout _pinoption _text : "Noter" ,
toast _noteadd _text : "Meddelelse tilføjet til notesbog." ,
toast _noteremove _text : "Meddelelse fjernet fra notesbog."
} ;
case "de" : //german
return {
popout _note _text : "Notizen" ,
popout _channel _text : "Kanal" ,
popout _server _text : "Server" ,
popout _allservers _text : "Alle Server" ,
popout _sort _text : "Sortieren nach" ,
popout _messagesort _text : "Nachrichten-Datum" ,
popout _datesort _text : "Notiz-Datum" ,
popout _jump _text : "Springen" ,
popout _copy _text : "Kopieren" ,
context _pinoption _text : "Nachricht notieren" ,
context _unpinoption _text : "Notiz entfernen" ,
popout _pinoption _text : "Notieren" ,
toast _noteadd _text : "Nachricht zum Notizbuch hinzugefügt." ,
toast _noteremove _text : "Nachricht aus dem Notizbuch entfernt."
} ;
case "es" : //spanish
return {
popout _note _text : "Notas" ,
popout _channel _text : "Canal" ,
popout _server _text : "Servidor" ,
popout _allservers _text : "Todos los servidores" ,
popout _sort _text : "Ordenar por" ,
popout _messagesort _text : "Mensaje-Fecha" ,
popout _datesort _text : "Nota-Fecha" ,
popout _jump _text : "Ir a" ,
popout _copy _text : "Copiar" ,
context _pinoption _text : "Anotar mensaje" ,
context _unpinoption _text : "Quitar la nota" ,
popout _pinoption _text : "Anotar" ,
toast _noteadd _text : "Mensaje agregado al cuaderno." ,
toast _noteremove _text : "Mensaje eliminado del cuaderno."
} ;
case "fr" : //french
return {
popout _note _text : "Notes" ,
popout _channel _text : "Canal" ,
popout _server _text : "Serveur" ,
popout _allservers _text : "Tous les serveurs" ,
popout _sort _text : "Trier par" ,
popout _messagesort _text : "Message-Date" ,
popout _datesort _text : "Note-Date" ,
popout _jump _text : "Accéder" ,
popout _copy _text : "Copier" ,
context _pinoption _text : "Noter le message" ,
context _unpinoption _text : "Enlevez la note" ,
popout _pinoption _text : "Noter" ,
toast _noteadd _text : "Message ajouté au bloc-notes." ,
toast _noteremove _text : "Message supprimé du bloc-notes."
} ;
case "it" : //italian
return {
popout _note _text : "Note" ,
popout _channel _text : "Canale" ,
popout _server _text : "Server" ,
popout _allservers _text : "Tutti i server" ,
popout _sort _text : "Ordina per" ,
popout _messagesort _text : "Messaggio-Data" ,
popout _datesort _text : "Nota-Data" ,
popout _jump _text : "Vai" ,
popout _copy _text : "Copiare" ,
context _pinoption _text : "Annotare il messaggio" ,
context _unpinoption _text : "Rimuovi la nota" ,
popout _pinoption _text : "Annotare" ,
toast _noteadd _text : "Messaggio aggiunto al blocco note." ,
toast _noteremove _text : "Messaggio rimosso dal blocco note."
} ;
case "nl" : //dutch
return {
popout _note _text : "Notities" ,
popout _channel _text : "Kanaal" ,
popout _server _text : "Server" ,
popout _allservers _text : "Alle servers" ,
popout _sort _text : "Sorteer op" ,
popout _messagesort _text : "Bericht-Datum" ,
popout _datesort _text : "Notitie-Datum" ,
popout _jump _text : "Openen" ,
popout _copy _text : "Kopiëren" ,
context _pinoption _text : "Noteer bericht" ,
context _unpinoption _text : "Verwijder de notitie" ,
popout _pinoption _text : "Noteer" ,
toast _noteadd _text : "Bericht toegevoegd aan notitieblok." ,
toast _noteremove _text : "Bericht verwijderd van notitieblok."
} ;
case "no" : //norwegian
return {
popout _note _text : "Notatene" ,
popout _channel _text : "Kanal" ,
popout _server _text : "Server" ,
popout _allservers _text : "Alle servere" ,
popout _sort _text : "Sorter etter" ,
popout _messagesort _text : "Melding-Dato" ,
popout _datesort _text : "Merknad-Dato" ,
popout _jump _text : "Hoppe" ,
popout _copy _text : "Kopiere" ,
context _pinoption _text : "Notat ned meldingen" ,
context _unpinoption _text : "Fjern notatet" ,
popout _pinoption _text : "Notere" ,
toast _noteadd _text : "Melding lagt til i notisboken." ,
toast _noteremove _text : "Melding fjernet fra notatboken."
} ;
case "pl" : //polish
return {
popout _note _text : "Notatki" ,
popout _channel _text : "Kanał" ,
popout _server _text : "Serwer" ,
popout _allservers _text : "Wszystkie serwery" ,
popout _sort _text : "Sortuj według" ,
popout _messagesort _text : "Wiadomość-Data" ,
popout _datesort _text : "Notatka-Data" ,
popout _jump _text : "Skocz" ,
popout _copy _text : "Kopiować" ,
context _pinoption _text : "Notuj wiadomość" ,
context _unpinoption _text : "Usuń notatkę" ,
popout _pinoption _text : "Notuj" ,
toast _noteadd _text : "Wiadomość została dodana do notatnika." ,
toast _noteremove _text : "Wiadomość została usunięta z notatnika."
} ;
case "pt-BR" : //portuguese (brazil)
return {
popout _note _text : "Notas" ,
popout _channel _text : "Canal" ,
popout _server _text : "Servidor" ,
popout _allservers _text : "Todos os servidores" ,
popout _sort _text : "Ordenar por" ,
popout _messagesort _text : "Mensagem-Data" ,
popout _datesort _text : "Nota-Data" ,
popout _jump _text : "Pular" ,
popout _copy _text : "Copiar" ,
context _pinoption _text : "Anote a mensagem" ,
context _unpinoption _text : "Remova a nota" ,
popout _pinoption _text : "Anotar" ,
toast _noteadd _text : "Mensagem adicionada ao caderno." ,
toast _noteremove _text : "Mensagem removida do caderno."
} ;
case "fi" : //finnish
return {
popout _note _text : "Muistiinpanot" ,
popout _channel _text : "Kanava" ,
popout _server _text : "Palvelin" ,
popout _allservers _text : "Kaikki palvelimet" ,
popout _sort _text : "Järjestä" ,
popout _messagesort _text : "Viesti-Päivämäärä" ,
popout _datesort _text : "Huomaa-Päivämäärä" ,
popout _jump _text : "Siirry" ,
popout _copy _text : "Kopioida" ,
context _pinoption _text : "Huomaa viesti" ,
context _unpinoption _text : "Poista muistiinpano" ,
popout _pinoption _text : "Huomaa" ,
toast _noteadd _text : "Viesti lisätty muistikirjaan." ,
toast _noteremove _text : "Viesti poistettiin muistikirjaan."
} ;
case "sv" : //swedish
return {
popout _note _text : "Anteckningarna" ,
popout _channel _text : "Kanal" ,
popout _server _text : "Server" ,
popout _allservers _text : "Alla servrar" ,
popout _sort _text : "Sortera efter" ,
popout _messagesort _text : "Meddelande-Datum" ,
popout _datesort _text : "Anteckningen-Datum" ,
popout _jump _text : "Hoppa" ,
popout _copy _text : "Kopiera" ,
context _pinoption _text : "Anteckna meddelande" ,
context _unpinoption _text : "Ta bort noten" ,
popout _pinoption _text : "Anteckna" ,
toast _noteadd _text : "Meddelandet läggs till i anteckningsboken." ,
toast _noteremove _text : "Meddelande borttaget från anteckningsboken."
} ;
case "tr" : //turkish
return {
popout _note _text : "Notlar" ,
popout _channel _text : "Kanal" ,
popout _server _text : "Sunucu" ,
popout _allservers _text : "Tüm Sunucular" ,
popout _sort _text : "Göre sı rala" ,
popout _messagesort _text : "Mesaj-Tarih" ,
popout _datesort _text : "Not-Tarih" ,
popout _jump _text : "Git" ,
popout _copy _text : "Kopyalamak" ,
context _pinoption _text : "Mesajı not alı n" ,
context _unpinoption _text : "Notu kaldı rmak" ,
popout _pinoption _text : "Not almak" ,
toast _noteadd _text : "Mesaj not defteri'ya eklendi." ,
toast _noteremove _text : "Mesaj not defteri'dan kaldı rı ldı ."
} ;
case "cs" : //czech
return {
popout _note _text : "Poznámky" ,
popout _channel _text : "Kanál" ,
popout _server _text : "Server" ,
popout _allservers _text : "Všechny servery" ,
popout _sort _text : "Seřazeno podle" ,
popout _messagesort _text : "Zpráva-datum" ,
popout _datesort _text : "Poznámka-datum" ,
popout _jump _text : "Skok" ,
popout _copy _text : "Kopírovat" ,
context _pinoption _text : "Poznámka dolů zprávu" ,
context _unpinoption _text : "Odstraňte poznámku" ,
popout _pinoption _text : "Poznámka dolů" ,
toast _noteadd _text : "Zpráva byla přidána do notebooku." ,
toast _noteremove _text : "Zpráva byla odebrána z notebooku."
} ;
case "bg" : //bulgarian
return {
popout _note _text : "бележките" ,
popout _channel _text : "Канал" ,
popout _server _text : "Сървър" ,
popout _allservers _text : "Всички сървъри" ,
popout _sort _text : "Сортиране по" ,
popout _messagesort _text : "Съобщение-Дата" ,
popout _datesort _text : "Забележка-Дата" ,
popout _jump _text : "Направо" ,
popout _copy _text : "Копирам" ,
context _pinoption _text : "Oтб е ле же те съобщението" ,
context _unpinoption _text : "Премахнете бележката" ,
popout _pinoption _text : "Oтб е ле же те " ,
toast _noteadd _text : "Съобщението б е добавено към бележника." ,
toast _noteremove _text : "Съобщението е премахнато от преносимия компютър."
} ;
case "ru" : //russian
return {
popout _note _text : "Заметки" ,
popout _channel _text : "Канал" ,
popout _server _text : "Cе р ве р " ,
popout _allservers _text : "В с е серверы" ,
popout _sort _text : "Сортировать по" ,
popout _messagesort _text : "Сообщение-дата" ,
popout _datesort _text : "Заметки-Дата" ,
popout _jump _text : "Перейти" ,
popout _copy _text : "Копировать" ,
context _pinoption _text : "Записывать вниз" ,
context _unpinoption _text : "Удалить заметку" ,
popout _pinoption _text : "Записывать" ,
toast _noteadd _text : "Сообщение добавлено в блокнот." ,
toast _noteremove _text : "Сообщение удалено из записной книжки."
} ;
case "uk" : //ukrainian
return {
popout _note _text : "Замітки" ,
popout _channel _text : "Канал" ,
popout _server _text : "Сервер" ,
popout _allservers _text : "В с і сервери" ,
popout _sort _text : "Сортувати за" ,
popout _messagesort _text : "Повідомлення-дата" ,
popout _datesort _text : "Примітка-дата" ,
popout _jump _text : "Плиг" ,
popout _copy _text : "Копіювати" ,
context _pinoption _text : "Зверніть увагу на повідомлення" ,
context _unpinoption _text : "Видаліть нотатку" ,
popout _pinoption _text : "Занотуйте" ,
toast _noteadd _text : "Повідомлення додається до ноутбука." ,
toast _noteremove _text : "Повідомлення видалено з ноутбука."
} ;
case "ja" : //japanese
return {
popout _note _text : "ノート" ,
popout _channel _text : "チャネル" ,
popout _server _text : "サーバ" ,
popout _allservers _text : "すべてのサーバー" ,
popout _sort _text : "並び替え" ,
popout _messagesort _text : "メッセージ-日付" ,
popout _datesort _text : "注-日付" ,
popout _jump _text : "ジャンプ" ,
popout _copy _text : "写す" ,
context _pinoption _text : "ノートダウンメッセージ" ,
context _unpinoption _text : "メモを削除" ,
popout _pinoption _text : "書き留める" ,
toast _noteadd _text : "ノートブックにメッセージが追加されました." ,
toast _noteremove _text : "ノートブックからメッセージが削除されました."
} ;
case "zh-TW" : //chinese (traditional)
return {
popout _note _text : "筆記" ,
popout _channel _text : "渠道" ,
popout _server _text : "服務器" ,
popout _allservers _text : "所有服務器" ,
popout _sort _text : "排序方式" ,
popout _messagesort _text : "消息-日期" ,
popout _datesort _text : "注-日期" ,
popout _jump _text : "跳到" ,
popout _copy _text : "複製" ,
context _pinoption _text : "記下下來的消息" ,
context _unpinoption _text : "刪除備註" ,
popout _pinoption _text : "記下" ,
toast _noteadd _text : "消息添加到筆記本." ,
toast _noteremove _text : "消息從筆記本中刪除."
} ;
case "ko" : //korean
return {
popout _note _text : "노트" ,
popout _channel _text : "채널" ,
popout _server _text : "섬기는 사람" ,
popout _allservers _text : "모든 서버" ,
popout _sort _text : "정렬 기준" ,
popout _messagesort _text : "메시지-날짜" ,
popout _datesort _text : "주-날짜" ,
popout _jump _text : "이동" ,
popout _copy _text : "베끼다" ,
context _pinoption _text : "메모 다운 메시지" ,
context _unpinoption _text : "메모 삭제" ,
popout _pinoption _text : "메모하다" ,
toast _noteadd _text : "노트북에 메시지 추가됨." ,
toast _noteremove _text : "노트에서 메시지 삭제됨."
} ;
default : //default: english
return {
popout _note _text : "Notes" ,
popout _channel _text : "Channel" ,
popout _server _text : "Server" ,
popout _allservers _text : "All Servers" ,
popout _sort _text : "Sort by" ,
popout _messagesort _text : "Message-Date" ,
popout _datesort _text : "Note-Date" ,
popout _jump _text : "Jump" ,
popout _copy _text : "Copy" ,
context _pinoption _text : "Note Message" ,
context _unpinoption _text : "Remove Note" ,
popout _pinoption _text : "Note" ,
toast _noteadd _text : "Message added to notebook." ,
toast _noteremove _text : "Message removed from notebook."
} ;
}
}
}