views:

105

answers:

2

Hi

I am trying to develop a firefox add-on which would allow me to highlight a text on the web page (any webpage client side) and then allwo me to write a note and save it. So when i visit the web page next time, if an annotation exists for a webpage it shows up a small Anchor/link next to the text, which on clciking should display the annotation that i typed in earlier.

Is this possible? Any ideas on how to go about it?

cheers

A: 

Definitely possible.

For example, you could use sqlite from an extension and, in that, store urls (or their hash) and any associated annotations. Then when visiting a page, check against the DB, and restore the annotations.

As to how you specifically want to accomplish this is up to you. There is no shortage of ways to accomplish this.

See Building an Extension and Storage at MDC.

Jonathan Fingland
Thanks for that and i can get to the point of getting the parent tag (the tag in which the text is stored e.g. 4th <P>)but how do i get the exact text position on the contentDocument?
fftoolbar
the easiest way would be to record an xpath expression that would re-identify the paragraph. go up the tree until you find an element with an id. then the xpath expression could be something like id('element_id')//p[.='matching text']
Jonathan Fingland
as an addendum, note that using p[4] wouldn't be a good choice as thing may get inserted and such. if the text itself has changed (and thus no match) then the annotation would be lost (risks being orphaned)
Jonathan Fingland
how do i trigger event when a text is selected? I tried it with mouseup and mousedown (which eventually gives me a click event) and i have already registered click event on the page to do something else. How do i detect if a text is selected on the contentDocument? This is a little too confusing for me now.
fftoolbar
see the link http://javascript.internet.com/page-details/highlighted-text.html from Wesley Johnson's answer
Jonathan Fingland
A: 

This sounds eerily similar to an idea I posted on Hacker News a few days ago. Interesting! Anyway, it sounds like you want to know what text is selected when you go to create your annotation. Googling "javascript text selection" lead me here, hope this helps!

http://javascript.internet.com/page-details/highlighted-text.html

Cheers! :)

WesleyJohnson
i want to know when the text is selected not what text is selected. Since i have already registered the clickevent the mouseup and mousedown does not seem to help me. so is there any other way i can detect text selection in firefox?
fftoolbar
Thanks for that, i need to ask you one more thing. How can i capture mousup in a frame. I have 2 frames and i want to capture mouseup in respective frames. window.capture seem to capture for the whole window but i want to capture for the individual frames. Is this even possible?cheers
fftoolbar