1 line
8 KiB
JavaScript
1 line
8 KiB
JavaScript
(function(m,w,o,d,s,p,T,x,R,V){"use strict";function $(e,t,n,r){try{return n()}catch(a){return r.error(`[${e}] Failed to apply the "${t}" patch, that surface will be skipped: ${a}`),function(){}}}function k(e,t,n){const r=Object.entries(n).map(function([a,c]){return $(e,a,c,t)});return function(){return r.forEach(function(a){return a()})}}function B(e){return e.length===4?"#"+e.slice(1).split("").map(function(t){return t+t}).join(""):e}function O(e,t,n){const r=function(f){return(B(f).match(/\w\w/g)??["00","00","00"]).map(function(i){return parseInt(i,16)})},a=function(f){return"#"+f.map(function(i){return i.toString(16).padStart(2,"0")}).join("")},c=r(e),l=r(t),u=c.map(function(f,i){return Math.round(f+(l[i]-f)*n)});return a(u)}const P=d.findByStoreName("ThemeStore"),_=d.find(function(e){return e?.default?.internal?.resolveSemanticColor})?.default?.internal?.resolveSemanticColor??d.find(function(e){return e?.meta?.resolveSemanticColor})?.meta?.resolveSemanticColor??function(){};function S(){try{return _(P?.theme,T.semanticColors.TEXT_NORMAL)}catch{return}}const I=d.findByStoreName("GuildMemberStore"),A=d.findByStoreName("ChannelStore"),M=d.findByName("RowManager",!1);function y(e,t,n,r){if(!e)return e;if(r=r?[...r,e]:[e],Array.isArray(e.content)?e.content.forEach(function(a,c){return e.content[c]=y(a,t,n,r)}):e.items?e.items.forEach(function(a,c){return e.items[c]=y(a,t,n,r)}):Array.isArray(e)&&e.forEach(function(a,c){return e[c]=y(a,t,n,r)}),e.type)for(const a of t)e=a(e,n,r)||e;return e}function v(e){const{message:t}=e;if(!t||(!o.storage.chatInterpolation||o.storage.chatInterpolation<=0)&&o.storage.noMention)return;const n=A?.getChannel(t.channelId);if(!n?.guild_id)return;const r=function(l){if(l.type!=="mention"||!l.userId)return;const u=I?.getMember(n.guild_id,l.userId)?.colorString;if(u)return{...l,roleColor:parseInt(u.slice(1),16),color:parseInt(u.slice(1),16),colorString:u}},a=function(l,[u],f){if(f?.map(function(h){return h.type})?.some(function(h){return["mention","channelMention","roleMention","commandMention","link"].includes(h)})||l.type!=="text")return;const i=I?.getMember(t.guildId,u);if(i?.colorString)return{content:[l],target:"usernameOnClick",context:{username:1,usernameOnClick:{action:"0",userId:"0",linkColor:s.ReactNative.processColor(O(S()??"#ffffff",i.colorString,o.storage.chatInterpolation/100)),messageChannelId:"0"},medium:!0},type:"link"}},c=[];o.storage.chatInterpolation>0&&c.push(a),o.storage.noMention||(c.push(r),t.shouldShowRoleOnName=!0,t.referencedMessage?.message&&(t.referencedMessage.message.shouldShowRoleOnName=!0)),c.length&&(t.content&&y({content:t.content},c,[t.authorId]),t.embeds&&t.embeds.forEach(function(l){return y({content:l.description},c,[t.authorId])}),t.referencedMessage?.message?.content&&y({content:t.referencedMessage.message.content},c,[t.referencedMessage.message.authorId]))}function G(){const{NativeModules:e}=s.ReactNative,t=e?.DCDChatManager;return t?.updateRows?p.before("updateRows",t,function(n){try{const r=JSON.parse(n[1]);for(const a of r)v(a);n[1]=JSON.stringify(r)}catch{}}):M?.prototype?.generate?p.after("generate",M.prototype,function(n,r){try{v(r)}catch{}}):function(){}}const{View:C}=s.ReactNative,L=d.findByStoreName("GuildStore");function F(){return C?p.after("render",C,function(e,t){try{if(o.storage.noRole)return;const n=x.findInReactTree(t,function(a){return a?.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}};p.after("type",r.type,function(a,c){const l=c?.props?.children?.[1];if(!l?.type)return;const u={type:{...l.type}};p.after("render",u.type,function(f,i){const h=L?.getGuild(n.props.guildId)?.roles?.[n.props.roleId];!h?.colorString||!i?.props?.style?.push||i.props.style.push({color:h.colorString})}),l.type=u.type}),n.type=r.type}catch{}}):function(){}}const{Text:D}=R.General,H=d.findByStoreName("UserStore"),U=d.findByStoreName("RelationshipStore"),j=d.findByStoreName("GuildMemberStore"),b=d.findByProps("TYPING_WRAPPER_HEIGHT");function z(){return b?.default?p.after("default",b,function([{channel:e}],t){try{if(!t||o.storage.hideTyping)return;const n=t.props?.children;if(!n)return;const r=p.after("type",n,function(a,c){try{s.React.useEffect(function(){return function(){return r()}},[]);const l=c?.props?.children?.[0]?.props?.children?.[1]?.props;if(!l?.children||l.children==="Several people are typing...")return;const u=(b.useTypingUserIds?.(e.id)??[]).map(function(i){const h=j?.getMember(e.guild_id,i),E=H?.getUser(i),re=h?.nick||U?.getNickname?.(i)||E?.globalName||E?.username||"Someone",oe=h?.colorString||S();return{name:re,color:oe}});if(!u.length)return;const f=function(i){return s.React.createElement(D,{style:{color:i.color,fontFamily:s.constants.Fonts.DISPLAY_SEMIBOLD}},i.name)};l.children=u.length===1?[f(u[0])," is typing..."]:[...u.slice(0,-1).flatMap(function(i,h){return[f(i),h<u.length-2?", ":" and "]}),f(u[u.length-1])," are typing..."]}catch{}})}catch{}}):function(){}}function W(){const e=d.findByName("VoiceUserConnected",!1);return e?p.after("default",e,function([t],n){try{if(o.storage.noVoice||!n?.type)return;const r=!!n.type.prototype?.render,a=r?"render":"type",c=r?n.type.prototype:n.type,l=p.after(a,c,function(u,f){try{l();const i=f?.props?.children?.[1]?.props;if(!i?.style)return;i.style.color=t?.member?.colorString||S()}catch{}})}catch{}}):function(){}}const{ScrollView:J,View:X}=s.ReactNative;function Y({children:e}){return s.React.createElement(J,{style:{flex:1}},e,s.React.createElement(X,{style:{height:24}}))}const{View:q,Text:K}=s.ReactNative;function Q({children:e,style:t}){return s.React.createElement(q,{style:[{marginHorizontal:16,marginVertical:8,padding:10,borderRadius:8,borderWidth:1,borderColor:"rgba(128,128,128,0.25)"},t]},s.React.createElement(K,{style:{fontSize:12.5,lineHeight:18,opacity:.75}},e))}const{FormSection:Z,FormSwitchRow:g,FormInput:ee}=R.Forms;function te(){return V.useProxy(o.storage),s.React.createElement(Y,null,s.React.createElement(Z,{title:"Where to show the top role color"},s.React.createElement(g,{label:"Typing indicator",subLabel:'Color names in the "X is typing..." bar',value:!o.storage.hideTyping,onValueChange:function(e){o.storage.hideTyping=!e}}),s.React.createElement(g,{label:"Mentions",subLabel:"Color @mentions in chat messages",value:!o.storage.noMention,onValueChange:function(e){o.storage.noMention=!e}}),s.React.createElement(g,{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}}),s.React.createElement(g,{label:"Voice channel participant names",value:!o.storage.noVoice,onValueChange:function(e){o.storage.noVoice=!e}}),s.React.createElement(g,{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&&s.React.createElement(ee,{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))}})),s.React.createElement(Q,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 N=function(){};var ne={onLoad:function(){o.storage.noMention??=!1,o.storage.noRole??=!1,o.storage.noVoice??=!1,o.storage.hideTyping??=!1,o.storage.chatInterpolation??=0,N=k("RoleColorEverywhere",w.logger,{"mentions & chat text":G,"member list role headers":F,"typing indicator":z,"voice channel names":W})},onUnload:function(){return N()},settings:te};return m.default=ne,Object.defineProperty(m,"__esModule",{value:!0}),m})({},vendetta,vendetta.plugin,vendetta.metro,vendetta.metro.common,vendetta.patcher,vendetta.ui,vendetta.utils,vendetta.ui.components,vendetta.storage);
|