Hacker News new | ask | show | jobs
by thinkingemote 603 days ago
Programmatically what can a developer do with this?

I see that there is a method and an object to see if its enabled or not. And there is a way to get the whole fragment which can be parsed.

Are there methods to see whether some text in the fragment was actually highlighted or not? Are there methods to programmatically select text?

Could there be a way to, for example, draw a rectangle around the highlighted section, to get the coordinates of the text, to read out the selected text, to store what words people select and link to etc

Maybe it's an external link about headline news and the news title got changed by the editor. Maybe the developer may want to change the selection to the edited title so the user isn't surprised. Maybe its a multi lingual blog post and the user links using another language... etc etc

1 comments

Since you have access to the URL fragment in JS, you should be able to do any of that manually even if there isn't a special API to use. The easiest thing to do would be to check for this specially-crafted fragment in the URL and store it.

I think though that this is a pretty niche feature though, so it's unlikely to be a big source of data. In my experience, the median sophistication web user has discovered that the browser's Back button exists and can Open in New Tab. Bookmarks, zoom, ctrl-F are all too confusing. A feature that requires right-clicking may as well be black magic to most people.