|
function () {
|
|
|
|
function onAttributeChange(target, attribute, callback) {
|
|
const observerCallback = (mutationsList) => {
|
|
for (let mutation of mutationsList) {
|
|
if (mutation.type === 'attributes' && mutation.attributeName === attribute) {
|
|
callback(mutation.target);
|
|
}
|
|
}
|
|
};
|
|
|
|
const observer = new MutationObserver(observerCallback);
|
|
const config = { attributes: true };
|
|
observer.observe(target, config);
|
|
console.log("Start observing.");
|
|
}
|
|
|
|
function waitForElementToAppear(selector, callback) {
|
|
const targetNode = document.body;
|
|
const config = { childList: true, subtree: true };
|
|
|
|
const observer = new MutationObserver((mutationsList, observer) => {
|
|
const element = document.querySelector(selector);
|
|
if (element) {
|
|
observer.disconnect();
|
|
setTimeout(() => callback(element), 500);
|
|
}
|
|
});
|
|
|
|
observer.observe(targetNode, config);
|
|
}
|
|
|
|
const speech = document.querySelector("#speech");
|
|
if (speech) {
|
|
if (speech.textContent.trim() === "Record") {
|
|
speech.textContent = "Send";
|
|
const record = document.querySelector(".record-button");
|
|
record.click()
|
|
} else {
|
|
const stop = document.querySelector(".stop-button");
|
|
stop.click();
|
|
speech.textContent = "Processing";
|
|
speech.disabled= true
|
|
waitForElementToAppear(".record-button", (button) => {
|
|
speech.disabled= false
|
|
speech.textContent = "Record";
|
|
});
|
|
|
|
}
|
|
}
|
|
} |