Thursday, November 5, 2009

Custom Firefox Search Engine


There are many great search engine add-ons for Firefox (youtube, wikipedia, amazon, etc.), and it is relatively easy to add your own. I was recently interested in creating an engine that would search for lyrics while excluding sites that require Javascript in order to view them, and giving preference to sites that organize lyrics nicely, by album and artist. Firefox search engines are specified in XML using the OpenSearch Description documents. I created one (lyrics.xml) as follows ("good_lyrics_site" and "bad_lyrics_site" names used for anonymity:


<?xml version="1.0" encoding="UTF-8" ?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
 <ShortName>Lyrics Search</ShortName>
 <Description>Search lyrics, avoiding nasty javascript websites </Description>
 <InputEncoding>UTF-8</InputEncoding> 
 <Url type="text/html" template="http://www.google.com/search?as_q={searchTerms}+lyrics&as_oq=good_lyrics_site&as_eq=bad_lyrics_site" />
 <Image width="16" height="16">http://www.good_lyrics_site.com/favicon.ico</Image>
 <Developer>Philip Kilinskas</Developer> 
 <moz:SearchForm>http://www.google.com/</moz:SearchForm>
</OpenSearchDescription>

and an html file to load it:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<link rel="search" type="application/opensearchdescription+xml" title="Lyrics Search" href="lyrics.xml" /> 
</html>


For some reason, opening the html from File->Open in Firefox didn't allow me to add the search engine, but placing it on a web server did. Once you've loaded the html, pull down the search menu in the upper right corner of Firefox, and add the "Lyrics Search" search engine.






No comments:

Post a Comment