1

I'm doing firefox addon that has it's sqlite database mydb.sqlite. It's a database of my selected links and I have a load event for gBrowser. Now I would like to write a code that will check the content.document.location on each load event and will notify me if the currently open link is in the database or if it is not in the database (e.g. with some icon on the status bar).

Do you know how to do it efficiently? So it won't slow down firefox much?

thank you

Wayne
  • 59,728
  • 15
  • 131
  • 126
xralf
  • 3,312
  • 45
  • 129
  • 200

1 Answers1

1
  1. Be sure you're listening for the DOMContentLoaded event, which fires on every page load

  2. You can get the loaded page's URL from within your DOMContentLoaded handler using e.target.defaultView.location.href (where e should be whatever you've named the first parameter in your callback).

  3. Now compare this URL to what's in the DB. Consider using asynchronous statement execution (Firefox 3.5 and newer only), so that you don't block the main thread unnecessarily.

  4. This excellent tutorial will show you how to update the status bar.

Wayne
  • 59,728
  • 15
  • 131
  • 126
  • Thank you for useful information and how would you do the comparation in step 3? Sequantialy compare link in every record with loaded href? What if I have 10000 links in some time? Is it still eficient or is there some trick for more efficiency? – xralf Mar 10 '11 at 20:46
  • @xralf - Just let the DB do that work for you. Query the table asking for any records that match the URL for the page you're currently on. If the query returns any results, then you've found a match. Make sure to put a `UNIQUE` constraint on the URL column to limit table size (and create an appropriate index). I think you should be fine. – Wayne Mar 11 '11 at 18:38