Last active
April 10, 2020 19:09
-
-
Save antoni/995fa4600605fb71d765dc071b3b016e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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