-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef64bd9
commit ad3fd9f
Showing
2 changed files
with
42 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const iconSrc = './info.svg'; | ||
const iconAlt = 'Icon description'; | ||
const targetWords = ['crazy', 'stupid', 'mad']; // Replace with your list of target words | ||
|
||
// Find all elements that contain any of the target words | ||
document.querySelectorAll('*').forEach(element => { | ||
targetWords.forEach(targetWord => { | ||
if (element.innerHTML.includes(targetWord)) { | ||
const className = `icon-container-${targetWord}`; | ||
// Split the innerHTML into parts to handle replacements | ||
const parts = element.innerHTML.split(targetWord); | ||
const replacedHTML = parts.join(`${targetWord}<span class="${className}"></span>`); | ||
|
||
// Update the element with the replaced content | ||
element.innerHTML = replacedHTML; | ||
|
||
// Add icon after each occurrence of the target word | ||
const iconContainers = element.querySelectorAll(`.${className}`); | ||
iconContainers.forEach(container => { | ||
const icon = document.createElement('img'); | ||
icon.src = iconSrc; | ||
icon.alt = iconAlt; | ||
container.appendChild(icon); | ||
|
||
}); | ||
} | ||
}); | ||
}); |