feat: url cleaner tool and extension update
This commit is contained in:
@@ -122,6 +122,17 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request.action === 'writeClipboard') {
|
||||||
|
if (isSniffing) {
|
||||||
|
chrome.runtime.sendMessage({
|
||||||
|
target: 'offscreen',
|
||||||
|
type: 'write-clipboard',
|
||||||
|
data: request.content
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (request.type === 'clipboard-data' && request.target === 'background') {
|
if (request.type === 'clipboard-data' && request.target === 'background') {
|
||||||
// Received data from offscreen document
|
// Received data from offscreen document
|
||||||
if (isSniffing && request.data && request.data !== lastClipboardContent) {
|
if (isSniffing && request.data && request.data !== lastClipboardContent) {
|
||||||
|
|||||||
@@ -46,6 +46,17 @@ window.addEventListener('message', (event) => {
|
|||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.data.type === 'TOOLS_APP_CLIPBOARD_WRITE') {
|
||||||
|
try {
|
||||||
|
chrome.runtime.sendMessage({
|
||||||
|
action: 'writeClipboard',
|
||||||
|
content: event.data.content
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Tools App Extension: Write clipboard failed', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen for messages from the Extension Background
|
// Listen for messages from the Extension Background
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "Tools App Extension",
|
"name": "Tools App Extension",
|
||||||
"version": "1.0",
|
"version": "1.1",
|
||||||
"description": "Browser extension for Tools App",
|
"description": "Browser extension for Tools App",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"clipboardRead",
|
"clipboardRead",
|
||||||
|
"clipboardWrite",
|
||||||
"offscreen",
|
"offscreen",
|
||||||
"storage",
|
"storage",
|
||||||
"alarms",
|
"alarms",
|
||||||
|
|||||||
@@ -42,12 +42,24 @@ setInterval(async () => {
|
|||||||
}
|
}
|
||||||
}, 50);
|
}, 50);
|
||||||
|
|
||||||
// Listen for messages from background if we need to change behavior
|
// Listen for messages from background
|
||||||
chrome.runtime.onMessage.addListener((message) => {
|
chrome.runtime.onMessage.addListener((message) => {
|
||||||
if (message.target === 'offscreen') {
|
if (message.target === 'offscreen') {
|
||||||
// Handle commands
|
// Handle commands
|
||||||
if (message.type === 'play-sound') {
|
if (message.type === 'play-sound') {
|
||||||
playNotificationSound();
|
playNotificationSound();
|
||||||
|
} else if (message.type === 'write-clipboard') {
|
||||||
|
try {
|
||||||
|
const text = message.data;
|
||||||
|
if (text) {
|
||||||
|
textEl.value = text;
|
||||||
|
textEl.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
lastText = text; // Update internal state to avoid re-triggering update
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to write clipboard:', e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user