import { useState, useEffect } from "react"; import parseBuilder, { readVars } from "./builder"; import { AiFillSave } from "react-icons/ai"; const placeholder = `Enter your variables here like below. group1Delim:\\n \tvar1:\\w \tvar2:\\d \tgroup2Delim:\\s \t\tvar3:\\w \t\tvar4:\\d`; function App() { const [valid, setValid] = useState(false); const [build, setBuild] = useState(""); const [edited, setEdited] = useState(0); const [target, setTarget] = useState(null); const [save, setSave] = useState(true); const [hideVariables, setHideVariables] = useState(false); const [hideBuilder, setHideBuilder] = useState(false); const [varText, setVarText] = useState(""); const [builderText, setBuilderText] = useState(""); console.log("app is running"); const regexInput = document.querySelector( "#regex-app > div > div.QtZzw > div > div.AUc0W > div.rjodX > div.cO83v > div.h9z_E.T886D > div > div > div:nth-child(1) > textarea" ); const regexValue = document.querySelector( "#regex-app > div > div.QtZzw > div > div.AUc0W > div.rjodX > div.cO83v > div.h9z_E.T886D > div > div > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code" ); const hideButton = (setHide, hide) => { return (
); }; const variables = (
{hideButton(setHideVariables, hideVariables)}
); const builder = (
{hideButton(setHideBuilder, hideBuilder)}
); const updateRegex = () => { if (edited !== 0 || !save) return; saveBuild(); }; useEffect(updateRegex, [edited]); useEffect(() => { if (save) saveBuild(); }, [save]); return (
Build Variables
{variables}
Build Regex
{builder}
{saveButton(setSave, save)}
); function saveBuild() { if (!regexValue) return; const length = regexValue.textContent.length; for (let i = 0; i < length; i++) regexInput.dispatchEvent( new KeyboardEvent("keydown", { key: "Backspace", code: "Backspace", keyCode: 8, }) ); regexInput.value = build; setTimeout(() => target?.focus(), 100); } } export default App; function saveButton(setSave, save) { const active = "bg-blue-500 h-10 p-1 rounded-sm hover:bg-blue-100"; const inactive = "bg-blue-100 h-10 p-1 rounded-sm hover:bg-blue-500"; const activeSave = ; const inactiveSave = ; return ( ); }