Creating a custom searchbastard engine

From Searchbastard

Jump to: navigation, search

Contents

Viewing examples

Error creating thumbnail:
Custom Wikipedia engine preference page as of version 1.4.2

A good place to start is examining existing engines. You might need to first install some. I was able to do this by right-clicking the searchbastard icon at the left edge of the searchbastard search bar, via the menu item Find new Searchbastard engines. Once I did this, many custom icons showed up on my search bar. Right-clicking on the Wikipedia icon and selecting properties gets you a screen as shown at the right.

The full path name to the the engine.xml source file is shown on the File line. The first time you click Open in editor you might be prompted to associate an editor which will become the future default. Choose an editor with XML support if you have one. Under Ubuntu, /usr/bin/gedit is not a bad starting point and will provide syntax colouring.


On a Ubuntu system, the path looks something like this:

/home/archimedes/.mozilla/firefox/dxesdf5s.default/searchplugins-searchbastard/wikipedia.xml

Google map example XML code

This one is fairly short and illustrates the basic structure. Note that I've trimmed the binary icon data.

<source lang="xml">
<?xml version="1.0" encoding="UTF-8"?>
<SearchBastardEngine
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="http://searchbastard.rosell.dk/searchbastard-engine-version-1.xsd">
    <ShortName>Google Maps</ShortName>
    <Version>1</Version>
    <Description></Description>
    <Language>eng</Language>
    <Tags>Maps</Tags>
    <SuggestedAliases>gm,map</SuggestedAliases>
    <Creator>Bjørn Rosell</Creator>
    <URL>http://searchbastard.rosell.dk/sb-engines/google-maps.xml</URL>
    <VersionURL>http://searchbastard.rosell.dk/sb-engines/versioninfo/google-maps.xml</VersionURL>
    <CreationDate>2008-06-30</CreationDate>
    <UpdateDate>2008-07-23</UpdateDate>
    <WebPage>http://rosell.dk/searchbastard-engines/google-maps</WebPage>
    <Image>data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAA...
AAI8AAACBAAAAAAAAAEAgAAAYQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==</Image>
    <SearchForm>http://maps.google.com/</SearchForm>
    <Search>
        <SearchOptions/>
        <VisualOptions>
            <VisualOption id="cleanup" name="Cleanup" type="select" default="userbar,header" labelInSidebar="">
                <Option label="No cleanup" value=""/>
                <Option label="5% - Remove userbar" value="userbar"/>
                <Option label="20% - Remove header" value="userbar,header"/>
            </VisualOption>
        </VisualOptions>
        <Macro>
            <Get template="http://maps.google.com/maps" encoding="UTF-8">
                <Param name="f" value="q"/>
                <Param name="source" value="s_q"/>
                <Param name="hl" value="en"/>
                <Param name="geocode" value=""/>
                <Param name="q" value="{searchTerms}"/>
                <Param name="btnG" value="Search+Maps"/>
                <Param name="sourceid" value="Mozilla-search"/>
            </Get>
            <If condition="option('cleanup').indexOf('userbar')!=-1">
                <Css>
                    div#guser{display:none}
                </Css>
            </If>
            <If condition="option('cleanup').indexOf('header')!=-1">
                <Css>
                    div#header{display:none}
                </Css>
            </If>
            <InjectScript condition="option('cleanup')!=''">
                resizeApp();
                
                // User can click on the left arrow image, which removes the left column
                // and resizes the map.
                // It would be cool to trigger this function here...
                // the javascript on google maps is unfortunately extremely complex.
                // one way to do it might be using the "dispatchEvent"
                // http://developer.mozilla.org/en/docs/DOM:element.dispatchEvent
                
                //var a = document.getElementById('paneltoggle2');
            </InjectScript>
        </Macro>
    </Search>
</SearchBastardEngine>
</source>

Making the icon data

On my system, I have the Firefox add-on Add to Search Bar. With this add-on, I can put the text cursor into any search box, then right click and select the menu item Add to Search Bar.... This creates an engine which shows up as an icon on my Searchbastard search bar. If I examine the XML source code for this, it contains the necessary binary icon data, which I can cut and paste into my custom search definition for the site.

I haven't tested this yet. My test file encodes the icon as data:image/png;base64 where the example encodes it as data:image/x-icon;base64. Maybe that has more to do with how the original icon was created than anything else.

See also

Personal tools