Help to create function that locates text in Javascript

Asked

Viewed 31 times

0

I’m trying to create a userscript for me to enter my password instead of clicking on the numeric keyboard that the site requires.

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

For example this is the keyboard that just 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 find 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 didn’t succeed, I’m a little lost in how I can get someone to give me a hint?

grateful.

1 answer

1


Tries:

while (i < t)
{
  l = senha.substr(i,1);
  if ($('img')[i].title.indexOf(l) !== -1)
  {
    $('img')[i].click();
  }
  i++;
}
  • Thanks the idea is right there, but the bank site has some lock that does not let the userscript work right, so in the end will not work so.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.