Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Create FireFox search plugin for arbitrary web site

by ccn (Vicar)
on Nov 09, 2008 at 14:39 UTC ( #722480=CUFP: print w/replies, xml ) Need Help??

Below is a script which makes a search plugin for arbitrary site.

It can create plugin not only for search engines but for any dynamic site which accepts CGI parameters.

To create search plugin:

  1. Make a search of bareword searchTerms, then copy a url appeared in address bar of a browser
  2. Run the script with that url as parameter
  3. Redirect script output to .xml file in searchplugins directory of your firefox profile

As an example let's create search plugin for LiveJournal

  1. Search 'searchTerms' using the search form
  2. Got url http://search.livejournal.ru/ljsearch?query=searchTerms&ie=utf-8
  3. run the script with url as parameter
    perl mksp.pl Livejournal 'http://search.livejournal.ru/ljsearch?query= +searchTerms&ie=utf-8' > ~/.mozilla/firefox/ze02d000.default/searchplu +gins/lj.xml
  4. restart FireFox and enjoy with blue pen of LiveJournal in search plugins
#!/usr/bin/perl -- use strict; use LWP::Simple; use MIME::Base64 qw(encode_base64); die "Usage: $0 Name 'SearchURLString'\n" if @ARGV < 2; my ($name, $url) = @ARGV; my ($site) = split '(?<![:/])/', $url; my $ico = get($site . '/favicon.ico'); unless ($ico) { $site =~ s{http://[^.]+\.}{http://}; $ico = get($site . '/favicon.ico'); } die "Can't get favicon for $site\n" unless defined $ico; my $base64 = encode_base64($ico); $url =~ s/searchTerms/{searchTerms}/gi; $url =~ s/&(?!amp;)/&amp;/g; print <<END_OF_SEARCHPLUGIN; <SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/" xmlns:os="http://a9.com/-/spec/opensearch/1.1/"> <os:ShortName>$name</os:ShortName> <os:Description>$name</os:Description> <os:InputEncoding>UTF-8</os:InputEncoding> <os:Image width="16" height="16"> data:image/x-icon;base64,$base64</os:Image> <SearchForm>$site</SearchForm> <os:Url type="text/html" method="GET" template="$url"> </os:Url> </SearchPlugin> END_OF_SEARCHPLUGIN __END__

Replies are listed 'Best First'.
Re: Create FireFox search plugin for arbitrary web site
by Lawliet (Curate) on Nov 09, 2008 at 16:54 UTC

    ccn++ # Why didn't I think of this -.-

    I'm so adjective, I verb nouns!

    chomp; # nom nom nom

Re: Create FireFox search plugin for arbitrary web site
by jgamble (Pilgrim) on Nov 29, 2008 at 21:45 UTC

    This is great.

    I wonder if there is some way to automate the output file, instead of having to type the path to the filename explicitly. I believe you can get away with a hardcoded path in Windows, but is it different for Linux?

      Yes, there is. The best way is to make a personal wrapper for the script:

      linux:

      #!/bin/sh perl mksp.pl $1 $2 > ~/.mozilla/firefox/YOURPROFILE/searchplugins/$1.x +ml

      windows:

      REM windows batch file perl mksp.pl %1 %2 > PATH\TO\YOUR\PROFILE\searchplugins\%1.xml

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://722480]
Approved by Corion
Front-paged by Arunbear
help
Chatterbox?
[prathap keerthipati]: how to update perl in unix
[hippo]: yum update perl
[hippo]: Other package managers are available
LanX wouldn't update system Perl!
[Discipulus]: prathap keerthipati might be it is better to install an alternative Perl instead and do not touch the system one
[LanX]: see perlbrew for alternative Perl installations
[marto]: unless you know exactly what you're doing an often saner option is to simply build another Perl rather than replace the system one

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (16)
As of 2017-03-23 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (285 votes). Check out past polls.