Skip to content

Instantly share code, notes, and snippets.

@antoni
Last active April 10, 2020 19:09
Show Gist options
  • Save antoni/995fa4600605fb71d765dc071b3b016e to your computer and use it in GitHub Desktop.
Save antoni/995fa4600605fb71d765dc071b3b016e to your computer and use it in GitHub Desktop.
// Intended to be run on https://google.pl
function executeSearchTypingScript() {
const googleDomain = 'google.pl';
if (window.location.href.indexOf('google.pl') === -1) {
throw new Error(`This script should be run on ${googleDomain}`);
}
const searchInputField = document.querySelector('[aria-label=Szukaj]');
const searchText = 'Jiu-jitsu';
const LETTER_INTERVAL = 200;
// Question: why do we need to use 'let' here? Why wouldn't 'var' work?
for (let i = 0; i < searchText.length; i++) {
setTimeout(function() {
searchInputField.value = `${searchInputField.value}${searchText[i]}`;
}, i * LETTER_INTERVAL);
}
const form = document.getElementsByTagName('form')[0];
// Question: why do we need to use 'setTimeout()' here?
setTimeout(function() {
form.submit();
}, searchText.length * LETTER_INTERVAL);
}
executeSearchTypingScript();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment