import React, {useEffect, useState} from "react"; import {Button, Input} from "antd"; import TextArea from "antd/lib/input/TextArea"; import {wsc} from "@network/chrome"; interface EvalInTabProps { } export const EvalInTab: React.FC = () => { const [funcName, setFuncName] = useState(""); const [inputArgsData, setInputArgsData] = useState(""); const [code, setCode] = useState(""); useEffect(() => { wsc.onWSCMessage((message) => { console.log("message from content script:", message) if (message.action === wsc.ActionType.TO_EXTENSION_PAGE) { console.log("eval in tab:", message.result); // alert("from content script: " + JSON.stringify(message.result)); // 发送结果 wsc.sendMessage({"type": "chrome-extension", res: message.result}) } }); }, []); const handleClick = async () => { try { const [tab] = await wsc.getTab(); await chrome.runtime.sendMessage({ action: wsc.ActionType.INJECT_SCRIPT, tabId: tab.id, value: {mode: "CONTENT_CALL_FUNCTION", fn_name: funcName, args: inputArgsData}, }); } catch (error) { console.log("error:", error) } }; const handleInputChange = (event: React.ChangeEvent) => { setInputArgsData(event.target.value); }; const handleEvalCodeClick = async () => { try { const [tab] = await wsc.getTab(); await chrome.runtime.sendMessage({ action: wsc.ActionType.INJECT_SCRIPT, tabId: tab.id, value: { mode: "CONTENT_EVAL_CODE", code: code, }, }); } catch (error) { } } return (
setFuncName(e.target.value)} placeholder="Enter function name" >