1 line
2 KiB
JavaScript
1 line
2 KiB
JavaScript
(function(u,g,f,P,d,o){"use strict";const m={he:"he/him",she:"she/her",they:"they/them",it:"it/its",any:"any",other:"other",ask:"ask",avoid:"avoid, use name"};function w(e){if(e?.length)return e.map(function(t){return m[t]??t}).join(" / ")}const i=new Map,r=new Map;let s=new Set,l;function h(e,t){r.get(e)?.forEach(function(n){return n(t)}),r.delete(e)}async function R(){const e=[...s];if(s=new Set,!!e.length)try{const t=await(await d.safeFetch(`https://pronoundb.org/api/v2/lookup?platform=discord&ids=${e.join(",")}`,{headers:{Accept:"application/json"}})).json();for(const n of e){const a=w(t?.[n]?.sets?.en);i.set(n,a??null),h(n,a)}}catch{for(const t of e)i.set(t,null),h(t,void 0)}}function S(e){return i.get(e)??void 0}function j(e,t){return i.has(e)?(t(i.get(e)??void 0),function(){}):(r.has(e)||r.set(e,new Set),r.get(e).add(t),s.add(e),clearTimeout(l),l=setTimeout(R,150),function(){return r.get(e)?.delete(t)})}const{Text:A}=o.ReactNative,p=f.findByName("UserProfileSection",!1);function E({userId:e}){const[t,n]=o.React.useState(function(){return S(e)});return o.React.useEffect(function(){return j(e,n)},[e]),!t||!p?null:o.React.createElement(p,{title:"Pronouns"},o.React.createElement(A,{style:{fontSize:16}},t))}const y=f.find(function(e){return e?.type?.name==="UserProfile"});function I(){return y?P.after("type",y,function(e,t){try{const n=d.findInReactTree(t,function(c){return Array.isArray(c?.props?.children)&&c.props.children.some(function(T){return T?.type?.name==="UserProfileBio"})})?.props?.children;if(!Array.isArray(n))return;const a=n.find(function(c){return typeof c?.props?.displayProfile?.userId=="string"})?.props?.displayProfile?.userId;if(!a)return;n.unshift(React.createElement(E,{userId:a}))}catch{}}):function(){}}let v=function(){};var $={onLoad:function(){try{v=I()}catch(e){g.logger.error(`[PronounDB] Failed to apply the profile patch: ${e}`)}},onUnload:function(){return v()}};return u.default=$,Object.defineProperty(u,"__esModule",{value:!0}),u})({},vendetta,vendetta.metro,vendetta.patcher,vendetta.utils,vendetta.metro.common);
|