Skip to content

Commit

Permalink
Add a simple script to iterate through all elements and change the text.
Browse files Browse the repository at this point in the history
Prompt:

```
can you create a chrome extension that can read text from all elements in html
and modify them?
```
  • Loading branch information
vrajat committed May 1, 2023
1 parent f003add commit c40125e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions extension/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// content.js

// Get all the elements on the page
let elements = document.getElementsByTagName("*");

// Iterate through the elements and modify their text
for (let i = 0; i < elements.length; i++) {
let element = elements[i];

// Only modify elements with text content
if (element.innerText.length > 0) {
let text = element.innerText;

// Modify the text
text = text.toUpperCase();

// Write the modified text back to the element
element.innerText = text;
}
}

0 comments on commit c40125e

Please sign in to comment.