/* * Vencord, a modification for Discord's desktop app * Copyright (c) 2022 Vendicated and contributors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import { CodeBlock } from "@components/CodeBlock"; import { Flex } from "@components/Flex"; import { SettingsTab, wrapTab } from "@components/settings/tabs/BaseTab"; import { debounce } from "@shared/debounce"; import { Margins } from "@utils/margins"; import { copyWithToast } from "@utils/misc"; import { stripIndent } from "@utils/text"; import { ReplaceFn } from "@utils/types"; import { search } from "@webpack"; import { Button, Forms, React, TextInput, useMemo, useState } from "@webpack/common"; import { FullPatchInput } from "./FullPatchInput"; import { PatchPreview } from "./PatchPreview"; import { ReplacementInput } from "./ReplacementInput"; const findCandidates = debounce(function ({ find, setModule, setError }) { const candidates = search(find); const keys = Object.keys(candidates); const len = keys.length; if (len === 0) setError("No match. Perhaps that module is lazy loaded?"); else if (len !== 1) setError("Multiple matches. Please refine your filter"); else setModule([keys[0], candidates[keys[0]]]); }); function PatchHelper() { const [find, setFind] = useState(""); const [match, setMatch] = useState(""); const [replacement, setReplacement] = useState(""); const [parsedFind, setParsedFind] = useState(""); const [findError, setFindError] = useState(); const [matchError, setMatchError] = useState(); const [replacementError, setReplacementError] = useState(); const [module, setModule] = useState<[number, Function]>(); const code = useMemo(() => { const find = parsedFind instanceof RegExp ? parsedFind.toString() : JSON.stringify(parsedFind); const replace = typeof replacement === "function" ? replacement.toString() : JSON.stringify(replacement); return stripIndent` { find: ${find}, replacement: { match: /${match.replace(/(? full patch find match
{module && ( )} {!!(find && match && replacement) && ( <> Code )} ); } export default IS_DEV ? wrapTab(PatchHelper, "PatchHelper") : null;