diff --git a/Plugins/BDFDB.js b/Plugins/BDFDB.js index f6d392a3fe..79a13bb500 100644 --- a/Plugins/BDFDB.js +++ b/Plugins/BDFDB.js @@ -1203,7 +1203,9 @@ const pluginId = (typeof plugin === "string" ? plugin : plugin.name).toLowerCase(); return pluginId && module[methodName] && module[methodName].__isBDFDBpatched && module.BDFDBpatch[methodName] && BDFDB.ObjectUtils.toArray(module.BDFDBpatch[methodName]).some(patchObj => BDFDB.ObjectUtils.toArray(patchObj).some(priorityObj => Object.keys(priorityObj).includes(pluginId))); }; - BDFDB.ModuleUtils.patch = function (plugin, module, methodNames, patchMethods, forceRepatch = false) { + BDFDB.ModuleUtils.patch = function (plugin, module, methodNames, patchMethods, config = {}) { + // REMOVE + config = BDFDB.ObjectUtils.is(config) ? config : {force:config}; plugin = plugin == BDFDB && InternalBDFDB || plugin; if (!plugin || !BDFDB.ObjectUtils.is(module) || !methodNames || !BDFDB.ObjectUtils.is(patchMethods)) return null; patchMethods = BDFDB.ObjectUtils.filter(patchMethods, type => WebModulesData.PatchTypes.includes(type), true); @@ -1213,9 +1215,10 @@ const patchPriority = BDFDB.ObjectUtils.is(plugin) && !isNaN(plugin.patchPriority) ? (plugin.patchPriority < 0 ? 0 : (plugin.patchPriority > 10 ? 10 : Math.round(plugin.patchPriority))) : 5; if (!BDFDB.ObjectUtils.is(module.BDFDBpatch)) module.BDFDBpatch = {}; methodNames = [methodNames].flat(10).filter(n => n); + let cancel = _ => {BDFDB.ModuleUtils.unpatch(plugin, module, methodNames);}; for (let methodName of methodNames) if (module[methodName] == null || typeof module[methodName] == "function") { let i = 0; - if (!module.BDFDBpatch[methodName] || forceRepatch && (!module[methodName] || !module[methodName].__isBDFDBpatched)) { + if (!module.BDFDBpatch[methodName] || config.force && (!module[methodName] || !module[methodName].__isBDFDBpatched)) { if (!module.BDFDBpatch[methodName]) { module.BDFDBpatch[methodName] = {}; for (let type of WebModulesData.PatchTypes) module.BDFDBpatch[methodName][type] = {}; @@ -1251,6 +1254,7 @@ } else BDFDB.TimeUtils.suppress(data.callOriginalMethod, `originalMethod of ${methodName} in ${module.constructor ? module.constructor.displayName || module.constructor.name : "module"}`)(); callInstead = false, stopCall = false; + if (config.once) cancel(); return methodName == "render" && data.returnValue === undefined ? null : data.returnValue; }; for (let key of Object.keys(originalMethod)) module[methodName][key] = originalMethod[key]; @@ -1266,8 +1270,7 @@ module.BDFDBpatch[methodName][type][patchPriority][pluginId].pluginName = pluginName; } } - let cancel = _ => {BDFDB.ModuleUtils.unpatch(plugin, module, methodNames);}; - if (BDFDB.ObjectUtils.is(plugin)) { + if (BDFDB.ObjectUtils.is(plugin) && !config.once) { if (!BDFDB.ArrayUtils.is(plugin.patchCancels)) plugin.patchCancels = []; plugin.patchCancels.push(cancel); } @@ -1364,19 +1367,18 @@ InternalBDFDB.initiateProcess = function (plugin, type, e) { plugin = plugin == BDFDB && InternalBDFDB || plugin; if (BDFDB.ObjectUtils.is(plugin) && !plugin.stopping && e.instance) { - type = (type.split(" _ _ ")[1] || type).replace(/[^A-z0-9]|_/g, ""); - type = type.charAt(0).toUpperCase() + type.slice(1); - if (typeof plugin["process" + type] == "function") { + type = LibraryModules.StringUtils.upperCaseFirstChar(type.split(" _ _ ")[1] || type).replace(/[^A-z0-9]|_/g, ""); + if (typeof plugin[`process${type}`] == "function") { if (typeof e.methodname == "string" && (e.methodname.indexOf("componentDid") == 0 || e.methodname.indexOf("componentWill") == 0)) { e.node = BDFDB.ReactUtils.findDOMNode(e.instance); - if (e.node) return plugin["process" + type](e); + if (e.node) return plugin[`process${type}`](e); else BDFDB.TimeUtils.timeout(_ => { e.node = BDFDB.ReactUtils.findDOMNode(e.instance); - if (e.node) return plugin["process" + type](e); + if (e.node) return plugin[`process${type}`](e); }); } - else if (e.returnvalue || e.patchtypes.includes("before")) return plugin["process" + type](e); + else if (e.returnvalue || e.patchtypes.includes("before")) return plugin[`process${type}`](e); } } }; @@ -2130,11 +2132,10 @@ let MessagesIns = BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.app), {name:"Messages", unlimited:true}); let MessagesPrototype = BDFDB.ReactUtils.getValue(MessagesIns, "_reactInternalFiber.type.prototype"); if (MessagesIns && MessagesPrototype) { - let patchCancel = BDFDB.ModuleUtils.patch({name:"tempPatch"}, MessagesPrototype, "render", {after: e => { - patchCancel(); + BDFDB.ModuleUtils.patch(BDFDB, MessagesPrototype, "render", {after: e => { let [children, index] = BDFDB.ReactUtils.findChildren(e.returnValue, {props: ["message", "channel"]}); if (index > -1) for (let ele of children) if (ele.props.message) ele.props.message = new BDFDB.DiscordObjects.Message(ele.props.message); - }}); + }}, {once: true}); BDFDB.ReactUtils.forceUpdate(MessagesIns); } }, 1000); @@ -9205,7 +9206,7 @@ } }; InternalBDFDB.processMessageHeader = function (e) { - if (e.instance.props.message && e.instance.props.message.author && !document.querySelector(BDFDB.dotCN.emojipicker)) { + if (e.instance.props.message && e.instance.props.message.author) { let avatarWrapper = BDFDB.ReactUtils.getValue(e, "returnvalue.props.children.0"); if (avatarWrapper && avatarWrapper.props && typeof avatarWrapper.props.children == "function") { let renderChildren = avatarWrapper.props.children; @@ -9387,20 +9388,22 @@ } });});}))}, {childList: true}); BDFDB.ModuleUtils.patch(BDFDB, BDFDB.ReactUtils.getValue(BDFDB.ModuleUtils.findByString("renderReactions", "canAddNewReactions", "showMoreUtilities", false), "exports.default"), "type", {after: e => { - let [children, index] = BDFDB.ReactUtils.findChildren(e.returnValue, {filter: c => c && c.props && c.props.showMoreUtilities != undefined && c.props.showEmojiPicker != undefined && c.props.setPopout != undefined}); - if (index > -1) BDFDB.ModuleUtils.patch(BDFDB, children[index], "type", {after: e2 => { - let [children2, index2] = BDFDB.ReactUtils.findChildren(e2.returnValue, {filter: c => c && c.props && typeof c.props.onRequestClose == "function" && c.props.onRequestClose.toString().indexOf("moreUtilities") > -1}); - let popoutWrapper = children2[index2]; - InternalBDFDB.executeExtraPatchedPatches("MessageOptionToolbar", {instance:{props:Object.assign({}, e2.methodArguments[0], {hasMorePopout: index2 > -1})}, returnvalue:e2.returnValue, methodname:"default"}); - if (popoutWrapper && typeof popoutWrapper.props.renderPopout == "function") { - let renderPopout = popoutWrapper.props.renderPopout; - popoutWrapper.props.renderPopout = (...args) => { + if (document.querySelector(BDFDB.dotCN.emojipicker)) return; // avoid multi react EmojiPicker rerender + let toolbar = BDFDB.ReactUtils.findChild(e.returnValue, {filter: c => c && c.props && c.props.showMoreUtilities != undefined && c.props.showEmojiPicker != undefined && c.props.setPopout != undefined}); + if (toolbar) BDFDB.ModuleUtils.patch(BDFDB, toolbar, "type", {after: e2 => { + let menu = BDFDB.ReactUtils.findChild(e2.returnValue, {filter: c => c && c.props && typeof c.props.onRequestClose == "function" && c.props.onRequestClose.toString().indexOf("moreUtilities") > -1}); + InternalBDFDB.executeExtraPatchedPatches("MessageOptionToolbar", {instance:{props:Object.assign({}, e2.methodArguments[0], {hasMorePopout: !!menu})}, returnvalue:e2.returnValue, methodname:"default"}); + if (menu && typeof menu.props.renderPopout == "function") { + let renderPopout = menu.props.renderPopout; + menu.props.renderPopout = (...args) => { let renderedPopout = renderPopout(...args); - BDFDB.ModuleUtils.patch(BDFDB, renderedPopout, "type", {after: e3 => {InternalBDFDB.executeExtraPatchedPatches("MessageOptionContextMenu", {instance:{props:e3.methodArguments[0]}, returnvalue:e3.returnValue, methodname:"default"});}}); + BDFDB.ModuleUtils.patch(BDFDB, renderedPopout, "type", {after: e3 => { + InternalBDFDB.executeExtraPatchedPatches("MessageOptionContextMenu", {instance:{props:e3.methodArguments[0]}, returnvalue:e3.returnValue, methodname:"default"}); + }}, {once: true}); return renderedPopout; } } - }}); + }}, {once: true}); }}); BDFDB.ModuleUtils.forceAllUpdates(BDFDB); diff --git a/Plugins/BDFDB.min.js b/Plugins/BDFDB.min.js index 32e3f42ea5..a1b4ac886e 100644 --- a/Plugins/BDFDB.min.js +++ b/Plugins/BDFDB.min.js @@ -1 +1 @@ -(a=>{if(window['BDFDB']&&window['BDFDB']['ListenerUtils']&&typeof window['BDFDB']['ListenerUtils']['remove']=='function')window['BDFDB']['ListenerUtils']['remove'](window['BDFDB']);if(window['BDFDB']&&window['BDFDB']['StoreChangeUtils']&&typeof window['BDFDB']['StoreChangeUtils']['remove']=='function')window['BDFDB']['StoreChangeUtils']['remove'](window['BDFDB']);if(window['BDFDB']&&window['BDFDB']['ObserverUtils']&&typeof window['BDFDB']['ObserverUtils']['disconnect']=='function')window['BDFDB']['ObserverUtils']['disconnect'](window['BDFDB']);if(window['BDFDB']&&window['BDFDB']['ModuleUtils']&&typeof window['BDFDB']['ModuleUtils']['unpatch']=='function')window['BDFDB']['ModuleUtils']['unpatch'](window['BDFDB']);if(window['BDFDB']&&window['BDFDB']['WindowUtils']&&typeof window['BDFDB']['WindowUtils']['closeAll']=='function')window['BDFDB']['WindowUtils']['closeAll'](window['BDFDB']);if(window['BDFDB']&&window['BDFDB']['WindowUtils']&&typeof window['BDFDB']['WindowUtils']['removeListener']=='function')window['BDFDB']['WindowUtils']['removeListener'](window['BDFDB']);const b={'myPlugins':Object['assign']({},window['BDFDB']&&window['BDFDB']['myPlugins']),'InternalData':Object['assign']({'pressedKeys':[],'mousePosition':{'pageX':0x0,'pageY':0x0},'componentPatchQueries':{}},window['BDFDB']&&window['BDFDB']['InternalData'],{'creationTime':performance['now']()}),'BDv2Api':window['BDFDB']&&window['BDFDB']['BDv2Api']||undefined,'name':'BDFDB'};const c={'name':'BDFDB','patchPriority':0x0};const d=Math['round'](Math['random']()*0x2386f26fc10000);b['InternalData']['loadId']=d;if(typeof Array['prototype']['flat']!='function')Array['prototype']['flat']=function(){return this;};c['defaults']={'settings':{'showToasts':{'value':!![],'description':'Show\x20Plugin\x20start\x20and\x20stop\x20Toasts'},'showSupportBadges':{'value':!![],'description':'Show\x20little\x20Badges\x20for\x20Users\x20who\x20support\x20my\x20Patreon'}}};b['LogUtils']={};b['LogUtils']['log']=function(y,z){console['log']('%c['+(typeof z=='string'&&z||'BDFDB')+']','color:\x20#3a71c1;\x20font-weight:\x20700;',(typeof y=='string'&&y||'')['trim']());};b['LogUtils']['warn']=function(y,z){console['warn']('%c['+(typeof z=='string'&&z||'BDFDB')+']','color:\x20#3a71c1;\x20font-weight:\x20700;',(typeof y=='string'&&y||'')['trim']());};b['LogUtils']['error']=function(y,z){console['error']('%c['+(typeof z=='string'&&z||'BDFDB')+']','color:\x20#3a71c1;\x20font-weight:\x20700;','Fatal\x20Error:\x20'+(typeof y=='string'&&y||'')['trim']());};b['LogUtils']['log']('Loading\x20library.');b['PluginUtils']={};b['PluginUtils']['init']=function(y){y['name']=y['name']||(typeof y['getName']=='function'?y['getName']():null);y['version']=y['version']||(typeof y['getVersion']=='function'?y['getVersion']():null);y['author']=y['author']||(typeof y['getAuthor']=='function'?y['getAuthor']():null);y['description']=y['description']||(typeof y['getDescription']=='function'?y['getDescription']():null);c['clearStartTimeout'](y);let z=b['LanguageUtils']['LibraryStringsFormat']('toast_plugin_started','v'+y['version']);b['LogUtils']['log'](z,y['name']);if(!b['BDUtils']['getSettings']('fork-ps-2')&&b['DataUtils']['get'](b,'settings','showToasts'))b['NotificationUtils']['toast'](y['name']+'\x20'+z,{'nopointer':!![],'selector':'plugin-started-toast'});let A=typeof y['getRawUrl']=='function'&&typeof y['getRawUrl']()=='string'?y['getRawUrl']():'https://mwittrien.github.io/BetterDiscordAddons/Plugins/'+y['name']+'/'+y['name']+'.plugin.js';b['PluginUtils']['checkUpdate'](y['name'],A);if(b['ObjectUtils']['is'](y['classes']))c['addPluginClasses'](y);if(typeof y['initConstructor']==='function')b['TimeUtils']['suppress'](y['initConstructor']['bind'](y),'Could\x20not\x20initiate\x20constructor!',y['name'])();if(typeof y['css']==='string')b['DOMUtils']['appendLocalStyle'](y['name'],y['css']);c['patchPlugin'](y);c['addSpecialListeners'](y);b['PluginUtils']['translate'](y);b['PluginUtils']['checkChangeLog'](y);if(!window['PluginUpdates']||typeof window['PluginUpdates']!=='object')window['PluginUpdates']={'plugins':{}};window['PluginUpdates']['plugins'][A]={'name':y['name'],'raw':A,'version':y['version']};if(typeof window['PluginUpdates']['interval']==='undefined')window['PluginUpdates']['interval']=b['TimeUtils']['interval'](B=>{b['PluginUtils']['checkAllUpdates']();},0x3e8*0x3c*0x3c*0x2);y['started']=!![];delete y['stopping'];for(let B in b['myPlugins'])if(!b['myPlugins'][B]['started']&&typeof b['myPlugins'][B]['initialize']=='function')setImmediate(C=>{b['TimeUtils']['suppress'](b['myPlugins'][B]['initialize']['bind'](b['myPlugins'][B]),'Could\x20not\x20initiate\x20plugin!',B)();});};b['PluginUtils']['clear']=function(y){c['clearStartTimeout'](y);delete b['myPlugins'][y['name']];let z=b['LanguageUtils']['LibraryStringsFormat']('toast_plugin_stopped','v'+y['version']);b['LogUtils']['log'](z,y['name']);if(!b['BDUtils']['getSettings']('fork-ps-2')&&b['DataUtils']['get'](b,'settings','showToasts'))b['NotificationUtils']['toast'](y['name']+'\x20'+z,{'nopointer':!![],'selector':'plugin-stopped-toast'});let A=typeof y['getRawUrl']=='function'&&typeof y['getRawUrl']()=='string'?y['getRawUrl']():'https://mwittrien.github.io/BetterDiscordAddons/Plugins/'+y['name']+'/'+y['name']+'.plugin.js';if(b['ObjectUtils']['is'](y['classes']))c['removePluginClasses'](y);if(typeof y['css']==='string')b['DOMUtils']['removeLocalStyle'](y['name']);b['ModuleUtils']['unpatch'](y);b['ListenerUtils']['remove'](y);b['StoreChangeUtils']['remove'](y);b['ObserverUtils']['disconnect'](y);b['WindowUtils']['closeAll'](y);b['WindowUtils']['removeListener'](y);for(let B in b['InternalData']['componentPatchQueries'])b['ArrayUtils']['remove'](b['InternalData']['componentPatchQueries'][B]['query'],y,!![]);for(let C of document['querySelectorAll']('.'+y['name']+'-modal,\x20.'+y['name']['toLowerCase']()+'-modal,\x20.'+y['name']+'-settingsmodal,\x20.'+y['name']['toLowerCase']()+'-settingsmodal')){let D=C['querySelector'](b['dotCN']['modalclose']);if(D)D['click']();}delete b['DataUtils']['cached'][y['name']];delete window['PluginUpdates']['plugins'][A];delete y['started'];b['TimeUtils']['timeout'](E=>{delete y['stopping'];});};b['PluginUtils']['translate']=function(y){y['labels']={};if(typeof y['setLabelsByLanguage']==='function'||typeof y['changeLanguageStrings']==='function'){if(document['querySelector']('html')['lang'])z();else{let A=b['TimeUtils']['interval'](B=>{if(document['querySelector']('html')['lang']){b['TimeUtils']['clear'](A);z();}},0x64);}function z(){let B=b['LanguageUtils']['getLanguage']();if(typeof y['setLabelsByLanguage']==='function')y['labels']=y['setLabelsByLanguage'](B['id']);if(typeof y['changeLanguageStrings']==='function')y['changeLanguageStrings']();b['LogUtils']['log'](b['LanguageUtils']['LibraryStringsFormat']('toast_plugin_translated',B['ownlang']),y['name']);}}};b['PluginUtils']['checkUpdate']=function(y,z){if(y&&z)return new Promise(A=>{j['request'](z,(B,C,D)=>{if(B)return A(null);let E=D['match'](/['"][0-9]+\.[0-9]+\.[0-9]+['"]/i);if(!E)return A(null);if(b['NumberUtils']['getVersionDifference'](E[0x0],window['PluginUpdates']['plugins'][z]['version'])>0.2){b['NotificationUtils']['toast'](y+'\x20will\x20be\x20force\x20updated,\x20because\x20your\x20version\x20is\x20heavily\x20outdated.',{'type':'warn','nopointer':!![],'selector':'plugin-forceupdate-toast'});b['PluginUtils']['downloadUpdate'](y,z);return A(0x2);}else if(b['NumberUtils']['compareVersions'](E[0x0],window['PluginUpdates']['plugins'][z]['version'])){b['PluginUtils']['showUpdateNotice'](y,z);return A(0x1);}else{b['PluginUtils']['removeUpdateNotice'](y);return A(0x0);}});});return new Promise(A=>{callback(null);});};b['PluginUtils']['checkAllUpdates']=function(){return new Promise(y=>{let z=0x0,A=0x0;for(let B in window['PluginUpdates']['plugins']){let C=window['PluginUpdates']['plugins'][B];if(C)b['PluginUtils']['checkUpdate'](C['name'],C['raw'])['then'](D=>{z++;if(D==0x1)A++;if(z>=Object['keys'](window['PluginUpdates']['plugins'])['length'])y(A);});}});};b['PluginUtils']['showUpdateNotice']=function(y,z){if(!y||!z)return;let A=document['querySelector']('#pluginNotice');if(!A){A=b['NotificationUtils']['notice']('The\x20following\x20plugins\x20need\x20to\x20be\x20updated: ',{'html':!![],'id':'pluginNotice','type':'info','btn':!b['BDUtils']['isAutoLoadEnabled']()?'Reload':'','customicon':''});A['style']['setProperty']('display','block','important');A['style']['setProperty']('visibility','visible','important');A['style']['setProperty']('opacity','1','important');A['querySelector'](b['dotCN']['noticedismiss'])['addEventListener']('click',C=>{b['DOMUtils']['remove']('.update-clickme-tooltip');});let B=A['querySelector'](b['dotCN']['noticebutton']);if(B){b['DOMUtils']['toggle'](B,!![]);B['addEventListener']('click',C=>{j['electron']['remote']['getCurrentWindow']()['reload']();});B['addEventListener']('mouseenter',C=>{if(window['PluginUpdates']['downloaded'])b['TooltipUtils']['create'](B,window['PluginUpdates']['downloaded']['join'](',\x20'),{'type':'bottom','selector':'update-notice-tooltip','style':'max-width:\x20420px'});});}}if(A){let C=A['querySelector']('#outdatedPlugins');if(C&&!C['querySelector']('#'+y+'-notice')){if(C['querySelector']('span'))C['appendChild'](b['DOMUtils']['create'](',\x20'));let D=b['DOMUtils']['create'](''+y+'');D['addEventListener']('click',E=>{b['PluginUtils']['downloadUpdate'](y,z);});C['appendChild'](D);if(!document['querySelector']('.update-clickme-tooltip'))b['TooltipUtils']['create'](C,'Click\x20us!',{'type':'bottom','selector':'update-clickme-tooltip','delay':0x1f4});}}};b['PluginUtils']['removeUpdateNotice']=function(y,z=document['querySelector']('#pluginNotice')){if(!y||!z)return;let A=z['querySelector']('#outdatedPlugins');if(A){let B=A['querySelector']('#'+y+'-notice');if(B){let C=B['nextSibling'];let D=B['prevSibling'];if(C&&b['DOMUtils']['containsClass'](C,'separator'))C['remove']();else if(D&&b['DOMUtils']['containsClass'](D,'separator'))D['remove']();B['remove']();}if(!A['querySelector']('span')){let E=z['querySelector'](b['dotCN']['noticebutton']);if(E){z['querySelector']('.notice-message')['innerText']='To\x20finish\x20updating\x20you\x20need\x20to\x20reload.';b['DOMUtils']['toggle'](E,![]);}else z['querySelector'](b['dotCN']['noticedismiss'])['click']();}}};b['PluginUtils']['downloadUpdate']=function(y,z){if(!y||!z)return;j['request'](z,(A,B,C)=>{if(A)return b['LogUtils']['warn']('Unable\x20to\x20get\x20update\x20for\x20'+y);b['InternalData']['creationTime']=0x0;let D=C['match'](/['"][0-9]+\.[0-9]+\.[0-9]+['"]/i);D=D['toString']()['replace'](/['"]/g,'');j['fs']['writeFileSync'](j['path']['join'](b['BDUtils']['getPluginsFolder'](),z['split']('/')['slice'](-0x1)[0x0]),C);b['NotificationUtils']['toast'](y+'\x20v'+window['PluginUpdates']['plugins'][z]['version']+'\x20has\x20been\x20replaced\x20by\x20'+y+'\x20v'+D+'.',{'nopointer':!![],'selector':'plugin-updated-toast'});let E=document['querySelector']('#pluginNotice');if(E){if(E['querySelector'](b['dotCN']['noticebutton'])){window['PluginUpdates']['plugins'][z]['version']=D;if(!window['PluginUpdates']['downloaded'])window['PluginUpdates']['downloaded']=[];if(!window['PluginUpdates']['downloaded']['includes'](y))window['PluginUpdates']['downloaded']['push'](y);}b['PluginUtils']['removeUpdateNotice'](y,E);}});};b['PluginUtils']['checkChangeLog']=function(y){if(!b['ObjectUtils']['is'](y)||!y['changelog'])return;let z=b['DataUtils']['load'](y,'changelog');if(!z['currentversion']||b['NumberUtils']['compareVersions'](y['version'],z['currentversion'])){z['currentversion']=y['version'];b['DataUtils']['save'](z,y,'changelog');b['PluginUtils']['openChangeLog'](y);}};b['PluginUtils']['openChangeLog']=function(y){if(!b['ObjectUtils']['is'](y)||!y['changelog'])return;let z='',A={'added':'New\x20Features','fixed':'Bug\x20Fixes','improved':'Improvements','progress':'Progress'};for(let B in y['changelog']){B=B['toLowerCase']();let C=b['disCN']['changelog'+B];if(C){z+='