-
-
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
fd6213d
commit c5b51ca
Showing
2 changed files
with
50 additions
and
1 deletion.
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,48 @@ | ||
const iconSrc = './info.svg'; | ||
const iconAlt = 'Icon description'; | ||
const targetWords = ['crazy', 'stupid', 'mad']; // Replace with your list of 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); | ||
|
||
console.log(icon) | ||
// Hovering feature: Popup with content | ||
icon.addEventListener('mouseover', () => { | ||
const popup = document.createElement('div'); | ||
popup.className = 'popup-content'; | ||
popup.textContent = "wow"; | ||
// Positioning of the popup content | ||
popup.style.position = 'absolute'; | ||
popup.style.left = `${icon.offsetLeft + icon.offsetWidth}px`; | ||
popup.style.top = `${icon.offsetTop}px`; | ||
// Append popup to the document body or relevant container | ||
document.body.appendChild(popup); | ||
// container.appendChild(popup); | ||
|
||
// Remove popup when mouseout | ||
icon.addEventListener('mouseout', () => { | ||
popup.remove(); | ||
}); | ||
}); | ||
|
||
}); | ||
} | ||
}); | ||
}); |