-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
28 lines (22 loc) · 1004 Bytes
/
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
async function updateButtonState() {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.tabs.sendMessage(tab.id, { type: "GET_PLAYBACK_STATE" }, (isPlaying) => {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message);
return;
}
document.getElementById("start").textContent = isPlaying ? "音声読み上げを停止" : "音声読み上げを開始";
});
}
document.getElementById("start").addEventListener("click", async () => {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.tabs.sendMessage(tab.id, { type: "TOGGLE_PLAYBACK" }, (isPlaying) => {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message);
return;
}
document.getElementById("start").textContent = isPlaying ? "音声読み上げを停止" : "音声読み上げを開始";
});
});
// Update the button state when the popup is opened
updateButtonState();