Search and Highlight Words on a Page
PreReqs

Prefer to watch?
Step 1: Configure the Trigger starter brick
1.1 Click the New Mod button in the top left corner of the Page Editor and choose Trigger

1.2 Configure the Trigger brick with a name and set it to run on any page.
Field name
Value
🤔 Why?
🏁 Checkpoint

Step 2: Get text from the page
2.1 Add the Extract from Page brick

2.2 Set the property to `text` and use the `body` selector


🏁 Checkpoint
Step 3: Add to a mod package and create a config option
3.1 Click the three dots on a mod listing and choose Add to mod

3.2 Choose Create new mod from the dropdown, and click Move.
3.3 Set an alias if you haven't already, adjust the description, and click Create.

3.4 Click the top-level Mod Package and choose Input Form in the middle panel

3.5 Create a field to capture a string of words and phrases
Field
Value
🤔 Why?
🏁 Checkpoint

Step 4: Set your current inputs and save the mod
4.1 Click the Current Inputs tab in the middle panel

4.2 Type some words or phrases in the Keywords field
4.3 Click the save icon in the Mod Listing Panel to save the mod

🏁 Checkpoint

Step 5: Create an array of the string from words in config
5.1 Add the Run JavaScript Function brick

5.2 Adjust the Function field with a function for transforming the data
5.3 Create the words argument and set the value to @options.words
5.4 Change the Output value to words instead of output
5.5 Run the mod to confirm your function works as expected

🏁 Checkpoint

Step 6: Search text on the page
6.1 Add the Search Text brick

6.2 Set the Text value to @data.text
6.3 Set the Query value to @words
6.4 Run the mod to confirm the output is expected

Step 7: Display different alerts if its found or not
7.1 Add the If/Else brick

7.2 Update the Step Name to "Alert if matches found"
7.2 Set the condition to {{ true if @matches.matches | length > 0 }}

7.3 Add the Window Alert brick in the if pipeline

7.4 Copy the Window Alert brick and paste it in the else pipeline

7.5 Adjust the alert message to say No matches were found
7.6 Run the mod to view the alerts

🏁 Checkpoint

Step 8: Use a for loop to highlight each word on a page
8.1 Add the For-Each Loop brick

8.2 Update the Step Name for clarity
8.3 Set the Elements variable to @words
8.4 Change the Elements Key to word

8.5 Add the highlight text brick inside the body pipeline
8.6 Run the mod and confirm your words are highlighted on the page

Step 9: Save the mod and share
9.1 Save the mod
9.2 Open the Extension Console

9.3 View your active mods and click the three dots on the Search for words on a page mod

9.4 Create or select a team, copy the link below, then Save and Close


🏁 Checkpoint
Last updated
Was this helpful?