Hotfix for Discord's switch to rspack (#1685)

* Fix patchable modules

* Fix bd-head location and modals
This commit is contained in:
Zerebos 2023-10-26 15:26:09 -04:00 committed by GitHub
parent 68688684a6
commit 19e622e455
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 27 deletions

View File

@ -34,24 +34,20 @@ export default function () {
if (!Reflect.has(window, chunkName)) {
predefine(window, chunkName, instance => {
predefine(instance, "push", () => {
instance.push([[Symbol()], {}, require => {
require.d = (target, exports) => {
for (const key in exports) {
if (!Reflect.has(exports, key) || target[key]) continue;
Object.defineProperty(target, key, {
get: () => exports[key](),
set: v => {exports[key] = () => v;},
enumerable: true,
configurable: true
});
}
};
}]);
instance.pop();
});
instance.push([[Symbol()], {}, require => {
require.d = (target, exports) => {
for (const key in exports) {
if (!Reflect.has(exports, key) || target[key]) continue;
Object.defineProperty(target, key, {
get: () => exports[key](),
set: v => {exports[key] = () => v;},
enumerable: true,
configurable: true
});
}
};
}]);
});
}
};

View File

@ -198,7 +198,7 @@ export default class DOMManager {
}
}
DOMManager.createElement("bd-head", {target: document.head});
DOMManager.createElement("bd-head", {target: document.body});
DOMManager.createElement("bd-body", {target: document.body});
DOMManager.createElement("bd-scripts", {target: DOMManager.bdHead});
DOMManager.createElement("bd-styles", {target: DOMManager.bdHead});

View File

@ -190,7 +190,7 @@ export default class WebpackModules {
if (!modules.hasOwnProperty(index)) continue;
let module = null;
try {module = modules[index]} catch {continue;};
try {module = modules[index];} catch {continue;}
const {exports} = module;
if (!exports || exports === window || exports === document.documentElement || exports[Symbol.toStringTag] === "DOMTokenList") continue;

View File

@ -21,10 +21,7 @@ export default class Modals {
static get shouldShowAddonErrors() {return Settings.get("settings", "addons", "addonErrors");}
static get ModalActions() {
return this._ModalActions ??= {
openModal: WebpackModules.getModule(m => typeof m === "function" && m?.toString().includes("onCloseCallback") && m?.toString().includes("Layer"), {searchExports: true}),
closeModal: WebpackModules.getModule(m => typeof m === "function" && m?.toString().includes("onCloseCallback()"), {searchExports: true})
};
return this._ModalActions ??= WebpackModules.getByProps("openModal", "closeModal");
}
static get ModalStack() {return this._ModalStack ??= WebpackModules.getByProps("push", "update", "pop", "popWithKey");}
static get ModalComponents() {return this._ModalComponents ??= WebpackModules.getByProps("Header", "Footer");}
@ -32,7 +29,7 @@ export default class Modals {
static get ModalClasses() {return this._ModalClasses ??= WebpackModules.getByProps("modal", "content");}
static get FlexElements() {return this._FlexElements ??= WebpackModules.getByProps("Child", "Align");}
static get TextElement() {return this._TextElement ??= WebpackModules.getModule(m => m?.Sizes?.SIZE_32 && m.Colors);}
static get ConfirmationModal() {return this._ConfirmationModal ??= WebpackModules.getModule(m => m?.toString?.()?.includes(".confirmButtonColor"), {searchExports: true});}
static get ConfirmationModal() {return this._ConfirmationModal ??= WebpackModules.getByProps("ConfirmModal").ConfirmModal;}
static get Markdown() {return this._Markdown ??= WebpackModules.find(m => m?.prototype?.render && m.rules);}
static get Buttons() {return this._Buttons ??= WebpackModules.getModule(m => m.BorderColors, {searchExports: true});}
static get ModalQueue() {return this._ModalQueue ??= [];}
@ -237,8 +234,8 @@ export default class Modals {
static showChangelogModal(options = {}) {
const OriginalModalClasses = WebpackModules.getByProps("hideOnFullscreen", "root");
const ChangelogModalClasses = WebpackModules.getModule(m => m.modal && m.maxModalWidth);
const ChangelogClasses = WebpackModules.getByProps("fixed", "improved") ?? {maxModalWidth: "490px",video: "video-8B-TdZ",container: "container-3PVapX",image: "image-ZPv20Y",title: "title-2ftWWc",lead: "lead-2VtcIe",added: "added-mQcv9V title-2ftWWc",fixed: "fixed-cTX7Hp title-2ftWWc",improved: "improved-2SJXHz title-2ftWWc",progress: "progress-1DcfFh title-2ftWWc",marginTop: "marginTop-VGmU1T",footer: "footer-1gMODG",socialLink: "socialLink-1qjJIk",premiumBanner: "premiumBanner-FU1Urp",premiumIcon: "premiumIcon-rhwgnW",date: "date-2tmzZM"};
const ChangelogModalClasses = WebpackModules.getModule(m => typeof(m) === "object" && Object.keys(m).length === 2 && m.modal && m.content);
const ChangelogClasses = WebpackModules.getByProps("fixed", "improved") ?? {added: "added__838d6", container: "container__2475a", date: "date__6a5c1", fixed: "fixed_f67fc0", footer: "footer__33610", image: "image__58d6f", improved: "improved_fd72d9", lead: "lead__5fdb1", marginTop: "marginTop__0baf0", premiumBanner: "premiumBanner_d2ce99", premiumIcon: "premiumIcon_a78bd4", progress: "progress__8e0f4", socialLink: "socialLink__64e09", title: "title__19dfe", video: "video__4de58"};
const TextElement = this.TextElement;
const FlexChild = this.FlexElements;
const MarkdownParser = WebpackModules.getByProps("defaultRules", "parse");