diff --git a/browser/GMPolyfill.js b/browser/GMPolyfill.js index 387389ce..1f1b8878 100644 --- a/browser/GMPolyfill.js +++ b/browser/GMPolyfill.js @@ -17,9 +17,10 @@ */ function parseHeaders(headers) { + const result = new Headers(); if (!headers) - return {}; - const result = {}; + return result; + const headersArr = headers.trim().split("\n"); for (var i = 0; i < headersArr.length; i++) { var row = headersArr[i]; @@ -27,13 +28,7 @@ function parseHeaders(headers) { , key = row.slice(0, index).trim().toLowerCase() , value = row.slice(index + 1).trim(); - if (result[key] === undefined) { - result[key] = value; - } else if (Array.isArray(result[key])) { - result[key].push(value); - } else { - result[key] = [result[key], value]; - } + result.append(key, value); } return result; } diff --git a/browser/userscript.meta.js b/browser/userscript.meta.js index 32f3c381..7b3278d2 100644 --- a/browser/userscript.meta.js +++ b/browser/userscript.meta.js @@ -9,6 +9,7 @@ // @license GPL-3.0 // @match *://*.discord.com/* // @grant GM_xmlhttpRequest +// @grant unsafeWindow // @run-at document-start // @compatible chrome Chrome + Tampermonkey or Violentmonkey // @compatible firefox Firefox Tampermonkey diff --git a/src/plugins/consoleShortcuts/index.ts b/src/plugins/consoleShortcuts/index.ts index 813653a4..048d2903 100644 --- a/src/plugins/consoleShortcuts/index.ts +++ b/src/plugins/consoleShortcuts/index.ts @@ -74,6 +74,22 @@ function makeShortcuts() { }; } + function findStoreWrapper(findStore: typeof Webpack.findStore) { + const cache = new Map(); + + return function (storeName: string) { + const cacheKey = String(storeName); + if (cache.has(cacheKey)) return cache.get(cacheKey); + + let store: unknown; + try { + store = findStore(storeName); + } catch { } + if (store) cache.set(cacheKey, store); + return store; + }; + } + let fakeRenderWin: WeakRef | undefined; const find = newFindWrapper(f => f); const findByProps = newFindWrapper(filters.byProps); @@ -98,7 +114,7 @@ function makeShortcuts() { findComponentByCode: newFindWrapper(filters.componentByCode), findAllComponentsByCode: (...code: string[]) => findAll(filters.componentByCode(...code)), findExportedComponent: (...props: string[]) => findByProps(...props)[props[0]], - findStore: newFindWrapper(filters.byStoreName), + findStore: findStoreWrapper(Webpack.findStore), PluginsApi: { getter: () => Vencord.Plugins }, plugins: { getter: () => Vencord.Plugins.plugins }, Settings: { getter: () => Vencord.Settings }, diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index a1812f3c..b6a1cd27 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -470,6 +470,29 @@ export function findStore(name: StoreNameFilter) { } } + try { + const getLibdiscore = findByCode("libdiscoreWasm is not initialized"); + const libdiscoreExports = getLibdiscore(); + + for (const libdiscoreExportName in libdiscoreExports) { + if (!libdiscoreExportName.endsWith("Store")) { + continue; + } + + const storeName = libdiscoreExportName; + const store = libdiscoreExports[storeName]; + + if (storeName === name) { + res = store; + } + + if (fluxStores[storeName] == null) { + fluxStores[storeName] = store; + } + } + + } catch { } + if (res == null) { res = find(filters.byStoreName(name), { isIndirect: true }); }