I am making a highlighting browser plugin for firefox as a project.
I am trying to find a way to save where in a webpage a user highlights so I can reproduce it on reload.
I do my highlighting by getting what text the user has selected with their mouse, and surrounding that text with a span (and putting a background color for that span).
But what is an efficient way to save where the user highlighted.
I see two ways:
- traverse the dom from the highlight/span until reach an element with an ID. Then save this path.
But, these seem quite brute force, and I have a suspicion that there must be an easier way.
Is there a better way to do this?