1 line
18 KiB
JavaScript
1 line
18 KiB
JavaScript
(function(Q,ze,He,c,A,o,Me,p,x,u,Ve,k,I,Ge){"use strict";function We(e,t,n,i){try{return n()}catch(r){return i.error(`[${e}] Failed to apply the "${t}" patch, that surface will be skipped: ${r}`),function(){}}}function Ke(e,t,n){const i=Object.entries(n).map(function([r,l]){return We(e,r,l,t)});return function(){return i.forEach(function(r){return r()})}}const z=He.FluxDispatcher,je=c.findByStoreName("CollectiblesPurchaseStore"),Z=c.findByStoreName("ProfileEffectStore"),N=c.findByStoreName("UserProfileStore"),v=c.findByStoreName("UserStore"),Xe=Me.semanticColors,Ye=c.find(function(e){return e.default?.internal?.resolveSemanticColor})?.default.internal.resolveSemanticColor??c.find(function(e){return e.meta?.resolveSemanticColor})?.meta.resolveSemanticColor??function(){};function U(e,t,n){for(const i of t){const r=Xe?.[i];if(r)try{const l=Ye(e,r);if(l)return l}catch{}}return n}const Qe=c.findByProps("useAvatarColors")?.useAvatarColors??function(){},me=c.findByProps("getProfileTheme")?.getProfileTheme??function(e){return e==null?null:"dark"},q=c.findByProps("useThemeContext")?.useThemeContext??function(){return{}},Ze=c.findByProps("ThemeContextProvider")?.ThemeContextProvider??function({children:e}){return e};function J(){z.dispatch({type:"USER_SETTINGS_ACCOUNT_SUBMIT_SUCCESS"})}let _=!0;function qe(e){const[t,n]=o.useState(function(){return _=e});return[t,function(i){n(_=i),J()}]}let S=null;function Je(e){const[t,n]=o.useState(function(){return S=e});return[t,function(i){n(S=i),_&&J()}]}let E=null;function $e(e){const[t,n]=o.useState(function(){return E=e});return[t,function(i){n(E=i),_&&J()}]}let O;function $(e){O=e}const et=function(){let e=c.findByName("useProfileTheme",!1);return e?function(){return A.after("default",e,function([t],n){const{user:i}=t;return(i!=null&&i.id===O||"pendingThemeColors"in t)&&_&&(S!==null?(n.theme=me(S),n.primaryColor=S,n.secondaryColor=E??S):E!==null&&(n.theme=me(E),n.primaryColor=E,n.secondaryColor=E)),n})}:(e=c.findByName("useProfileThemeColors",!1),e?function(){return A.after("default",e,function([t,n,i],r){if((t!=null&&t.id===O||i)&&_){if(S!==null)return[S,E??S];if(E!==null)return[E,E]}return r})}:function(){return function(){return!0}})}(),tt=function(){return A.instead("getPurchase",je,function(e,t){return O?{purchasedAt:new Date}:t(e)})},w=String.fromCodePoint(8203),b=4096,y=917504,ee=y+b-1;function te(e,t){return String.fromCodePoint(...[...`[#${e.toString(16)},#${t.toString(16)}]`].map(function(n){return n.codePointAt(0)+y}))}function pe(e){const[t,n]=e.matchAll(/(?<=#)[\dA-Fa-f]{1,6}/g);return[t?parseInt(t[0],16):-1,n?parseInt(n[0],16):-1]}function ne(e){if(e===0)return String.fromCodePoint(y);let t="";for(;e>0;e=Math.trunc(e/b))t=String.fromCodePoint(e%b+y)+t;return t}function L(e){if(e==="")return-1;let t=0;for(let n=0;n<e.length;n++){if(t>16777215)return-2;t+=e.codePointAt(n)*b**(e.length-1-n)}return t}function H(e){if(e===0n)return String.fromCodePoint(y);let t="";for(;e>0n;e/=BigInt(b))t=String.fromCodePoint(Number(e%BigInt(b))+y)+t;return t}function M(e){if(e==="")return-1n;let t=0n;for(let n=0;n<e.length;n++){if(t>=10000000000000000000n)return-2n;t+=BigInt(e.codePointAt(n))*BigInt(b)**BigInt(e.length-1-n)}return t}function nt(e,t,n,i){let r="";if(i){if(e>=0)return t>=0?r=te(e,t):r=te(e,e),n&&(r+=w+H(BigInt(n))),r;if(t>=0)return r=te(t,t),n&&(r+=w+H(BigInt(n))),r}else if(e>=0){if(r=ne(e),t>=0&&e!==t)return r+=w+ne(t),n&&(r+=w+H(BigInt(n))),r}else t>=0&&(r=ne(t));return n&&(r+=w+w+H(BigInt(n))),r}function re(e){const t=["","",""];let n=0;for(const i of e){const r=i.codePointAt(0);if(r===8203){if(n>=2)break;n++}else if(r>=y&&r<=ee)t[n]+=String.fromCodePoint(r-y);else if(n>0||t[0])break}return t}function he(e){for(const t of e){const n=t.codePointAt(0);if(n>=y&&n<=ee||n===8203)return!0}return!1}function Ee(e){return[...e].filter(function(t){const n=t.codePointAt(0);return(n<y||n>ee)&&n!==8203}).join("").trim()}function V(e,t,n){t>-1?(e.themeColors=[t,n>-1?n:t],e.premiumType=2):n>-1&&(e.themeColors=[n,n],e.premiumType=2)}function G(e,t){t>-1n&&(e.profileEffectId=e.profileEffectID=t.toString(),e.premiumType=2)}const rt=function(){return A.after("getUserProfile",N,function(e,t){if(!t||t.profileFetchFailed)return t;if(p.storage.prioritizeNitro){if(t.themeColors){if(!(t.profileEffectId||t.profileEffectID)){const r=re(t.bio);L(r[0])===-2?G(t,M(r[1])):G(t,M(r[2]))}return t}else if(t.profileEffectId||t.profileEffectID){const r=re(t.bio),l=L(r[0]);return l===-2?V(t,...pe(r[0])):V(t,l,L(r[1])),t}}const n=re(t.bio),i=L(n[0]);return i===-2?(V(t,...pe(n[0])),G(t,M(n[1]))):(V(t,i,L(n[1])),G(t,M(n[2]))),t})},oe=c.findByName("ProfileEffectRecord");(function(e){return e[e.AVATAR_DECORATION=0]="AVATAR_DECORATION",e[e.PROFILE_EFFECT=1]="PROFILE_EFFECT",e[e.NONE=100]="NONE",e[e.BUNDLE=1e3]="BUNDLE",e})({});const ot=c.findByPropsAll("NONE_ITEM");let it,ye;const ct=function(){return ot.map(function(e){return A.after("default",e,function(t,n){if(O){const i=Z.profileEffects;it!==i?(n.splice(1),n[0].items.splice(1),Z.profileEffects.forEach(function(r){n[0].items.push(new oe(r))}),ye=n):n=ye}return n})})};function Pe(e){return typeof e[Symbol.iterator]=="function"}function ie(e){return e!==null&&typeof e=="object"}function ce(e){return ie(e)&&"type"in e}function Se(e){return"children"in e.props}function lt(e){return"_context"in e}function st(e){return"render"in e}function ft(e){return"type"in e}function B(e){return typeof e=="symbol"?Symbol.keyFor(e)||null:typeof e=="function"?e.displayName||e.name||null:lt(e)?e._context.displayName||null:e.displayName?e.displayName:st(e)?e.render.displayName||e.render.name||null:ft(e)?B(e.type):null}function W(e,t,n=200){if(ie(e))if(Pe(e)){if(n>0)for(const i of e){const r=W(i,t,n-1);if(r)return r}}else{if(t(e))return e;if(Se(e))return W(e.props.children,t,n-1)}return null}function K(e,t,n=200){if(ie(e)){if(Pe(e)){if(n>0)for(const i of e){const r=K(i,t,n-1);if(r)return r}}else if(Se(e))return t(e.props.children)?e:K(e.props.children,t,n-1)}return null}const ge=c.findByName("EditProfileEffectActionSheet");let le;function ut(e){const{currentEffectId:t,effects:n,onSelect:i,user:r}=e,l=ge({user:r}),h=q(),P=o.useMemo(function(){return n.map(function(f){return{items:new oe(f)}})},[n]);if(p.storage.forceFallbackEffectPicker)return o.createElement(j,e);let g=!1;const a=W(l,function(f){return B(f.type)==="EditProfileEffectInner"?!0:"profileEffects"in f.props&&"selectedProfileEffect"in f.props&&typeof f.props.setSelectedProfileEffect=="function"?g=!0:!1});if(!a)return le||o.createElement(j,e);const C=W(l,function(f){return B(f.type)==="Button"});if(!C)return le||o.createElement(j,e);if(g){a.props.selectedProfileEffect===void 0&&a.props.setSelectedProfileEffect(e.currentEffectId?{id:e.currentEffectId}:null),a.props.profileEffects=e.effects;const f=K(l,function(s){return Array.isArray(s)&&s.some(function(d){return B(d.type)==="DisplayBanner"})});if(f){const s=l;f.props.children=o.createElement(Ze,{theme:s.props.theme,primaryColor:s.props.primaryColor,secondaryColor:s.props.secondaryColor,children:f.props.children}),s.props.theme=h.theme,s.props.primaryColor=h.primaryColor,s.props.secondaryColor=h.secondaryColor}}else a.props.selectedProfileEffect===void 0&&a.props.setSelectedProfileEffect(t?new oe({id:t}):null),a.props.purchases=P;return $(r.id),C.props.onPress=function(){$(void 0),i(n.find(function(f){return f.id===a.props.selectedProfileEffect?.id})?.config??null)},le=l}const at=ge?ut:j,Ce=c.findByProps("triggerHapticFeedback"),dt=Ce?.HapticFeedbackTypes??{},mt=Ce?.triggerHapticFeedback??function(){},pt=k.getAssetIDByName("img_none"),ht=c.findByProps("DEFAULT_PROFILE_EFFECT_WH_RATIO")?.DEFAULT_PROFILE_EFFECT_WH_RATIO??45/88,Et=k.getAssetIDByName("sample-profile-small")??{uri:"https://discordapp.com/assets/f328a6f8209d4f1f5022.png"};k.getAssetIDByName("toast_copy_link"),k.getAssetIDByName("Small");const se=c.findByProps("Radius")?.Radius??{},T=c.findByProps("Spacing")?.Spacing??{},yt=c.findByProps("SafeAreaContext")?.SafeAreaContext,Pt=c.findByName("useWindowDimensions")??function(){},Ae=3;function be({label:e,isSelected:t,size:n,colors:i,onPress:r,style:l,children:h}){const[P,g,a]=i;return o.createElement(ve,{accessibilityLabel:e,accessibilityRole:"button",accessibilityState:{selected:t},disabled:t,onPress:function(){mt(dt.IMPACT_LIGHT),r()},style:[{height:n,width:n,overflow:"hidden",backgroundColor:g,borderColor:P,borderRadius:se.sm,borderWidth:2},t&&{borderColor:a},l]},h)}function j({currentEffectId:e,effects:t,onSelect:n}){const[i,r]=o.useState(e),[l,h]=o.useState(0),{theme:P}=q(),g=o.useMemo(function(){return[U(P,["BACKGROUND_PRIMARY","BACKGROUND_BASE_LOWER","BACKGROUND_BASE_LOW"],"#1E1F22"),U(P,["BACKGROUND_FLOATING","MOBILE_FLOATINGBAR_BACKGROUND","BACKGROUND_BASE_LOWER"],"#2B2D31"),U(P,["BUTTON_OUTLINE_BRAND_BORDER_ACTIVE","BORDER_FOCUS"],"#5865F2")]},[P]),a=Pt(),C=o.useContext(yt),f=o.useMemo(function(){const s=Ve.chunk([null,...t],Ae),d=s[s.length-1];for(;d.length<3;)d.push(void 0);return s},[t]);return o.createElement(Ct,{transparentHeader:!0,scrollable:!0,startExpanded:!0,startHeight:a.height-C.top},o.createElement(At,{scrollsToTop:!1},o.createElement(u.View,{style:{flex:1,flexDirection:"column",alignItems:"center",paddingBottom:88}},o.createElement(X,{variant:"redesign/heading-18/bold",color:"header-primary",style:{margin:T.PX_16}},e?"Change Effect":"Add Profile Effect"),o.createElement(u.View,{style:{width:"72%",minHeight:38}},o.createElement(X,{variant:"heading-md/bold",color:"header-primary",style:{textAlign:"center"}},t.find(function(s){return s.id===i})?.config.title??"None")),o.createElement(u.View,{style:{flex:1,width:"92%",marginTop:3}},o.createElement(wt,{accessibilityLabel:"Profile Effect Selection Section",numColumns:1,estimatedItemSize:98,ItemSeparatorComponent:function(){return o.createElement(u.View,{style:{height:T.PX_16}})},contentContainerStyle:{paddingHorizontal:T.PX_4},data:f,extraData:i,renderItem:function({item:s}){return o.createElement(u.View,{style:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",paddingHorizontal:T.PX_16}},s.map(function(d){return d?o.createElement(be,{label:d.config.accessibilityLabel,isSelected:d.id===i,size:l,colors:g,onPress:function(){r(d.id)}},o.createElement(Re,{effect:d.config})):d===null?o.createElement(be,{label:"None",isSelected:!i,size:l,colors:g,onPress:function(){r(void 0)},style:{alignItems:"center",justifyContent:"center"}},o.createElement(we,{source:pt,size:we.Sizes.LARGE}),o.createElement(X,{variant:"text-sm/medium",color:"header-primary",style:{marginTop:T.PX_4}},"None")):o.createElement(u.View,{style:{width:l,height:l}})}))},onLayout:function(s){h((s.nativeEvent.layout.width-64)/Ae)}})))),o.createElement(F,{text:"Apply",textStyle:{fontSize:16},onPress:function(){n(t.find(function(s){return s.id===i})?.config??null)},style:{position:"absolute",right:0,bottom:0,left:0,height:48,marginHorizontal:36,marginBottom:T.PX_48,borderRadius:se.round}}))}const St=c.findByName("showCustomColorPickerActionSheet")??function(){};function Be(e){return e.color??=0,St(e)}const fe="__FPTE__";function gt(e,t){function n(i){i.key===fe&&(z.unsubscribe("HIDE_ACTION_SHEET",n),$(void 0))}z.subscribe("HIDE_ACTION_SHEET",n),bt({content:o.createElement(at,{effects:Z.profileEffects,onSelect:function(i){e(i),Bt(fe)},user:v.getCurrentUser(),currentEffectId:t}),key:fe})}const Ct=c.findByProps("BottomSheet")?.BottomSheet??c.findByProps("ActionSheet")?.ActionSheet??function(){throw new Error("FakeProfileThemesAndEffects threw an error to avoid an otherwise-inevitable, unrecoverable freeze.")},At=c.findByProps("BottomSheetScrollView")?.BottomSheetScrollView??function(){return null},Te=c.findByProps("showActionSheet"),bt=Te?.showActionSheet??function(){},Bt=Te?.default?.hideActionSheet??function(){},Tt=I.Forms.FormSection,Ft=I.Forms.FormRow,Fe=I.Forms.FormRadioRow,Ie=I.Forms.FormSwitchRow,It=I.Forms.FormCardSection,_e=c.findByProps("saveProfileChanges");function _t({guildId:e}){const[t,n]=Je(null),[i,r]=$e(null),[l,h]=o.useState(null);qe(!0);const[P,g]=o.useState(!1),{theme:a}=q(),[C,f]=o.useMemo(function(){return[U(a,["HEADER_SECONDARY","TEXT_MUTED","TEXT_SUBTLE"],"#B5BAC1"),U(a,["BACKGROUND_ACCENT","BACKGROUND_BASE_LOWER","BACKGROUND_BASE_LOW"],"#1E1F22")]},[a]),s=Qe(v.getCurrentUser()?.getAvatarURL(e,80)??"",f,!1),[d,ae]=o.useState(null);o.useEffect(function(){const R=v.getCurrentUser();if(!R)return;const m=N.getUserProfile(R.id);m&&ae(m.bio??null)},[]);const D=d!==null&&he(d),Y=t!==null||i!==null||l!==null,xe=nt(t??-1,i??-1,l?.id??"",P);function xt(){const R=v.getCurrentUser();if(!R)return;let m=d??"";if(D&&!Y){m=Ee(m);try{_e.saveProfileChanges({...N.getUserProfile(R.id),bio:m}),ae(m),x.showToast("FPTE removed!")}catch(de){x.showToast("Failed to update bio!"),console.error(de)}return}if(xe){he(m)&&(m=Ee(m)),m.length>0&&(m+=" "),m+=xe;try{_e.saveProfileChanges({...N.getUserProfile(R.id),bio:m}),ae(m),x.showToast("FPTE applied!")}catch(de){x.showToast("Failed to update bio!"),console.error(de)}}}const kt=D&&!Y?"Remove FPTE":"Apply FPTE",ke=Y||D;return o.createElement(It,{title:o.createElement(u.View,{style:{flexDirection:"row",alignItems:"center"}},o.createElement(u.Text,{style:{fontSize:16,color:"#FFFFFF"}},"FPTE Builder"),o.createElement(u.Text,{style:{color:D?"#4CAF50":"#F44336",fontSize:17,marginLeft:8}},D?"Active":"Inactive")),cardStyle:{backgroundColor:"transparent"}},o.createElement(u.View,{style:{flexDirection:"row",justifyContent:"space-between"}},o.createElement(ue,{fgColor:C,label:"Primary",bgColor:t,onPress:function(){return Be({color:t,onSelect:n,suggestedColors:s})}}),o.createElement(ue,{fgColor:C,label:"Accent",bgColor:i,onPress:function(){return Be({color:i,onSelect:r,suggestedColors:s})}}),o.createElement(ue,{fgColor:C,label:"Effect",onPress:function(){return gt(h,l?.id)}},l&&o.createElement(Re,{effect:l,style:{width:"140%",height:"100%"}})),o.createElement(u.View,{style:{flexDirection:"column",alignItems:"center",marginLeft:12}},o.createElement(F,{text:kt,size:F.Sizes.SMALL,onPress:xt,style:{marginBottom:6,paddingHorizontal:12,opacity:ke?1:0},pointerEvents:ke?"auto":"none"}),o.createElement(F,{text:"Reset",look:F.Looks.LINK,color:F.Colors.TRANSPARENT,size:F.Sizes.SMALL,...Y?{}:{pointerEvents:"none",style:{opacity:0}},onPress:function(){n(null),r(null),h(null)}}))))}const ue=function({label:e,fgColor:t,bgColor:n,onPress:i,children:r}){return o.createElement(u.View,{style:{width:50}},o.createElement(ve,{accessibilityLabel:e,accessibilityRole:"button",onPress:i,style:[{display:"flex",alignItems:"center",justifyContent:"center",height:50,overflow:"hidden",borderColor:t,borderStyle:"dashed",borderWidth:2,borderRadius:se.xs},n!=null&&{backgroundColor:"#"+n.toString(16).padStart(6,"0"),borderStyle:"solid"},!!r&&{borderWidth:0}]},r??(n==null&&o.createElement(Rt,{fill:t,width:"40%",height:"40%",viewBox:"0 0 144 144"},o.createElement(Nt,{d:"M144 64H80V0H64v64H0v16h64v64h16V80h64Z"})))),!!e&&o.createElement(X,{variant:"text-sm/normal",style:{marginTop:T.PX_4,textAlign:"center"}},e))},F=I.Button,we=c.findByProps("IconSizes")?.default??function(){return null},Re=function({effect:e,style:t}){return o.createElement(u.View,{style:t},o.createElement(u.Image,{resizeMode:"cover",source:Et,style:{width:"100%",height:"100%"}}),o.createElement(u.Image,{alt:e.accessibilityLabel,resizeMethod:"resize",resizeMode:"cover",source:{uri:e.thumbnailPreviewSrc},style:{position:"absolute",width:"100%",aspectRatio:ht}}))},X=c.findByProps("TextStyleSheet")?.Text??function(){return null},wt=c.findByName("FlashList")??function(){return null},Ne=c.findByProps("Svg"),Rt=Ne?.Svg??function(){return null},Nt=Ne?.Path??function(){return null},ve=c.findByProps("PressableOpacity")?.PressableOpacity??function(){return null},vt=c.findByName("UserProfileEditForm",!1),Ut=function(){return A.after("default",vt,function(e,t){if(p.storage.hideBuilder)return t;const n=K(t,function(i){return Array.isArray(i)&&i.some(function(r){return ce(r)&&B(r.type)==="UserProfileEditFormTextField"})});if(n){const i=n.props.children.reduce(function(r,l,h){return ce(l)&&B(l.type)==="UserProfileEditFormTextField"&&r.push(h),r},[]);i.length>=3&&n.props.children.splice(i[2]+1,0,o.createElement(_t,null))}return t})},Ue=c.findByName("UserProfileEditForm",!1);function Oe(e){if(!e||ce(e)&&B(e.type)==="UserProfilePremiumUpsellCard")return null;if(e.props?.children){let t=e.props.children;Array.isArray(t)||(t=[t]);const n=t.map(Oe).filter(function(i){return i!==null});e.props.children=n.length===1?n[0]:n}return e}const Ot=function(){Ue&&A.after("default",Ue,function(e,t){return Oe(t)||t})};function Lt(){return Ge.useProxy(p.storage),o.createElement(u.ScrollView,null,o.createElement(Tt,{title:"Settings"},o.createElement(Ft,{label:"Source to prioritize"}),o.createElement(Fe,{label:"Nitro",selected:!!p.storage.prioritizeNitro,onPress:function(){p.storage.prioritizeNitro=!0}}),o.createElement(Fe,{label:"About Me",selected:!p.storage.prioritizeNitro,onPress:function(){p.storage.prioritizeNitro=!1}}),o.createElement(Ie,{label:"Hide Builder",subLabel:"Hide the FPTE Builder in the User Profile and Server Profiles settings pages",value:!!p.storage.hideBuilder,onValueChange:function(e){p.storage.hideBuilder=e}}),o.createElement(Ie,{label:"Force fallback effect picker",value:!!p.storage.forceFallbackEffectPicker,onValueChange:function(e){p.storage.forceFallbackEffectPicker=e}})))}function Le(){const e=v.getCurrentUser();if(!e)return;const t=N.getUserProfile(e.id);t&&z.dispatch({type:"USER_PROFILE_FETCH_SUCCESS",user:e,user_profile:t,connected_accounts:t.connectedAccounts})}let De=function(){};var Dt={onLoad(){De=Ke("FakeProfileThemesAndEffects",ze.logger,{"purchase check":tt,"user profile data":rt,"profile effect sections":function(){const e=ct();return function(){return e.forEach(function(t){return t()})}},"profile theme":et,"profile edit form":Ut,"nitro upsell card":Ot}),Le()},onUnload(){De(),Le()},settings:Lt};return Q.default=Dt,Object.defineProperty(Q,"__esModule",{value:!0}),Q})({},vendetta,vendetta.metro.common,vendetta.metro,vendetta.patcher,window.React,vendetta.ui,vendetta.plugin,vendetta.ui.toasts,vendetta.metro.common.ReactNative,lodash,vendetta.ui.assets,vendetta.ui.components,vendetta.storage);
|