1 line
7.4 KiB
JavaScript
1 line
7.4 KiB
JavaScript
(function(S,T,o,f,p,h,x,V,R,k){"use strict";const B=f.findByStoreName("ThemeStore"),_=f.find(function(e){return e?.default?.internal?.resolveSemanticColor})?.default?.internal?.resolveSemanticColor??f.find(function(e){return e?.meta?.resolveSemanticColor})?.meta?.resolveSemanticColor??function(){};function $(e,t,n){const r=function(u){return(u.match(/\w\w/g)??["00","00","00"]).map(function(a){return parseInt(a,16)})},l=function(u){return"#"+u.map(function(a){return a.toString(16).padStart(2,"0")}).join("")},c=r(e),i=r(t),s=c.map(function(u,a){return Math.round(u+(i[a]-u)*n)});return l(s)}function b(){try{return _(B?.theme,x.semanticColors.TEXT_NORMAL)}catch{return}}const M=f.findByStoreName("GuildMemberStore"),O=f.findByStoreName("ChannelStore"),v=f.findByName("RowManager",!1);function m(e,t,n,r){if(!e)return e;if(r=r?[...r,e]:[e],Array.isArray(e.content)?e.content.forEach(function(l,c){return e.content[c]=m(l,t,n,r)}):e.items?e.items.forEach(function(l,c){return e.items[c]=m(l,t,n,r)}):Array.isArray(e)&&e.forEach(function(l,c){return e[c]=m(l,t,n,r)}),e.type)for(const l of t)e=l(e,n,r)||e;return e}function C(e){const{message:t}=e;if(!t||(!o.storage.chatInterpolation||o.storage.chatInterpolation<=0)&&o.storage.noMention)return;const n=O?.getChannel(t.channelId);if(!n?.guild_id)return;const r=function(i){if(i.type!=="mention"||!i.userId)return;const s=M?.getMember(n.guild_id,i.userId)?.colorString;if(s)return{...i,roleColor:parseInt(s.slice(1),16),color:parseInt(s.slice(1),16),colorString:s}},l=function(i,[s],u){if(u?.map(function(d){return d.type})?.some(function(d){return["mention","channelMention","roleMention","commandMention","link"].includes(d)})||i.type!=="text")return;const a=M?.getMember(t.guildId,s);if(a?.colorString)return{content:[i],target:"usernameOnClick",context:{username:1,usernameOnClick:{action:"0",userId:"0",linkColor:p.ReactNative.processColor($(b()??"#ffffff",a.colorString,o.storage.chatInterpolation/100)),messageChannelId:"0"},medium:!0},type:"link"}},c=[];o.storage.chatInterpolation>0&&c.push(l),o.storage.noMention||(c.push(r),t.shouldShowRoleOnName=!0,t.referencedMessage?.message&&(t.referencedMessage.message.shouldShowRoleOnName=!0)),c.length&&(t.content&&m({content:t.content},c,[t.authorId]),t.embeds&&t.embeds.forEach(function(i){return m({content:i.description},c,[t.authorId])}),t.referencedMessage?.message?.content&&m({content:t.referencedMessage.message.content},c,[t.referencedMessage.message.authorId]))}function A(){const{NativeModules:e}=p.ReactNative,t=e?.DCDChatManager;return t?.updateRows?h.before("updateRows",t,function(n){try{const r=JSON.parse(n[1]);for(const l of r)C(l);n[1]=JSON.stringify(r)}catch{}}):v?.prototype?.generate?h.after("generate",v.prototype,function(n,r){try{C(r)}catch{}}):function(){}}const{View:N}=p.ReactNative,F=f.findByStoreName("GuildStore");function G(){return N?h.after("render",N,function(e,t){try{if(o.storage.noRole)return;const n=V.findInReactTree(t,function(l){return l?.props?.roleId!==void 0});if(!n||Number.isNaN(Number(n.props.roleId))||n.props.excludedApplications||"displayRoleIcon"in n.props||"searchable"in n.props)return;const r={type:{...n.type}};h.after("type",r.type,function(l,c){const i=c?.props?.children?.[1];if(!i?.type)return;const s={type:{...i.type}};h.after("render",s.type,function(u,a){const d=F?.getGuild(n.props.guildId)?.roles?.[n.props.roleId];!d?.colorString||!a?.props?.style?.push||a.props.style.push({color:d.colorString})}),i.type=s.type}),n.type=r.type}catch{}}):function(){}}const{Text:L}=R.General,P=f.findByStoreName("UserStore"),D=f.findByStoreName("RelationshipStore"),U=f.findByStoreName("GuildMemberStore"),I=f.findByProps("TYPING_WRAPPER_HEIGHT");function H(){return I?.default?h.after("default",I,function([{channel:e}],t){try{if(!t||o.storage.hideTyping)return;const n=t.props?.children;if(!n)return;const r=h.after("type",n,function(l,c){try{p.React.useEffect(function(){return function(){return r()}},[]);const i=c?.props?.children?.[0]?.props?.children?.[1]?.props;if(!i?.children||i.children==="Several people are typing...")return;const s=(I.useTypingUserIds?.(e.id)??[]).map(function(a){const d=U?.getMember(e.guild_id,a),w=P?.getUser(a),Q=d?.nick||D?.getNickname?.(a)||w?.globalName||w?.username||"Someone",Z=d?.colorString||b();return{name:Q,color:Z}});if(!s.length)return;const u=function(a){return p.React.createElement(L,{style:{color:a.color,fontFamily:p.constants.Fonts.DISPLAY_SEMIBOLD}},a.name)};i.children=s.length===1?[u(s[0])," is typing..."]:[...s.slice(0,-1).flatMap(function(a,d){return[u(a),d<s.length-2?", ":" and "]}),u(s[s.length-1])," are typing..."]}catch{}})}catch{}}):function(){}}function j(){const e=f.findByName("VoiceUserConnected",!1);return e?h.after("default",e,function([t],n){try{if(o.storage.noVoice||!n?.type)return;const r=!!n.type.prototype?.render,l=r?"render":"type",c=r?n.type.prototype:n.type,i=h.after(l,c,function(s,u){try{i();const a=u?.props?.children?.[1]?.props;if(!a?.style)return;a.style.color=t?.member?.colorString||b()}catch{}})}catch{}}):function(){}}const{ScrollView:J,View:W}=p.ReactNative,{FormSection:X,FormSwitchRow:y,FormInput:Y,FormText:z}=R.Forms;function q(){return k.useProxy(o.storage),React.createElement(J,{style:{flex:1}},React.createElement(X,{title:"Where to show the top role color"},React.createElement(y,{label:"Typing indicator",subLabel:'Color names in the "X is typing..." bar',value:!o.storage.hideTyping,onValueChange:function(e){o.storage.hideTyping=!e}}),React.createElement(y,{label:"Mentions",subLabel:"Color @mentions in chat messages",value:!o.storage.noMention,onValueChange:function(e){o.storage.noMention=!e}}),React.createElement(y,{label:"Member list role headers",subLabel:"Color the role section headers in the member list",value:!o.storage.noRole,onValueChange:function(e){o.storage.noRole=!e}}),React.createElement(y,{label:"Voice channel participant names",value:!o.storage.noVoice,onValueChange:function(e){o.storage.noVoice=!e}}),React.createElement(y,{label:"Message text",subLabel:"Tints message text toward the author's role color - disables text selection on tinted messages",value:o.storage.chatInterpolation>0,onValueChange:function(e){o.storage.chatInterpolation=e?60:0}}),o.storage.chatInterpolation>0&&React.createElement(Y,{title:"Message text strength (0-100)",value:String(o.storage.chatInterpolation),keyboardType:"numeric",onChange:function(e){o.storage.chatInterpolation=Math.max(0,Math.min(100,Number(e)||0))}})),React.createElement(W,{style:{paddingHorizontal:16,paddingVertical:8}},React.createElement(z,null,"Some of these surfaces (especially the member list headers) rely on component internals Discord doesn't officially expose, so a future Discord update may silently turn one of these off again - the rest will keep working if that happens.")))}let E=[];function g(e,t){try{return t()}catch(n){return T.logger.error(`[RoleColorEverywhere] Failed to apply the "${e}" patch, that surface will be skipped: ${n}`),function(){}}}var K={onLoad:function(){o.storage.noMention??=!1,o.storage.noRole??=!1,o.storage.noVoice??=!1,o.storage.hideTyping??=!1,o.storage.chatInterpolation??=0,E=[g("mentions & chat text",A),g("member list role headers",G),g("typing indicator",H),g("voice channel names",j)]},onUnload:function(){return E.forEach(function(e){return e()})},settings:q};return S.default=K,Object.defineProperty(S,"__esModule",{value:!0}),S})({},vendetta,vendetta.plugin,vendetta.metro,vendetta.metro.common,vendetta.patcher,vendetta.ui,vendetta.utils,vendetta.ui.components,vendetta.storage);
|