Script to Make Changes into a Text Box

146 views
Skip to first unread message

peter quitzgard

unread,
May 1, 2024, 8:21:00 PM5/1/24
to AutoControl
Hello, I'm trying to create a script which do the next:

1- Tab loads ends.
3- Run Script.

The script should do the next:

1- Make focus into the text box (TextArea Comment:).
2- Delete "nts" out of the prefilled "Comments..." word.
3- Position the cursor at determined location. Let's say 
between the "o" and the "m".
4- Insert any given text snippet.

To start the chain, I tried with different values, including this one:

document.getElementById("//form[@id='HTMLFormElements']//table/tbody[1]/tr[3]/td[1]/textarea[1]").focus();

But I couldn't find the way to make focus into that text box.

Thanks.

peter quitzgard

unread,
May 1, 2024, 8:24:01 PM5/1/24
to AutoControl

AutoControl support

unread,
May 2, 2024, 2:05:52 AM5/2/24
to AutoControl
The attached file has a working example.
Textarea magic.acs

peter quitzgard

unread,
May 3, 2024, 3:11:57 AM5/3/24
to AutoControl
Your example script is correct, and I'm trying to use it as a basis for automating
a few similar actions in other website. The thing is, I would need to perform the task,
according to the specific values I'm getting from the target website. The tasks I'm trying
to do are basically these:

1- After a tab finishes loading.
2- Find and delete a predefined text portion, which will always
get prefilled, into a text box.
3- Add a predefined text, at a specific position into the box.

I think the fixed text portion to delete as well as the one to add, could be
conditioned by the appearance of some specific elements, but I'm not sure
whether if they should get located by its exact text value, or rather their
exact locations. The text to delete should be erased wherever position it
appears into the text box, and the text to add will always have to be in a
fixed position, next to a specific character. I could show you a video with
the details, or just pass you the login data (privately) of the website, so you
cab try it.

Thanks.

AutoControl support

unread,
May 3, 2024, 3:19:22 PM5/3/24
to AutoControl
No need to reveal private information. A video or a few screenshots are enough.

peter quitzgard

unread,
May 3, 2024, 4:34:56 PM5/3/24
to AutoControl
Alright, this is what will be shown, after a "preview" refresh:


That's a graphical table with information, which the website fills
with the next text after the first "preview":

[center]* Items in [b]bold[/b] are required or strongly preferred.[/center]

============= Additional Comments =============

It won't appear anymore in next previews, after I delete it manually.

The text box's "ID" is "message". That's a "phpBB" forum website.

AutoControl support

unread,
May 3, 2024, 5:52:42 PM5/3/24
to AutoControl
This should do it:
let TEXT_INSERT = "Hello, world!" ; let txtareaElem = document.querySelector('#message') txtareaElem.value = txtareaElem.value.replace(/img\}/, 'img}'+TEXT_INSERT).replace(/\[center.+=====/s, '')

peter quitzgard

unread,
May 3, 2024, 7:24:17 PM5/3/24
to AutoControl
OK, that works fine, but there is still two little details that maybe could be fixed:

1- There is a remaining empty line between the "}" and the "[". They should
be one below the other in their own lines.

2- The added text snippet will keep getting added after each page preview.

By the way, is it possible to use wildcards/regex with the "URL" triggers?

AutoControl support

unread,
May 3, 2024, 10:05:18 PM5/3/24
to AutoControl
This should fix both issues:
let TEXT_INSERT = "Hello, world!" ; let txtareaElem = document.querySelector('#message') txtareaElem.value = txtareaElem.value.replace(/img\}\{\//, 'img}'+TEXT_INSERT+'{/').replace(/\[center.+=====\n*/s, '')

 
By the way, is it possible to use wildcards/regex with the "URL" triggers?

URL conditions do not support regular expressions given that it's a highly technical mechanism that would confuse and frustrate most people. AutoControl prioritizes ease of use.
You can use the RUN SCRIPT action in combination with ACtl.STOP_FULL_SEQ in order to prevent an action from executing depending on any condition that you can express with Javascript.

peter quitzgard

unread,
May 4, 2024, 1:29:48 AM5/4/24
to AutoControl
Alright, that did the trick, thanks a lot.

One last thing, some days ago, while trying a few actions (for a unique website),
I had a weird problem, which took me sometime to realize its cause. Basically,
after importing such actions into another PCs browser, they weren't working
as expected, but very erratically. The thing is, those actions were already tested and
I knew they were working rightly; moreover, I had around a previous set of similar actions
which I tested on that same PC, and they were working fine, but they also were working
erratically after being loaded that time. I tried them in a one by one basis, and they were working,
but not when the actions' chain was triggered.  I wasn't sure why said actions suddenly wouldn't
work, so I tried with the "Emergency repair" option, which didn't help neither. So, I decided to try the
same actions' sets using another fresh browser, and they were working rightly there. So, under such
circumstances, I finally realized the only solution could be restarting the main browser I was using;
and indeed, that was the solution.

I couldn't reproduce the error, but was wondering if do you have some kind of "debug" version,
that I could use for testing purposes only, in case this issue repeats again in the future?

AutoControl support

unread,
May 4, 2024, 2:39:19 PM5/4/24
to AutoControl
There's no generic debug version that can be used to debug all possible problems. Each problem requires its own ad-hoc investigation.
If the actions that were failing included one or more scripts, then it's possible that the script interfered with itself after being injected in the page multiple times (scripts may have persistent side effects in the page). In such cases, you can reload the page in order to wipe out all scripts in that page.

peter quitzgard

unread,
May 4, 2024, 7:47:14 PM5/4/24
to AutoControl
I'm %99 sure the erratic behavior wasn't due to the scripts' action chain, since I was already
using them, and they were working rightly, even on different systems. It was something triggered
after I replaced those actions, with the updated ones. I remember the extension having problems
to identify exactly where to run, since I was testing the actions on a "incognito" window, and while
trying to test a specific action running it from the script itself (after choosing the exact tab), the
action was executed on the extension's tab itself. I also remember the target website reloading
itself constantly, after triggering the last actions of the chain; I had to stop the looping refresh with
the "escape" key. It seems there were specific actions which would cease to work, and stop the
whole chain, but when I try them individually, they were working rightly.

I will keep trying it, and tell you about in case anything else which can be reproduced somehow
shows up.

Thanks.
Reply all
Reply to author
Forward
0 new messages