1 line
5.3 KiB
JavaScript
1 line
5.3 KiB
JavaScript
(function(g,N,s,B,c,x,w,D,I){"use strict";function P(t,e,o,a){try{return o()}catch(n){return a.error(`[${t}] Failed to apply the "${e}" patch, that surface will be skipped: ${n}`),function(){}}}function Y(t,e,o){const a=Object.entries(o).map(function([n,r]){return P(t,n,r,e)});return function(){return a.forEach(function(n){return n()})}}function F(t,e,o=100){let a=!1,n;const r=t();return r?(e(r),{cancel(){}}):(n=setInterval(function(){if(a)return;const i=t();i&&(a=!0,clearInterval(n),e(i))},o),{cancel(){a=!0,n&&clearInterval(n)}})}function R(t){const e=window?.modules;if(e)for(const o in e){const a=e[o];if(!a?.isInitialized)continue;const n=a.publicModule?.exports;if(n)try{if(t(n))return n;if(n.default!=null&&t(n.default))return n.default}catch{}}}function M(t){return R(function(e){return e?.name===t||e?.displayName===t||e?.type?.name===t||e?.type?.displayName===t})}const E=new Map,b=[];let p=[],d=!1;function j(t,e){p.push({predicate:t,onDetected:e})}function z(t){if(p.length===0)return;const e=[];for(const o of p){let a=!1;try{a=o.predicate(t)}catch{}if(a)try{o.onDetected(t)}catch{}else e.push(o)}p=e}function v(t,e){if(z(t),e)for(const{predicate:a,replacement:n}of b)try{if(a(e))return n?{type:n,props:e}:null}catch{}const o=E.get(t);if(o)return{type:o.replacement,props:o.extraProps?{...e,...o.extraProps}:e}}function V(t){if(d)return;const e=c.React.createElement;if(!e){console.warn("[createElementIntercept] React.createElement is null, skipping patch");return}const o=function(r,i,...f){const u=v(r,i);return u===null?null:u?e.call(c.React,u.type,u.props,...f):e.call(c.React,r,i,...f)};Object.assign(o,e),c.React.createElement=o,d=!0;const a=R(function(r){return typeof r?.jsx=="function"&&typeof r?.jsxs=="function"&&"Fragment"in r}),n=[];if(a)for(const r of["jsx","jsxs"]){const i=a[r];typeof i=="function"&&(a[r]=function(f,u,...h){const l=v(f,u);return l===null?null:l?i.call(this,l.type,l.props,...h):i.call(this,f,u,...h)},n.push(function(){a[r]=i}))}else console.warn("[createElementIntercept] jsx-runtime module not found, only classic createElement calls will be intercepted");t.push(function(){d&&(c.React.createElement=e,d=!1),n.forEach(function(r){return r()}),E.clear(),b.length=0,p=[]})}let y=function(){};function $(t){return t?.name==="YouBarNotificationsButton"||t?.displayName==="YouBarNotificationsButton"||t?.type?.name==="YouBarNotificationsButton"||t?.type?.displayName==="YouBarNotificationsButton"}function C(){const t=[];let e=function(){},o=null;function a(r){!r||r===o||(o=r,e=T(r))}V(t),j($,a);const n=F(function(){return M("YouBarNotificationsButton")},a);return t.push(function(){return n.cancel()}),function(){e(),t.forEach(function(r){return r()})}}function T(t){const e=B.findByProps("openUserSettings"),o=B.findByProps("transitionToGuild"),a=w.getAssetIDByName("ChatIcon"),n=w.getAssetIDByName("SettingsIcon");return x.instead("type",t,function(r,i){try{const[,f]=c.React.useReducer(function(Z){return~Z},0);y=function(){return f()};const u=i(...r);if(!u?.props?.children)return u;const h=u.props.children.type,l=u.props.children.props;return c.React.createElement(c.React.Fragment,null,s.storage.showDMButton&&c.React.createElement(h,{variant:l?.variant||"tertiary",size:l?.size||"sm",icon:a,onPress:function(){return o?.transitionToGuild?.("@me")}}),s.storage.showSettingsButton&&c.React.createElement(h,{variant:l?.variant||"tertiary",size:l?.size||"sm",icon:n,onPress:function(){return e?.openUserSettings?.()}}),u)}catch{return i(...r)}})}const{ScrollView:k,View:A}=c.ReactNative;function L({children:t}){return c.React.createElement(k,{style:{flex:1}},t,c.React.createElement(A,{style:{height:24}}))}const{View:O,Text:U}=c.ReactNative;function G({children:t,style:e}){return c.React.createElement(O,{style:[{marginHorizontal:16,marginVertical:8,padding:10,borderRadius:8,borderWidth:1,borderColor:"rgba(128,128,128,0.25)"},e]},c.React.createElement(U,{style:{fontSize:12.5,lineHeight:18,opacity:.75}},t))}const{FormSection:H,FormSwitchRow:m}=I.Forms;function _(){return D.useProxy(s.storage),c.React.useEffect(function(){return function(){return y()}},[]),c.React.createElement(L,null,c.React.createElement(G,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(H,{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,y()}}),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,y()}})))}let S=function(){};var W={onLoad:function(){s.storage.showDMButton??=!1,s.storage.showSettingsButton??=!0,S=Y("YouBar+",N.logger,{"YouBar buttons":C})},onUnload:function(){return S()},settings:_};return g.default=W,Object.defineProperty(g,"__esModule",{value:!0}),g})({},vendetta,vendetta.plugin,vendetta.metro,vendetta.metro.common,vendetta.patcher,vendetta.ui.assets,vendetta.storage,vendetta.ui.components);
|