feat(background): 添加消息监听以支持复制文本功能

新增 `chrome.runtime.onMessage` 监听器,用于接收来自 popup 或 sidepanel 的
`copyText` 消息,并将该消息转发至当前活动标签页的内容脚本,实现跨组件通信
与剪贴板写入功能。同时更新 manifest.json 权限声明,增加 clipboardWrite 和
clipboardRead 权限以支持 navigator.clipboard API 的调用。

此外,简化了 sidepanel 的 HTML 结构并增强时间戳工具功能,包括动态切换时间戳
单位、实时刷新与复制到剪贴板等交互逻辑。
This commit is contained in:
雨霖铃
2025-11-11 23:56:53 +08:00
parent 3ab976b930
commit a42f1f2cce
5 changed files with 136 additions and 156 deletions
+17 -1
View File
@@ -1,6 +1,22 @@
chrome.action.onClicked.addListener(async (tab) => {
await chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["content.js"]
files: ['content.js'],
});
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'copyText') {
// 转发到当前活动的标签页
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs[0]?.id) {
chrome.tabs.sendMessage(tabs[0].id, message, (response) => {
sendResponse(response);
});
} else {
sendResponse({ success: false });
}
});
return true; // 异步响应
}
});