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
+13
View File
@@ -82,4 +82,17 @@
iframe.style.transform = visible ? 'translateX(0)' : 'translateX(100%)';
}
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'copyText') {
navigator.clipboard
.writeText(message.data)
.then(() => sendResponse({ success: true }))
.catch((err) => {
console.error('❌ 复制失败:', err);
sendResponse({ success: false, error: err });
});
return true;
}
});
})();