After converted speech to text, text be on:$searchText and there is button by clicking button you search from google but i want it after cenverted a text it searchs automaticly without any buttons.
ex: after 3 seconds checks $searchText an if there is a text it search automaticly without button. help me i'm beginner :)
$button.addEventListener('click', () => {
if ($searchText.value !== '') {
var url = 'https://www.google.com/search?q=' + $searchText.value;
window.open(url, '_blank');
}
});
I have added an input box for simplifying. I believe you want something like this.
<!DOCTYPE html>
<html lang="en">
<body>
<!-- Your searchbox -->
<input type="text" id="searchText">
<script>
let timerID = null;
const $searchText = document.getElementById("searchText");
$searchText.addEventListener('input', () => {
clearTimeout(timerID)
if (!$searchText.value) {
return ;
}
timerID = setTimeout(() => {
const url = 'https://www.google.com/search?q=' + $searchText.value;
window.open(url, '_blank');
}, 3000 /* 3 seconds */)
});
</script>
</body>
</html>