chrome扩展通过点击图标控制侧边栏的显示和隐藏

manifest.json:

{
  "manifest_version": 3,
  "name": "ChatGPT学习",
  "version": "0.0.6",
  "description": "欢迎加入我们一起学习ChatGPT",
  "icons": {
    "16": "./src/images/logo.png",
    "48": "./src/images/logo.png",
    "128": "./src/images/logo.png"
  },
  "side_panel": {
    "default_path": "./src/views/panel.html",
    "openPanelOnActionClick": true
  },
  "permissions": ["sidePanel"],
  "action": {
    "default_title": "点击打开ChatGPT学习侧边栏"
  },
  "background": {
    "service_worker": "./src/scripts/service-worker.js"
  },
  "content_scripts": [
    {
      "matches": ["http://*/*", "https://*/*"],
      "exclude_matches": [
        "https://chat.xutongbao.top/*",
        "http://localhost:*/*"
      ],
      "css": ["./dist/lib/layui.css", "./dist/css/app.css"],
      "js": ["./dist/lib/layui.js", "./dist/js/app.js", "./index.js"]
    }
  ],
  "content_security_policy": {
    "extension_pages": "script-src 'self'; object-src 'self';"
  }
}

./src/scripts/service-worker.js:

 chrome.sidePanel
   .setPanelBehavior({ openPanelOnActionClick: true })
   .catch((error) => console.error(error))

人工智能学习网站:

https://chat.xutongbao.top

posted @ 2024-03-26 09:05  徐同保  阅读(13)  评论(0编辑  收藏  举报  来源