diff --git a/Jadefin.js b/Jadefin.js index 27e2d49..51a5d05 100644 --- a/Jadefin.js +++ b/Jadefin.js @@ -95,23 +95,14 @@ export default JadefinIntegrity("Jadefin", import.meta.url, () => window["Jadefi }; /** @type {(id: any) => string} */ - this.webpackIdToChunkJS = Object.values(this.webpackLoad).find(v => typeof(v) == "function" && v.toString().indexOf(`+".chunk.js"`) != -1); - + this.webpackChunkIdToJS = Object.values(this.webpackLoad).find(v => typeof(v) == "function" && v.toString().indexOf(`+".chunk.js"`) != -1); /** @type {(id: any) => string} */ - this.webpackIdToChunkCSS = Object.values(this.webpackLoad).find(v => typeof(v) == "function" && v.toString().indexOf(`+".css"`) != -1); - - const webpackIdToChunkJSKey = Object.keys(this.webpackLoad).find(k => this.webpackLoad?.[k] == this.webpackIdToChunkJS); - if (!this.webpackIdToChunkJS || !webpackIdToChunkJSKey) { - this.log.e("Couldn't obtain webpackIdToChunkJS"); + this.webpackIdToCSS = Object.values(this.webpackLoad).find(v => typeof(v) == "function" && v.toString().indexOf(`+".css"`) != -1); + if (!this.webpackChunkIdToJS || !this.webpackIdToCSS) { + this.log.e("Couldn't obtain webpackChunkIdToJS or webpackIdToCSS"); return; } - this.webpackLoad[webpackIdToChunkJSKey] = function(id) { - const rv = self.webpackIdToChunkJS?.(id); - self.log.v(`Webpack converted chunk ID to JS name: ${id} -> ${rv}`); - return rv; - }; - /** @type {(name: any, cb: any, sid: any, id: any) => any} */ this.webpackLoadChunkLowLevel = Object.values(this.webpackLoad).find(v => typeof(v) == "function" && v.toString().indexOf(`document.head.appendChild`) != -1); const webpackLoadChunkLowLevelKey = Object.keys(this.webpackLoad).find(k => this.webpackLoad?.[k] == this.webpackLoadChunkLowLevel); @@ -122,13 +113,11 @@ export default JadefinIntegrity("Jadefin", import.meta.url, () => window["Jadefi this.webpackLoad[webpackLoadChunkLowLevelKey] = function(name, cb, sid, id) { const _cb = cb; - self.log.v(`Webpack loading chunk ${id} (${sid}) from ${name}`); - /* + // self.log.v(`Webpack loading chunk ${id} (${sid}) from ${name}`); cb = (event) => { self.log.v(`Webpack loaded chunk ${id} (${sid}) from ${name}: ${event.type}`); return _cb(event); }; - */ const rv = self.webpackLoadChunkLowLevel?.(name, cb, sid, id); return rv; }; @@ -136,12 +125,33 @@ export default JadefinIntegrity("Jadefin", import.meta.url, () => window["Jadefi /** @type {(id: any) => Promise} */ this.webpackLoadChunk = Object.values(this.webpackLoad).find(v => typeof(v) == "function" && v.toString().indexOf(`Object.keys(`) != -1 && v.toString().indexOf(`}),[])`) != -1); - // HACKFIX: Load all chunks when Jadefin initializes! - // webpackIdToChunkJS contains all IDs either ahead of === or : - // FIXME: This smells like race condition hell! We might be too late for this kind of hooking. - // FIXME: Ideally, don't. This makes startup take ages. - const webpackChunks = [...this.webpackIdToChunkJS.toString().matchAll(/\d+(?=:|=)/g)].map(v => parseInt(v[0])); - await Promise.all(webpackChunks.map(id => this.webpackLoadChunk?.(id))); + // HACK: Load all chunks we could need when Jadefin initializes! + // webpackChunkIdToJS contains all IDs either ahead of === or : + // FIXME: Ideally, don't. This makes startup take ages and is unreliable! + this.webpackChunkIds = [...this.webpackChunkIdToJS.toString().matchAll(/\d+(?=:|=)/g)].map(v => parseInt(v[0])); + /** @type {any} */ + this.webpackChunkJSs = {}; + for (const id of this.webpackChunkIds) { + this.webpackChunkJSs[this.webpackChunkIdToJS(id)] = id; + } + + // Grabbed via JSON.stringify(webpackChunk.flatMap(c => c[0])) on the home screen. + const webpackChunkIdsWanted = JSON.parse("[1451,45642,23247,60815,81771,55931,1270,9886,12036,86897,59928,44965,56401,7495,17060,67224,67622,94048,36933,82363,36546,99377,82798,14577,78283,37658,94160,7184,83518,15277,71779,9911,82420,49398,32292,37821,74776,99994,87074,67942,60039,27017,65149,27182,4636,87530,4801,82255,99435,77077,71944,59874,21816,89409,79754,69285,43091,64380,40810,90186,87903,70118,64633,10905,68672,71318,86040,70555,41542,4836,30357,6270,49087,64706,19907,927,10672,2,56577,29593,55125,83354,49755,1680,39573,40394,60138,13151,65849,80835,14510,96307,16304,62155,84430,59258,37658,94160,7184,83518,15277,71779,9911,82420,49398,32292,39232,40465,18395,48979,68413,60039,27017,65149,27182,4636,87530,4801,82255,99435,77077,71944,59874,21816,80183,85500,7011,22940,33067,15434,39435,78938,94047,55802,18084,79617,1998,15605,57949,21857,91737,28567,22424,44184,45568,14510,96307,5617,96084,40367,73233,52011,40367,96084,56422,27962,96084,32762,35463,8372,28349,58782,29808,18119,24468,50777,84158,49275,35308,38965]"); + + // Grabbed through searching for module loads which still errored out. + webpackChunkIdsWanted.push( + ...Object.keys(this.webpackChunkJSs).filter(js => { + return false || + js.startsWith("user-display.") || + js.startsWith("user-display-") || + js.startsWith("53147.") || + js.startsWith("activity.") || + js.startsWith("node_modules.@juggle.") || + false; + }).map(js => this.webpackChunkJSs[js]) + ); + + await Promise.all(webpackChunkIdsWanted.map(id => this.webpackLoadChunk?.(id))); // Wait until everything else is ready. await JadefinUtils.waitUntil(() => this.webpackModuleFuncs);