-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
57 lines (49 loc) · 1.58 KB
/
popup.js
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
function Init() {
var paused = false;
var Render = function() {
document.getElementById("pauseresume_img").src = chrome.extension.getURL(paused ? "img/play32.png" : "img/pause32.png");
};
document.getElementById("narrate").addEventListener("click", function(e) {
chrome.tabs.query({ active: true }, function(tabs) {
tabs.forEach(function(tab) {
chrome.tabs.executeScript(tab.id, {file: "content_script.narrator.js" }, function(results) {
if(results && results.every(function(o) { return o; })) {
chrome.tabs.sendMessage(tab.id, { command: "getSelectionUtterance" });
}
});
});
});
});
document.getElementById("testbutton").addEventListener("click", function(e) {
narrate(document.getElementById("testText").value);
Render();
});
document.getElementById("stop").addEventListener("click", function(e) {
chrome.tts.stop();
paused = false;
Render();
});
document.getElementById("pauseresume").addEventListener("click", function(e) {
chrome.tts.isSpeaking(function(isSpeaking) {
console.log("Chrome TTS: " + (isSpeaking ? "is speaking" : "is not speaking"));
if(isSpeaking && !paused) {
chrome.tts.pause();
paused = true;
console.log("Paused.");
} else {
chrome.tts.resume();
paused = false;
console.log("Resumed.");
}
Render();
});
});
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.utterance) {
narrate(request.utterance, function() { sendResponse("Narrate: OK"); });
}
Render();
});
Render();
}
document.addEventListener("DOMContentLoaded", Init);