feat: improve Clipboard Sniffer extension integration and UI fixes

This commit is contained in:
2026-02-27 03:37:33 +00:00
parent 1d7fd9a5bc
commit 8e8bf47297
14 changed files with 872 additions and 181 deletions

66
extension/content.js Normal file
View File

@@ -0,0 +1,66 @@
// content.js
// This script runs on the web app page (e.g. localhost:5173)
console.log('Tools App Extension: Content script injected');
// Listen for messages from the Web App (Vue)
window.addEventListener('message', (event) => {
// We should verify the origin, but since we are running on the page itself, we trust window messages
// from our own app.
if (event.source !== window) return;
if (event.data.type && event.data.type === 'TOOLS_APP_INIT') {
// console.log('Tools App Extension: Received init from Web App');
window.postMessage({ type: 'TOOLS_APP_EXTENSION_READY', version: '1.0' }, '*');
}
// Heartbeat check
if (event.data.type === 'TOOLS_APP_PING') {
try {
// Only respond if the extension context is still valid
if (chrome.runtime && chrome.runtime.id) {
window.postMessage({ type: 'TOOLS_APP_PONG' }, '*');
}
} catch (e) {
// Extension context invalidated
// console.warn('Extension context invalidated during ping');
}
}
// Example: Receive request to sniff clipboard
if (event.data.type === 'TOOLS_APP_START_SNIFFING') {
// console.log('Tools App Extension: Start sniffing request');
// Relay to background script
try {
chrome.runtime.sendMessage({ action: 'startSniffing' });
} catch (e) {
console.warn('Tools App Extension: Connection lost, please reload the page', e);
}
}
if (event.data.type === 'TOOLS_APP_STOP_SNIFFING') {
// console.log('Tools App Extension: Stop sniffing request');
try {
chrome.runtime.sendMessage({ action: 'stopSniffing' });
} catch (e) {
// ignore
}
}
});
// Listen for messages from the Extension Background
try {
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'clipboardUpdate') {
// Send to Web App
window.postMessage({ type: 'TOOLS_APP_CLIPBOARD_UPDATE', content: request.content }, '*');
}
// Respond to background ping to confirm we are alive
if (request.action === 'ping') {
sendResponse('pong');
}
});
} catch (e) {
console.warn('Tools App Extension: Could not add listener', e);
}