1 line
15 KiB
JavaScript
1 line
15 KiB
JavaScript
(function(P,g,e,w,t,S,z,p,m,c){"use strict";var y={Failed:p.getAssetIDByName("Small"),Delete:p.getAssetIDByName("ic_message_delete"),Copy:p.getAssetIDByName("toast_copy_link"),Open:p.getAssetIDByName("ic_leave_stage"),Clipboard:p.getAssetIDByName("pending-alert"),Clock:p.getAssetIDByName("clock"),Forum:p.getAssetIDByName("ic_forum_channel"),Settings:{Toasts:{Settings:p.getAssetIDByName("ic_selection_checked_24px"),Failed:p.getAssetIDByName("ic_close_circle_24px")},Initial:p.getAssetIDByName("coffee"),Update:p.getAssetIDByName("discover"),Locale:p.getAssetIDByName("ic_locale_24px"),External:p.getAssetIDByName("ic_raised_hand_list"),Edit:p.getAssetIDByName("ic_edit_24px"),Reply:p.getAssetIDByName("ic_reply_24px"),Keyboard:p.getAssetIDByName("ic_keyboard_24px")}},b={shadow:function(a=.1){return{shadowColor:"#000",shadowOffset:{width:1,height:4},shadowOpacity:a,shadowRadius:4.65,elevation:8}},displayToast:function(a,r){e.toasts.open({content:r=="clipboard"?`Copied ${a} to clipboard.`:a,source:r=="clipboard"?y.Clipboard:y.Settings.Initial})}},A={plugin:{source:"https://github.com/MYSTRAVIL/vendetta-plugins"},author:{profile:{"Rosie<3":"https://github.com/acquitelol"}}};const{TouchableOpacity:v,View:N,Image:q,Text:L,Animated:C}=S.General,H=g.findByProps("transitionToGuild"),_=g.findByStoreName("UserStore"),X=g.findByProps("showUserProfile"),R=e.stylesheet.createThemedStyleSheet({container:{marginTop:25,marginLeft:"5%",marginBottom:-15,flexDirection:"row"},textContainer:{paddingLeft:15,paddingTop:5,flexDirection:"column",flexWrap:"wrap",...b.shadow()},image:{width:75,height:75,borderRadius:10,...b.shadow()},mainText:{opacity:.975,letterSpacing:.25},header:{color:m.semanticColors.HEADER_PRIMARY,fontFamily:e.constants.Fonts.DISPLAY_BOLD,fontSize:25,letterSpacing:.25},subHeader:{color:m.semanticColors.HEADER_SECONDARY,fontSize:12.75}});function J({name:a,authors:r}){const s=e.React.useRef(new C.Value(1)).current,n=function(){return C.spring(s,{toValue:1.1,duration:10,useNativeDriver:!0}).start()},i=function(){return C.spring(s,{toValue:1,duration:250,useNativeDriver:!0}).start()},l=function(){return X.showUserProfile({userId:_.getCurrentUser().id})},d={transform:[{scale:s}]};return e.React.createElement(e.React.Fragment,null,e.React.createElement(N,{style:R.container},e.React.createElement(v,{onPress:l,onPressIn:n,onPressOut:i},e.React.createElement(C.View,{style:d},e.React.createElement(q,{style:[R.image],source:{uri:_?.getCurrentUser()?.getAvatarURL()?.replace("webp","png")}}))),e.React.createElement(N,{style:R.textContainer},e.React.createElement(v,{onPress:function(){return H.openURL(A.plugin.source)}},e.React.createElement(L,{style:[R.mainText,R.header]},a)),e.React.createElement(N,{style:{flexDirection:"row"}},e.React.createElement(L,{style:[R.mainText,R.subHeader]},"A project by"),r.map(function(u,o,h){return e.React.createElement(v,{onPress:function(){return H.openURL(A.author.profile[u.name]??"https://github.com/")}},e.React.createElement(L,{style:[R.mainText,R.subHeader,{paddingLeft:4,fontFamily:e.constants.Fonts.DISPLAY_BOLD,flexDirection:"row"}]},u.name,o<h.length-1?",":null))})))))}const{View:Q,Text:Z}=S.General,K=e.stylesheet.createThemedStyleSheet({text:{color:m.semanticColors.HEADER_SECONDARY,paddingLeft:"5.5%",paddingRight:10,marginBottom:10,letterSpacing:.25,fontFamily:e.constants.Fonts.PRIMARY_BOLD,fontSize:12}});function V({label:a,children:r}){return e.React.createElement(Q,{style:{marginTop:10}},e.React.createElement(Z,{style:[K.text,K.optionText]},a.toUpperCase()),r)}const{FormRow:f,FormSwitch:M,FormDivider:I,FormInput:ee,FormText:te}=S.Forms,{ScrollView:ae,View:x,Text:re}=S.General,T=e.stylesheet.createThemedStyleSheet({icon:{color:m.semanticColors.INTERACTIVE_NORMAL},item:{color:m.semanticColors.TEXT_MUTED,fontFamily:e.constants.Fonts.PRIMARY_MEDIUM},container:{width:"90%",marginLeft:"5%",borderRadius:10,backgroundColor:m.semanticColors.BACKGROUND_MOBILE_SECONDARY,...b.shadow()},subheaderText:{color:m.semanticColors.HEADER_SECONDARY,textAlign:"center",margin:10,marginBottom:50,letterSpacing:.25,fontFamily:e.constants.Fonts.PRIMARY_BOLD,fontSize:14},image:{width:"100%",maxWidth:350,borderRadius:10}});function se(){t.storage.tapUsernameMention===void 0&&(t.storage.tapUsernameMention=!1),t.storage.reply===void 0&&(t.storage.reply=!0),t.storage.userEdit===void 0&&(t.storage.userEdit=!0),t.storage.keyboardPopup===void 0&&(t.storage.keyboardPopup=!0),t.storage.delay===void 0&&(t.storage.delay="1000"),z.useProxy(t.storage);const a=e.ReactNative.Platform.OS==="android",r=function(n){/^\d*$/.test(n)&&(t.storage.delay=n)},s=function(){try{e.ReactNative.Linking&&e.ReactNative.Linking.openURL?e.ReactNative.Linking.openURL(A.plugin.source):b.displayToast("Cannot open URL: Linking not available","error")}catch(n){b.displayToast("Error opening URL","error"),console.error("Error opening URL:",n)}};return e.React.createElement(ae,null,e.React.createElement(J,{name:t.manifest.name,authors:t.manifest.authors}),e.React.createElement(x,{style:{marginTop:20}},e.React.createElement(V,{label:"Preferences"},e.React.createElement(x,{style:[T.container]},e.React.createElement(f,{label:"Tap Username to Mention",subLabel:`Allows you to tap on a username to mention them instead of opening their profile.${a?" This option is disabled on Android.":""}`,onLongPress:function(){return b.displayToast("By default, Discord opens a profile when tapping on a username in chat. With this, it now mentions them, like on Android.","tooltip")},leading:e.React.createElement(f.Icon,{style:T.icon,source:t.storage.tapUsernameMention?y.Forum:y.Failed}),trailing:e.React.createElement(M,{value:a?!1:t.storage.tapUsernameMention,onValueChange:function(){a||(t.storage.tapUsernameMention=!t.storage.tapUsernameMention)}}),disabled:a}),e.React.createElement(I,null),e.React.createElement(f,{label:"Double Tap To Reply",subLabel:"Allows you to double tap on any messages to reply to them.",onLongPress:function(){return b.displayToast("Double tapping anyones message allows you to reply to them!","tooltip")},leading:e.React.createElement(f.Icon,{style:T.icon,source:t.storage.reply?y.Settings.Reply:y.Failed}),trailing:e.React.createElement(M,{value:t.storage.reply,onValueChange:function(){t.storage.reply=!t.storage.reply}})}),e.React.createElement(I,null),e.React.createElement(f,{label:"Open Keyboard Automatically",subLabel:"Opens the Keyboard when you reply to or edit a message with a double tap.",onLongPress:function(){return b.displayToast("Opens the Keyboard when you reply to or edit a message with a double tap.","tooltip")},leading:e.React.createElement(f.Icon,{style:T.icon,source:t.storage.keyboardPopup?y.Settings.Keyboard:y.Failed}),trailing:e.React.createElement(M,{value:t.storage.keyboardPopup,onValueChange:function(){t.storage.keyboardPopup=!t.storage.keyboardPopup}})}),e.React.createElement(I,null),e.React.createElement(f,{label:`${t.storage.userEdit?"Double tap to edit":"Double tap to reply to"} your own messages`,subLabel:`Allows you to double tap on any of your own messages to ${t.storage.userEdit?"edit":"reply to"} them.`,onLongPress:function(){return b.displayToast(`When double tapping on any of your own messages, you can now ${t.storage.userEdit?"edit them":"reply to them"}!`,"tooltip")},leading:e.React.createElement(f.Icon,{style:T.icon,source:t.storage.userEdit?y.Settings.Edit:y.Settings.Reply}),trailing:e.React.createElement(M,{value:t.storage.userEdit,onValueChange:function(){t.storage.userEdit=!t.storage.userEdit}})}),e.React.createElement(I,null),e.React.createElement(ee,{value:t.storage.delay,onChange:r,placeholder:"1000",title:"Maximum Delay",keyboardType:"numeric"}),e.React.createElement(I,null),e.React.createElement(te,{style:{padding:10}},"The maximum delay between taps until the double tap event is cancelled. This is 300ms by default."))),e.React.createElement(V,{label:"Source"},e.React.createElement(x,{style:T.container},e.React.createElement(f,{label:"Source",subLabel:`Open the repository of ${t.manifest.name} externally.`,onLongPress:function(){return b.displayToast(`Opens the repository of ${t.manifest.name} on GitHub in an external page to view any source code of the plugin.`,"tooltip")},leading:e.React.createElement(f.Icon,{style:T.icon,source:y.Open}),trailing:function(){return e.React.createElement(f.Arrow,null)},onPress:s})))),e.React.createElement(re,{style:T.subheaderText},`Build: (${t.manifest.hash?.substring(0,8)||"dev"}`))}const U=g.findByProps("insertText"),Y=g.findByStoreName("ChannelStore"),O=g.findByStoreName("MessageStore"),F=g.findByStoreName("UserStore"),W=g.findByProps("sendMessage","startEditMessage"),G=g.findByProps("createPendingReply");let B;try{B=g.findByProps("MessagesHandlers")}catch{c.logger.warn("BetterChatGestures: Could not find MessagesHandlers via findByProps")}if(!B)try{const a=window.vendetta?.metro?.cache||new Map;for(const[r,s]of a)if(s?.exports?.MessagesHandlers){B=s.exports,c.logger.log("BetterChatGestures: Found MessagesHandlers via cache iteration");break}}catch(a){c.logger.error("BetterChatGestures: Failed to find MessagesHandlers via cache",a)}const D=B?.MessagesHandlers,ne={unpatchGetter:null,unpatchHandlers:null,currentTapIndex:0,currentMessageID:null,timeoutTap:null,patches:[],handlersInstances:new WeakSet,doubleTapState({state:a="UNKNOWN",nativeEvent:r}){try{const s={state:a,data:r};a==="INCOMPLETE"&&r&&Object.assign(s,{reason:{required:{taps:2,isAuthor:!0},received:{taps:r.taps,isAuthor:r.isAuthor}}});const n=F?.getCurrentUser();n&&t.manifest.authors.find(function(i){return i.id===n.id})&&console.log("DoubleTapState",s)}catch(s){c.logger.error("BetterChatGestures: Error in doubleTapState",s)}},resetTapState(){try{this.timeoutTap&&(clearTimeout(this.timeoutTap),this.timeoutTap=null),this.currentTapIndex=0,this.currentMessageID=null}catch(a){c.logger.error("BetterChatGestures: Error in resetTapState",a)}},openKeyboard(){if(t.storage.keyboardPopup)try{const a=g.findByProps("openSystemKeyboard");if(a?.openSystemKeyboard){a.openSystemKeyboard();return}if(a?.openSystemKeyboardForLastCreatedInput){a.openSystemKeyboardForLastCreatedInput();return}const r=U?.refs?.[0]?.current;if(r?.focus){r.focus();return}e.ReactNative.Keyboard?.dismiss&&setTimeout(function(){r?.focus&&r.focus()},50)}catch(a){t.storage.debugMode&&c.logger.error("BetterChatGestures: Error opening keyboard",a)}},patchHandlers(a){var r=this;if(!this.handlersInstances.has(a)){this.handlersInstances.add(a);try{if(a.handleDoubleTapMessage){const s=w.instead("handleDoubleTapMessage",a,function(n,i){try{if(!n?.[0]?.nativeEvent)return;const{nativeEvent:l}=n[0],d=l.channelId,u=l.messageId;if(!d||!u)return;const o=Y?.getChannel(d),h=O?.getMessage(d,u);if(!h)return;const E=F?.getCurrentUser();E&&h.author&&h.author.id===E.id&&t.storage.userEdit?W?.startEditMessage(d,u,h.content||""):t.storage.reply&&o&&G?.createPendingReply({channel:o,message:h,shouldMention:!0}),r.openKeyboard();return}catch(l){c.logger.error("BetterChatGestures: Error in handleDoubleTapMessage patch",l)}});this.patches.push(s)}if(a.handleTapUsername&&t.storage.tapUsernameMention){const s=w.instead("handleTapUsername",a,function(n,i){try{if(!t.storage.tapUsernameMention||!n?.[0]?.nativeEvent)return i.apply(a,n);const l=U?.refs?.[0]?.current,{messageId:d}=n[0].nativeEvent;if(!l?.props?.channel?.id)return i.apply(a,n);const u=O.getMessage(l.props.channel.id,d);if(!u?.author)return i.apply(a,n);const o=u.author.discriminator!=="0"?`#${u.author.discriminator}`:"";U.insertText(`@${u.author.username}${o}`)}catch(l){return c.logger.error("BetterChatGestures: Error in handleTapUsername patch",l),i.apply(a,n)}});this.patches.push(s)}if(a.handleTapMessage){const s=w.after("handleTapMessage",a,function(n){try{if(!n?.[0])return;const{nativeEvent:i}=n[0];if(!i)return;const l=i.channelId,d=i.messageId;if(!l||!d)return;const u=Y?.getChannel(l),o=O?.getMessage(l,d);if(!o)return;r.currentMessageID===d?r.currentTapIndex++:(r.resetTapState(),r.currentTapIndex=1,r.currentMessageID=d);let h=1e3;if(t.storage.delay){const $=parseInt(t.storage.delay,10);!isNaN($)&&$>=200&&(h=$)}r.timeoutTap&&clearTimeout(r.timeoutTap),r.timeoutTap=setTimeout(function(){r.resetTapState()},h);const E=F?.getCurrentUser(),j=E&&o.author?o.author.id===E.id:!1,k={...i,taps:r.currentTapIndex,content:o.content||"",authorId:o.author?.id,isAuthor:j};if(r.currentTapIndex!==2){r.doubleTapState({state:"INCOMPLETE",nativeEvent:k});return}const oe=r.currentMessageID;r.resetTapState(),j?t.storage.userEdit?W?.startEditMessage(l,oe,k.content):t.storage.reply&&u&&G?.createPendingReply({channel:u,message:o,shouldMention:!0}):t.storage.reply&&u&&G?.createPendingReply({channel:u,message:o,shouldMention:!0}),r.openKeyboard(),r.doubleTapState({state:"COMPLETE",nativeEvent:k})}catch(i){c.logger.error("BetterChatGestures: Error in handleTapMessage patch",i),r.resetTapState()}});this.patches.push(s)}this.unpatchHandlers=function(){try{r.patches.forEach(function(s){typeof s=="function"&&s()}),r.patches=[],r.handlersInstances=new WeakSet}catch(s){c.logger.error("BetterChatGestures: Error in unpatchHandlers",s)}}}catch(s){c.logger.error("BetterChatGestures: Error in patchHandlers",s)}}},onLoad(){var a,r,s,n,i,l;try{if(!D){c.logger.error("BetterChatGestures: MessagesHandlers module not found! Plugin will not work.");return}(a=t.storage).tapUsernameMention??(a.tapUsernameMention=e.ReactNative.Platform.select({android:!1,ios:!0,default:!0})),e.ReactNative.Platform.OS==="android"&&(t.storage.tapUsernameMention=!1),(r=t.storage).reply??(r.reply=!0),(s=t.storage).userEdit??(s.userEdit=!0),(n=t.storage).keyboardPopup??(n.keyboardPopup=!0),(i=t.storage).delay??(i.delay="1000"),(l=t.storage).debugMode??(l.debugMode=!1),(!t.storage.delay||t.storage.delay===""||isNaN(parseInt(t.storage.delay,10))||parseInt(t.storage.delay,10)<200)&&(t.storage.delay="1000"),c.logger.log("BetterChatGestures: initialized with delay =",t.storage.delay);const d=this,u=["params","handlers","_params","messageHandlers"];let o=null,h=null;for(const E of u)if(o=Object.getOwnPropertyDescriptor(D.prototype,E)?.get,o){h=E,c.logger.log(`BetterChatGestures: Found property '${E}'`);break}o&&h?(Object.defineProperty(D.prototype,h,{configurable:!0,get(){return this&&d.patchHandlers.call(d,this),o.call(this)}}),this.unpatchGetter=function(){try{o&&h&&Object.defineProperty(D.prototype,h,{configurable:!0,get:o})}catch(E){c.logger.error("BetterChatGestures: Error in unpatchGetter",E)}}):c.logger.error("BetterChatGestures: Could not find params getter!")}catch(d){c.logger.error("BetterChatGestures: Error in onLoad",d)}},onUnload(){try{this.resetTapState(),this.unpatchGetter&&this.unpatchGetter(),this.unpatchHandlers&&this.unpatchHandlers(),this.timeoutTap&&(clearTimeout(this.timeoutTap),this.timeoutTap=null)}catch(a){c.logger.error("BetterChatGestures: Error in onUnload",a)}},settings:se};return P.default=ne,Object.defineProperty(P,"__esModule",{value:!0}),P})({},vendetta.metro,vendetta.metro.common,vendetta.patcher,vendetta.plugin,vendetta.ui.components,vendetta.storage,vendetta.ui.assets,vendetta.ui,vendetta);
|