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"
},
"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))
chrome.action.onClicked.addListener((tab) => {
// 当扩展图标被点击时,执行下面的代码
console.log('扩展图标被点击了!')
chrome.sidePanel.open({ windowId: tab.windowId });
})
console.log(1)
人工智能学习网站: