From e447dec67b3e9b06df8dfe6204287fcc2a8bab07 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Fri, 16 May 2025 21:33:41 +0200 Subject: [PATCH 1/2] UserScript: fix 'headers.get is not a function' error --- browser/GMPolyfill.js | 13 ++++--------- browser/userscript.meta.js | 1 + 2 files changed, 5 insertions(+), 9 deletions(-) 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 1d986aae..be3b0dd0 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 From b4dddfda4764e9d37cc93099fe532be7e8a0f3de Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Fri, 16 May 2025 17:07:33 -0300 Subject: [PATCH 2/2] Webpack: Make findStore compatible with libdiscore stores --- src/plugins/consoleShortcuts/index.ts | 18 +++++++++++++++++- src/webpack/webpack.ts | 23 +++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/plugins/consoleShortcuts/index.ts b/src/plugins/consoleShortcuts/index.ts index e8150f8f..feeada9e 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 ec9e99be..98e7d4d1 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -468,6 +468,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 }); }