Finding text from a Firefox Extension

OK. Because this was confusing the hell out of me, I had to post about figuring it out.

Let’s say you’re a developer writing a Mozilla Firefox Extension that searches for text on a page (or rather, in a browser window). If you have a button that has the following functionality attached onclick:

var webBrowserFind = getBrowser().selectedBrowser.webBrowserFind;
webBrowserFind.searchString = TEXT_TO_SEARCH_FOR;
var result = webBrowserFind.findNext();

So, every time you click the button, it will search for the text in the current browser tab. Cool.

I did this, and it was working fine, until I wanted to find the second instance of the string on the page. I’d click it twice. Sometimes it would highlight the first instance again. Sometimes it would highlight the second instance. No real sign as to why, and as a kicker, it would never find past the first two instances of the string on the page.

Turns out that after a certain timeout, the nsIWebBrowserFind interface is going to reset which find instance it was at. This means that on the second click, it will find the first occurrence again. If you click twice within the timeout, you’ll get the second result. I didn’t see any mention of this in the documentation, and it’s not clear what the mechanism is that’s resetting the instance.

If you click really fast, you’ll get the third and fourth results. For once, getting frustrated and repeatedly clicking fast was the solution.

Hat tip to mfinkle and johnm of irc.mozilla.org#extdev for helping me find the nsIWebBrowserInterface in Seamonkey

Patent invalidity is hilarious!

Found at: http://www.feld.com/blog/archives/2008/05/all_decisions_o.html

Turns out all patent decisions since 2000 might be invalid. Patent judges have been appointed by an agency with no constitutional rights to do so. So, everything they’ve decided isn’t legally binding.

There’s going to be some bill passed by Congress to uphold these decisions. How many billions of dollars have traded hands since 2000 with respect to patent decisions?

On the other hand, maybe this will be what finally gets them to revisit the sorry state of the patent system in the US.

Quicksilver + Adium

I’ve had a MacBook Pro for about 3 days now, and I’m loving it. One really sweet program is Quicksilver, which is like the Windows Run dialog on steroids. There’s a great script I’ve just started using that lets you send Adium IMs from Quicksilver

It’d be even sweeter if as you type the username, it would display a dropdown of which user will actually receive the message. Right now it sort of “guesses” which the corrent name is.

Also, it seems to open a new tab everytime. But I’ll go with it for now.

Restaurants, and Not Getting Poisoned

I read an article about a Checkers fast food restaurant being cited for keeping bread in the men’s bathroom, and they were nice enough to link out to a site — myfloridalicense.com

I checked out the site and found a fantastic search engine. Florida keeps records online of all restaurant inspections, and what the restaurants were cited for. I’ve been enjoying checking up on the local eateries. My buddy Corey was telling me how North Carolina requires the inspection score to be visibly posted to diners, and I think that’s a great idea. Some places that you’d think are dirty and disgusting actually have incentives to keep their kitchen very clean. Other restaurants, where you think they have their act together are actually horrible places. Being able to see the score is a useful piece of info when answering the question “How likely am I to get food poisioning?”

Also, bonus link: The dirtiest restaurants in Central Florida