1 line
5.2 KiB
JavaScript
1 line
5.2 KiB
JavaScript
(function(B,P,s,w,c,Y,R,I,x){"use strict";function F(t,e,a,o){try{return a()}catch(r){return o.error(`[${t}] Failed to apply the "${e}" patch, that surface will be skipped: ${r}`),function(){}}}function M(t,e,a){const o=Object.entries(a).map(function([r,n]){return F(t,r,n,e)});return function(){return o.forEach(function(r){return r()})}}function b(t,e,a=100){let o=!1,r;const n=t();return n?(e(n),{cancel(){}}):(r=setInterval(function(){if(o)return;const u=t();u&&(o=!0,clearInterval(r),e(u))},a),{cancel(){o=!0,r&&clearInterval(r)}})}function E(t){const e=window?.modules;if(e)for(const a in e){const o=e[a];if(!o?.isInitialized)continue;const r=o.publicModule?.exports;if(r)try{if(t(r))return r;if(r.default!=null&&t(r.default))return r.default}catch{}}}function j(t){return E(function(e){return e?.name===t||e?.displayName===t||e?.type?.name===t||e?.type?.displayName===t})}const v=new Map,S=[];let h=[],y=!1;function z(t,e){h.push({predicate:t,onDetected:e})}function V(t){if(h.length===0)return;const e=[];for(const a of h){let o=!1;try{o=a.predicate(t)}catch{}if(o)try{a.onDetected(t)}catch{}else e.push(a)}h=e}function N(t,e){if(V(t),e)for(const{predicate:o,replacement:r}of S)try{if(o(e))return r?{type:r,props:e}:null}catch{}const a=v.get(t);if(a)return{type:a.replacement,props:a.extraProps?{...e,...a.extraProps}:e}}function $(t){if(y)return;const e=c.React.createElement;if(!e){console.warn("[createElementIntercept] React.createElement is null, skipping patch");return}const a=function(n,u,...l){const i=N(n,u);return i===null?null:i?e.call(c.React,i.type,i.props,...l):e.call(c.React,n,u,...l)};Object.assign(a,e),c.React.createElement=a,y=!0;const o=[],r=b(function(){return E(function(n){return typeof n?.jsx=="function"&&typeof n?.jsxs=="function"&&"Fragment"in n})},function(n){for(const u of["jsx","jsxs"]){const l=n[u];typeof l=="function"&&(n[u]=function(i,d,...f){const p=N(i,d);return p===null?null:p?l.call(this,p.type,p.props,...f):l.call(this,i,d,...f)},o.push(function(){n[u]=l}))}});t.push(function(){r.cancel(),y&&(c.React.createElement=e,y=!1),o.forEach(function(n){return n()}),v.clear(),S.length=0,h=[]})}let g=function(){};function C(t){return t?.name==="YouBarNotificationsButton"||t?.displayName==="YouBarNotificationsButton"||t?.type?.name==="YouBarNotificationsButton"||t?.type?.displayName==="YouBarNotificationsButton"}function T(){const t=[];let e=function(){},a=null;function o(n){!n||n===a||(a=n,e=k(n))}$(t),z(C,o);const r=b(function(){return j("YouBarNotificationsButton")},o);return t.push(function(){return r.cancel()}),function(){e(),t.forEach(function(n){return n()})}}function k(t){const e=w.findByProps("openUserSettings"),a=w.findByProps("transitionToGuild"),o=R.getAssetIDByName("ChatIcon"),r=R.getAssetIDByName("SettingsIcon");return Y.instead("type",t,function(n,u){try{const[,l]=c.React.useReducer(function(p){return~p},0);g=function(){return l()};const i=u(...n);if(!i?.props?.children)return i;const d=i.props.children.type,f=i.props.children.props;return c.React.createElement(c.React.Fragment,null,s.storage.showDMButton&&c.React.createElement(d,{variant:f?.variant||"tertiary",size:f?.size||"sm",icon:o,onPress:function(){return a?.transitionToGuild?.("@me")}}),s.storage.showSettingsButton&&c.React.createElement(d,{variant:f?.variant||"tertiary",size:f?.size||"sm",icon:r,onPress:function(){return e?.openUserSettings?.()}}),i)}catch{return u(...n)}})}const{ScrollView:A,View:L}=c.ReactNative;function O({children:t}){return c.React.createElement(A,{style:{flex:1}},t,c.React.createElement(L,{style:{height:24}}))}const{View:U,Text:G}=c.ReactNative;function H({children:t,style:e}){return c.React.createElement(U,{style:[{marginHorizontal:16,marginVertical:8,padding:10,borderRadius:8,borderWidth:1,borderColor:"rgba(128,128,128,0.25)"},e]},c.React.createElement(G,{style:{fontSize:12.5,lineHeight:18,opacity:.75}},t))}const{FormSection:_,FormSwitchRow:m}=x.Forms;function W(){return I.useProxy(s.storage),c.React.useEffect(function(){return function(){return g()}},[]),c.React.createElement(O,null,c.React.createElement(H,null,"Fork of Purple-EyeZ's YouBar+, ported to Revenge's Vendetta-compat API, with a fix for a startup race where Metro hadn't always registered the YouBar component yet by the time this patch ran - if you toggle this on while Discord's already running, the buttons should still appear without a restart once they mount, but a fresh reload is the most reliable way to see them."),c.React.createElement(_,{title:"Buttons"},c.React.createElement(m,{label:"Direct Messages button",subLabel:"Show the DM button in the YouBar",value:!!s.storage.showDMButton,onValueChange:function(t){s.storage.showDMButton=t,g()}}),c.React.createElement(m,{label:"Settings button",subLabel:"Show the Settings button in the YouBar",value:!!s.storage.showSettingsButton,onValueChange:function(t){s.storage.showSettingsButton=t,g()}})))}let D=function(){};var Z={onLoad:function(){s.storage.showDMButton??=!1,s.storage.showSettingsButton??=!0,D=M("YouBar+",P.logger,{"YouBar buttons":T})},onUnload:function(){return D()},settings:W};return B.default=Z,Object.defineProperty(B,"__esModule",{value:!0}),B})({},vendetta,vendetta.plugin,vendetta.metro,vendetta.metro.common,vendetta.patcher,vendetta.ui.assets,vendetta.storage,vendetta.ui.components);
|