智能助手 

外观
麦肯锡工作法之如何了解一个新的行业:
- 100 个关键词法:掌握这个行业的 100 个关键词
- 问专家:找这个行业的三个专家聊天,问这个行业的各种问题
- 看书:精读三本这个行业的经典书籍
提示
1. 清单文件(manifest.json)
2. 弹出页面(Popup)
3. 背景脚本(Background Scripts)
4. 内容脚本(Content Scripts)
5. 权限(Permissions)
manifest.json
中声明需要访问的浏览器功能或网站资源。6. 浏览器操作(Browser Action)和页面操作(Page Action)
7. 选项页面(Options Page)
8. 消息传递(Messaging)
9. Chrome 扩展 API
10. 调试与测试
明确目标:
chrome-plugin
├─ src
│ ├─ background
│ │ └─ background.js
│ ├─ icons
│ │ ├─ icon128.png
│ │ └─ icon48.png
│ ├─ App.css
│ ├─ App.jsx
│ ├─ MyChildren.jsx
│ ├─ index.css
│ └─ main.jsx
├─ .gitignore
├─ index.html
├─ manifest.json
├─ package-lock.json
├─ package.json
└─ vite.config.js
manifest.json 是插件的核心配置文件:
{
"manifest_version": 3,
"name": "智能体插件",
"author": "tuyongtao",
"version": "1.0.0",
"permissions": [
"contextMenus",
"activeTab",
"cookies",
"tabs",
"sidePanel",
"scripting",
"storage"
],
"side_panel": {
"default_path": "index.html"
},
"action": { "default_popup": "index.html" },
"icons": {
"48": "src/icons/icon48.png",
"128": "src/icons/icon128.png"
},
"background": {
"service_worker": "src/background/background.js"
},
"web_accessible_resources": [
{
"resources": ["index.html", "*"],
"matches": ["<all_urls>"]
}
],
"host_permissions": ["<all_urls>"]
}
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { crx } from "@crxjs/vite-plugin";
import manifest from "./manifest.json";
export default defineConfig({
plugins: [react(), crx({ manifest })],
server: {
host: "local.jd.com",
},
});
// 创建上下文菜单项
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create(
{
id: "sendOkChatData",
title: "智能填表",
contexts: ["selection"],
},
() => {
if (chrome.runtime.lastError) {
console.error(
"Error creating sendData menu:",
chrome.runtime.lastError
);
} else {
console.log("sendData menu created successfully");
}
}
);
});
// 监听上下文菜单点击事件
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "sendOkChatData" && tab.id) {
const selectedText = info.selectionText;
// 获取当前活动的标签页
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs.length > 0) {
const activeTab = tabs[0];
chrome.scripting.executeScript({
target: { tabId: activeTab.id },
func: (text) => {
window.postMessage({ type: "sendOkChatData", data: text }, "*");
},
args: [selectedText],
});
} else {
console.error("No active tab found.");
}
});
}
});
点击网站右侧图标即可
版权归属:tuyongtao1