Help to create function that finds text in JavaScript

0

I'm trying to create a userscript for myself by typing in my password instead of clicking on the numeric keypad that the site requires.

The problem is that each button corresponds to 2 random numbers, so I need to have the function identify the number within the Title attribute of one of the buttons.

For example this is the keyboard that has now appeared:

<img src="/V1/ITAUF/IMG/teclado_tecla.gif" border="0" width="46" height="46" alt="" title="0 ou 2">
<img src="/V1/ITAUF/IMG/teclado_tecla.gif" border="0" width="46" height="46" alt="" title="1 ou 3">
<img src="/V1/ITAUF/IMG/teclado_tecla.gif" border="0" width="46" height="46" alt="" title="4 ou 6">
<img src="/V1/ITAUF/IMG/teclado_tecla.gif" border="0" width="46" height="46" alt="" title="8 ou 9">
<img src="/V1/ITAUF/IMG/teclado_tecla.gif" border="0" width="46" height="46" alt="" title="5 ou 7">

So assuming my password is 5821 first I would separate each character from the password I typed:

var senha  = prompt("Digite sua senha de Internet");
var t = senha.length;
var i = 0;
So now that I need to figure out which button corresponds to the character to click it, I thought of something with regular expressions:

while (i < t){
l = senha.substr(i,1);
$('img[title="[i]"]').click(); //Clica no botão que foi encontrado o caractere pela expressão regular
i++;
}

But I did not succeed, I'm kind of lost in how can I make someone give me a tip?

grateful.

    
asked by anonymous 06.12.2017 / 18:33

1 answer

1

Try:

while (i < t)
{
  l = senha.substr(i,1);
  if ($('img')[i].title.indexOf(l) !== -1)
  {
    $('img')[i].click();
  }
  i++;
}
    
06.12.2017 / 18:49