a42f1f2cce
新增 `chrome.runtime.onMessage` 监听器,用于接收来自 popup 或 sidepanel 的 `copyText` 消息,并将该消息转发至当前活动标签页的内容脚本,实现跨组件通信 与剪贴板写入功能。同时更新 manifest.json 权限声明,增加 clipboardWrite 和 clipboardRead 权限以支持 navigator.clipboard API 的调用。 此外,简化了 sidepanel 的 HTML 结构并增强时间戳工具功能,包括动态切换时间戳 单位、实时刷新与复制到剪贴板等交互逻辑。
23 lines
644 B
JavaScript
23 lines
644 B
JavaScript
chrome.action.onClicked.addListener(async (tab) => {
|
|
await chrome.scripting.executeScript({
|
|
target: { tabId: tab.id },
|
|
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; // 异步响应
|
|
}
|
|
});
|