I'm about as new and noobie as it gets when it comes to this, but it's something that really irritates me. There's this website, and to login, you must complete a sort of captcha It looks like this
<input type="text" class="form-control" id="question" placeholder=" 45638+41119?">
It's ridiculously annoying having to open a calculator to complete this every time, because the numbers i have to work with are too big. I wanna know if there's a way to get the sum of these two numbers and auto-fill the text field, all packed to a script I can use with Tampermonkey
Try this code:
console.log(eval(document.querySelector("input[type='text'][class='form-control']").placeholder.slice(0, -1)))
<input type="text" class="form-control" id="question" placeholder="45638+41119?">
It simply gets the element and reads the placeholder, takes out the question mark, and evaluates the answer.
Note that while the use of eval
is typically discouraged, it's fine if you know what you're doing - which in this case is a simple arithmetic task.
You can also take it a step further and autofill it:
inputCaptcha = document.querySelector("input[type='text'][class='form-control']")
inputCaptcha.value = eval(inputCaptcha.placeholder.slice(0, -1))
<input type="text" class="form-control" id="question" placeholder="45638+41119?">