mirror of
				https://github.com/smartfrigde/armcord.git
				synced 2024-08-14 23:56:58 +00:00 
			
		
		
		
	
							parent
							
								
									c8107ef588
								
							
						
					
					
						commit
						b5a6a2b579
					
				
					 1 changed files with 86 additions and 76 deletions
				
			
		|  | @ -1,43 +1,55 @@ | ||||||
| window.addEventListener( | window.addEventListener("load", async () => { | ||||||
|     "load", |   let Dispatcher = undefined, | ||||||
|     (() => { |     lookupAsset = undefined, | ||||||
|         let Dispatcher, |     lookupApp = undefined; | ||||||
|             lookupAsset, |  | ||||||
|             lookupApp, |  | ||||||
|             apps = {}; |  | ||||||
| 
 | 
 | ||||||
|         ArmCordRPC.listen(async (data) => { |   let apps = {}; | ||||||
|             msg = data; //already parsed
 |   const chunkName = 'webpackChunkdiscord_app'; | ||||||
|             //console.log(msg);
 | 
 | ||||||
|  |   const wpRequire = window[chunkName].push( | ||||||
|  |     [ [Symbol()], {}, (x) => x ] | ||||||
|  |   ); | ||||||
| 
 | 
 | ||||||
|             if (!Dispatcher) { |  | ||||||
|                 const wpRequire = window.webpackChunkdiscord_app.push([[Symbol()], {}, (x) => x]); |  | ||||||
|   const cache = wpRequire.c; |   const cache = wpRequire.c; | ||||||
|                 window.webpackChunkdiscord_app.pop(); |   window[chunkName].pop(); | ||||||
| 
 | 
 | ||||||
|   for (const id in cache) { |   for (const id in cache) { | ||||||
|     let mod = cache[id].exports; |     let mod = cache[id].exports; | ||||||
|                     for (const prop in mod) { |     if (typeof mod !== "object") continue; | ||||||
|                         const candidate = mod[prop]; | 
 | ||||||
|  |     let candidates; | ||||||
|  |     try { | ||||||
|  |       candidates = Object.values(mod); | ||||||
|  |     } catch { | ||||||
|  |       continue; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     for (const candidate of candidates) { | ||||||
|       if (candidate && candidate.register && candidate.wait) { |       if (candidate && candidate.register && candidate.wait) { | ||||||
|         Dispatcher = candidate; |         Dispatcher = candidate; | ||||||
|         break; |         break; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|                     if (Dispatcher) break; // make sure to exit outer loop as well
 |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   const factories = wpRequire.m; |   const factories = wpRequire.m; | ||||||
|   for (const id in factories) { |   for (const id in factories) { | ||||||
|                     if (factories[id].toString().includes("getAssetImage: size must === [number, number] for Twitch")) { |     if ( | ||||||
|  |       factories[id] | ||||||
|  |         .toString() | ||||||
|  |         .includes("getAssetImage: size must === [number, number] for Twitch") | ||||||
|  |     ) { | ||||||
|       const mod = wpRequire(id); |       const mod = wpRequire(id); | ||||||
| 
 | 
 | ||||||
|       // fetchAssetIds
 |       // fetchAssetIds
 | ||||||
|       const _lookupAsset = Object.values(mod).find( |       const _lookupAsset = Object.values(mod).find( | ||||||
|                             (e) => typeof e === "function" && e.toString().includes("APPLICATION_ASSETS_FETCH_SUCCESS") |         (e) => | ||||||
|  |           typeof e === "function" && | ||||||
|  |           e.toString().includes("APPLICATION_ASSETS_FETCH_SUCCESS"), | ||||||
|       ); |       ); | ||||||
|       if (_lookupAsset) |       if (_lookupAsset) | ||||||
|                             lookupAsset = async (appId, name) => (await _lookupAsset(appId, [name, undefined]))[0]; |         lookupAsset = async (appId, name) => | ||||||
|  |           (await _lookupAsset(appId, [name, undefined]))[0]; | ||||||
|     } |     } | ||||||
|     if (lookupAsset) break; |     if (lookupAsset) break; | ||||||
|   } |   } | ||||||
|  | @ -48,7 +60,7 @@ window.addEventListener( | ||||||
| 
 | 
 | ||||||
|       // fetchApplicationsRPC
 |       // fetchApplicationsRPC
 | ||||||
|       const _lookupApp = Object.values(mod).find( |       const _lookupApp = Object.values(mod).find( | ||||||
|                             (e) => typeof e === "function" && e.toString().includes(",coverImage:") |         (e) => typeof e === "function" && e.toString().includes(",coverImage:"), | ||||||
|       ); |       ); | ||||||
|       if (_lookupApp) |       if (_lookupApp) | ||||||
|         lookupApp = async (appId) => { |         lookupApp = async (appId) => { | ||||||
|  | @ -59,23 +71,22 @@ window.addEventListener( | ||||||
|     } |     } | ||||||
|     if (lookupApp) break; |     if (lookupApp) break; | ||||||
|   } |   } | ||||||
|             } |  | ||||||
| 
 | 
 | ||||||
|             if (msg.activity?.assets?.large_image) |   ArmCordRPC.listen(async (msg) => { | ||||||
|  |     if (msg.activity) { | ||||||
|  |       if (msg.activity?.assets?.large_image && lookupAsset) | ||||||
|         msg.activity.assets.large_image = await lookupAsset( |         msg.activity.assets.large_image = await lookupAsset( | ||||||
|           msg.activity.application_id, |           msg.activity.application_id, | ||||||
|                     msg.activity.assets.large_image |           msg.activity.assets.large_image, | ||||||
|         ); |         ); | ||||||
|             if (msg.activity?.assets?.small_image) |       if (msg.activity?.assets?.small_image && lookupAsset) | ||||||
|         msg.activity.assets.small_image = await lookupAsset( |         msg.activity.assets.small_image = await lookupAsset( | ||||||
|           msg.activity.application_id, |           msg.activity.application_id, | ||||||
|                     msg.activity.assets.small_image |           msg.activity.assets.small_image, | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
|             // prevent errors when activity is null and let activity stop
 |  | ||||||
|             if (msg.activity) { |  | ||||||
|       const appId = msg.activity.application_id; |       const appId = msg.activity.application_id; | ||||||
|                 if (!apps[appId]) apps[appId] = await lookupApp(appId); |       if (!apps[appId] && lookupApp) apps[appId] = await lookupApp(appId); | ||||||
| 
 | 
 | ||||||
|       const app = apps[appId]; |       const app = apps[appId]; | ||||||
|       if (!msg.activity.name) msg.activity.name = app.name; |       if (!msg.activity.name) msg.activity.name = app.name; | ||||||
|  | @ -83,5 +94,4 @@ window.addEventListener( | ||||||
| 
 | 
 | ||||||
|     Dispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", ...msg }); // set RPC status
 |     Dispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", ...msg }); // set RPC status
 | ||||||
|   }); |   }); | ||||||
|     })() | }); | ||||||
| ); |  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue