Re: How to autofill ONLY if a specific phrase/word exists?

236 views
Skip to first unread message
Message has been deleted

Autofill Extension

unread,
Feb 26, 2022, 9:18:28 PM2/26/22
to Autofill Extension
Yes, it's possible, but you may need to use a JavaScript rule. Can you provide HTML code of some questions that change?

On Saturday, February 26, 2022 at 4:55:32 PM UTC-8 luha...@gmail.com wrote:
Hello. I'm really sorry if this is a dumb question (I tried RegEx by googling for some commands but it didn't work as I don't knowledge about it😢).

What I would like to do is: I have web page that shows me a different question every time it is reloaded.
Some questions are very common so I want to autofill the text box when a specific word or phrase exists.

Example:
Question: "are u going to man united's game today?"
I want the text box to be autofilled with "Manchester United F.C."

So, in the example above I need the extension to detect "man united".

Is such thing possible?

Message has been deleted

Autofill Extension

unread,
Feb 28, 2022, 8:09:25 PM2/28/22
to Autofill Extension
Try this rule...

Type = JavaScript
Value =

let question = document.querySelector('crowd-form tr');
if (question) {
  let text = question.textContent.trim();
  let input = question.querySelector('input');
  if (input) {
    // Does text contain "too good for man united"?
    if (text.includes('too good for man united')) input.value = 'Answer 1';
    // Does text contain "man united team good enough"?
    else if (text.includes('man united team good enough')) input.value = 'Answer 2';
  }
}

Let me know if it works for you :).

On Sunday, February 27, 2022 at 4:18:42 AM UTC-8 luha...@gmail.com wrote:
Is this HTML code good enough?
I got it by clicking on "View frame source".

There's also a "View page source" option but it doesn't show the questions or anything related to it

M S

unread,
Mar 1, 2022, 1:31:35 AM3/1/22
to Autofill Extension

It works! Thanks ;)
If you don't mind, could you please help me insert a different text to the second text field? The current code successfully inserts "Answer 1" to the first text field, but I would like it to also insert "Website1" to the second text field. I've created a new profile just for the second field but the code didn't seem to work there.

Autofill Extension

unread,
Mar 1, 2022, 1:54:26 AM3/1/22
to Autofill Extension
Since the JavaScript rule handles all the different question variations, you shouldn't need to create separate rules for each question. To change what to insert into the field, change "Answer 1/2/3" to whatever you want. You can use this code as a template for other questions.

let question = document.querySelector('crowd-form tr');
if (question) {
  let text = question.textContent.trim();
  let input = question.querySelector('input');
  if (input) {
    // Does text contain "AAA"?
    if (text.includes('AAA')) input.value = 'Answer 1';
    // Does text contain "BBB"?
    else if (text.includes('BBB')) input.value = 'Answer 2';
    // Does text contain "CCC"?
    else if (text.includes('CCC')) input.value = 'Answer 3';
  }
}


M S

unread,
Mar 1, 2022, 6:59:37 AM3/1/22
to Autofill Extension
I understand that I can use that Javascript code to match all the different questions, but I'd would like it to also insert a different phrase into the second text field.
This is a screenshot of how the script is working, it inserts "Answer 1" into the fist field, but I want it to insert a website (https://www.website-1.com/) into the second field.
club.jpg

Autofill Extension

unread,
Mar 1, 2022, 8:16:44 PM3/1/22
to Autofill Extension
Ah, try this code:

let question = document.querySelector('crowd-form tr');
if (question) {
  let text = question.textContent.trim();
  let club = question.querySelector('input');
  let site = document.querySelector('input[name="club_website"]');
  if (club && site) {
    if (text.includes('AAA')) {
      club.value = 'Club 1';
      site.value = 'Site 1';
    } else if (text.includes('BBB')) {
      club.value = 'Club 2';
      site.value = 'Site 2';
    } else if (text.includes('CCC')) {
      club.value = 'Club 3';
      site.value = 'Site 3';
    }
  }
}


M S

unread,
Mar 1, 2022, 8:43:47 PM3/1/22
to Autofill Extension
Yes! It works just like I wished! Thank you so much man😊. Really appreciante your patience on helping newbies like me😁

Autofill Extension

unread,
Mar 3, 2022, 3:13:41 PM3/3/22
to Autofill Extension
Cool, glad it worked out  👍.
Reply all
Reply to author
Forward
0 new messages