eval done && fix findDOMNode warning

This commit is contained in:
go0p
2024-05-15 14:43:04 +08:00
committed by go0p
parent 6358fc720d
commit 207e8172f1
10 changed files with 87 additions and 102 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ function App() {
}}
>
<div className="App">
<Contro/>
{/*<Contro/>*/}
<Proxifier/>
<EvalInTab/>
+1 -2
View File
@@ -10,7 +10,6 @@ import {
} from "@assets/icon/icon";
import {wsc} from "@network/chrome";
import "./Contro.css";
import {ActionType} from "@network/chrome";
interface ControProps {
}
@@ -39,7 +38,7 @@ export const Contro: React.FC<ControProps> = () => {
}
wsc.onWSCMessage((message) => {
if (message.action === ActionType.STATUS) {
if (message.action === wsc.ActionType.STATUS) {
if (message.connected === false) {
handleConnectFail();
} else {
+7 -8
View File
@@ -2,7 +2,6 @@ import React, {useEffect, useState} from "react";
import {Button, Input} from "antd";
import TextArea from "antd/lib/input/TextArea";
import {wsc} from "@network/chrome";
import {ActionType} from "@network/chrome";
interface EvalInTabProps {
}
@@ -14,7 +13,7 @@ export const EvalInTab: React.FC<EvalInTabProps> = () => {
useEffect(() => {
wsc.onWSCMessage((message) => {
if (message.action === ActionType.TO_EXTENSION_PAGE) {
if (message.action === wsc.ActionType.TO_EXTENSION_PAGE) {
console.log("res:", message.result);
alert("from content script: " + JSON.stringify(message.result));
}
@@ -23,10 +22,10 @@ export const EvalInTab: React.FC<EvalInTabProps> = () => {
const handleClick = async () => {
try {
const tabId = await wsc.getTabId();
const [tab] = await wsc.getTab();
await chrome.runtime.sendMessage({
action: ActionType.INJECT_SCRIPT,
tabId: tabId,
action: wsc.ActionType.INJECT_SCRIPT,
tabId: tab.id,
value: {mode: "CONTENT_CALL_FUNCTION", fn_name: funcName, args: inputArgsData},
});
} catch (error) {
@@ -40,10 +39,10 @@ export const EvalInTab: React.FC<EvalInTabProps> = () => {
const handleEvalCodeClick = async () => {
try {
const tabId = await wsc.getTabId();
const [tab] = await wsc.getTab();
await chrome.runtime.sendMessage({
action: ActionType.INJECT_SCRIPT,
tabId: tabId,
action: wsc.ActionType.INJECT_SCRIPT,
tabId: tab.id,
value: {mode: "CONTENT_EVAL_CODE", code: code},
});
} catch (error) {
+2 -2
View File
@@ -268,13 +268,13 @@ export const Proxifier: React.FC<ProxifierProps> = () => {
item.port === ""
}
onChange={(checked: boolean) => {
wsc.clearproxy();
wsc.clearProxy();
const copyProxyList = structuredClone(proxyList);
copyProxyList.forEach((i) => {
if (i.id === item.id) {
i.open = checked;
if (checked) {
wsc.setproxy(item.scheme, item.host, Number(item.port));
wsc.setProxy(item.scheme, item.host, Number(item.port));
}
} else {
i.open = false;
+17 -23
View File
@@ -1,15 +1,16 @@
export enum ActionType {
CONNECT = 'connect',
DISCONNECT = 'disconnect',
STATUS = 'status',
PROXY_STATUS = 'proxy_status',
SET_PROXY = 'set_proxy',
CLEAR_PROXY = 'clear_proxy',
INJECT_SCRIPT = 'yakit_inject_script',
TO_EXTENSION_PAGE = "yakit_to_extension_page",
}
export namespace wsc {
export enum ActionType {
CONNECT = 'connect',
DISCONNECT = 'disconnect',
STATUS = 'status',
PROXY_STATUS = 'proxy_status',
SET_PROXY = 'set_proxy',
CLEAR_PROXY = 'clear_proxy',
INJECT_SCRIPT = 'yakit_inject_script',
// 用于接收来自content script的消息
TO_EXTENSION_PAGE = "yakit_to_extension_page",
}
export function connect(port: number, host?: string) {
chrome.runtime.sendMessage({
action: ActionType.CONNECT,
@@ -44,23 +45,16 @@ export namespace wsc {
chrome.runtime.onMessage.addListener(onMessage)
}
export function setproxy(scheme: string, host: string, port: number) {
export function setProxy(scheme: string, host: string, port: number) {
chrome.runtime.sendMessage({action: ActionType.SET_PROXY, scheme, host, port})
}
export function clearproxy() {
export function clearProxy() {
chrome.runtime.sendMessage({action: ActionType.CLEAR_PROXY})
}
export function getTabId() {
return new Promise<number>((resolve, reject) => {
chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {
if (tabs.length) {
resolve(tabs[0].id);
} else {
reject('No active tab found');
}
});
});
// 获取当前tab
export async function getTab() {
return chrome.tabs.query({active: true, currentWindow: true})
}
}