-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
100 lines (89 loc) · 2.62 KB
/
Copy pathcontent.js
File metadata and controls
100 lines (89 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Escuchar mensajes del background
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'getSelection') {
const selection = window.getSelection().toString();
sendResponse({ text: selection.trim() });
return true;
}
// Manejar clic en el icono de la extensión
if (request.action === 'translate-click') {
const selection = window.getSelection().toString();
if (!selection.trim()) {
showNotification('❌ No hay texto seleccionado');
return true;
}
chrome.storage.sync.get({
sourceLang: 'en',
targetLang: 'es'
}, (settings) => {
chrome.runtime.sendMessage({
action: 'openTranslateUrl',
text: selection,
sourceLang: settings.sourceLang,
targetLang: settings.targetLang
});
});
showNotification('✅ Abriendo Google Translate...');
return true;
}
if (request.action === 'translate') {
const selection = window.getSelection().toString();
if (!selection.trim()) {
showNotification('❌ No hay texto seleccionado');
return true;
}
chrome.storage.sync.get({
sourceLang: 'en',
targetLang: 'es'
}, (settings) => {
chrome.runtime.sendMessage({
action: 'openTranslateUrl',
text: selection,
sourceLang: settings.sourceLang,
targetLang: settings.targetLang
});
});
showNotification('✅ Abriendo Google Translate...');
return true;
}
if (request.action === 'speak') {
const selection = window.getSelection().toString();
if (!selection.trim()) {
showNotification('❌ No hay texto seleccionado');
return true;
}
chrome.storage.sync.get({
ttsLang: 'en-US'
}, (settings) => {
chrome.runtime.sendMessage({
action: 'playAudio',
text: selection,
ttsLang: settings.ttsLang
});
});
showNotification('🔊 Reproduciendo audio...');
return true;
}
});
// Mostrar notificación
function showNotification(message) {
const existing = document.getElementById('simple-notify');
if (existing) existing.remove();
const notification = document.createElement('div');
notification.id = 'simple-notify';
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
background: #333;
color: white;
padding: 15px 25px;
border-radius: 8px;
z-index: 10000;
font-family: sans-serif;
box-shadow: 0 4px 12px rgba(0,0,0,0.3);
`;
notification.textContent = message;
document.body.appendChild(notification);
setTimeout(() => notification.remove(), 2500);
}