home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 November / Chip_2003-11_cd1.bin / software / dave / dqsd.exe / searches / multi.xml < prev    next >
Text File  |  2002-10-17  |  6KB  |  178 lines

  1. <search function="multi">
  2.   <name>MultiSearch</name>
  3.   <description>
  4.     Perform multiple searches with a single command line expression.<br/>
  5.     <b><i>superMultiModeEnabled</i></b> can be set to true in localprefs.js to enable super multi mode which allows different sets of 
  6.          searches to be done (ie: multi search1 /firstParam; search2 search3 /secondParam)<br/>
  7.      <b><i>superMultiModeSepChar</i></b> can be set to a character in localprefs.js to determine the split character for the super multi mode
  8.          the default value is ;
  9.     <div class="helpboxDescLabels">Usage:</div>
  10.     <table class="helpboxDescTable">
  11.       <tr><td>multi <<i>search1</i>> [<<i>search2</i>> [...]] <<i>term</i>></td></tr>
  12.     </table>
  13.     <div class="helpboxDescLabels">Example:</div>
  14.     <table class="helpboxDescTable">
  15.       <tr><td>multi av gg wood planes</td><td> - </td><td>Display the search results for wood planes on altavista and google.</td></tr>
  16.       <tr><td>multi fm;sf hs /new</td><td> - </td><td>Display the new projects and files on freshmeat, sourceforge, and hotscripts provided superMultiModeEnabled is set to true in localprefs.js.</td></tr>
  17.     </table>
  18.   </description>
  19.   <category>Search the Web</category>
  20.   <contributor>Neel Doshi</contributor>
  21.   
  22.   <script><![CDATA[
  23.  
  24.     // This function is almost identical to the shortcut function in search.html
  25.     function multiIsCommand(t)
  26.     {
  27.       // look for matching commands first
  28.       var search = null;
  29.       var term = null;
  30.       var result = t.match(/^([a-zA-Z]+)\b/)
  31.       if (result)
  32.       {
  33.         if (aliases[result[1]])
  34.         {
  35.           search = aliases[result[1]];
  36.           term = t.slice(result[1].length);
  37.         }
  38.       }
  39.  
  40.       // then look for longest matching punctuation prefix
  41.       if (!search)
  42.       {
  43.         result = t.match(/^([\s~`!@#$%\^&\*()\-=\+{}\[\];:'<>,\.\/\?]+)/);
  44.         if (result)
  45.         {
  46.           for (var subs = result[1].length; subs>0; subs--)
  47.           {
  48.             search = aliases[result[1].slice(0, subs)];
  49.             if (search)
  50.             {
  51.               term = t.slice(subs);
  52.               break;
  53.             }
  54.           }
  55.         }
  56.       }
  57.  
  58.       // then look for longest matching punctuation suffix
  59.       if (!search)
  60.       {
  61.         result = t.match(/([\s~`!@#$%\^&\*()\-=\+{}\[\];:'<>,\.\/\?]+)$/);
  62.         if (result)
  63.         {
  64.           for (var subs = result[1].length; subs>0; subs--)
  65.           {
  66.             search = aliases[result[1].slice(-subs)];
  67.             if (search)
  68.             {
  69.               term = t.slice(0, -subs);
  70.               break;
  71.             }
  72.           }
  73.         }
  74.       }
  75.  
  76.       // no match, no dice
  77.       if (!search)
  78.         return false;
  79.  
  80.       // return the proper search term for the asking procedure
  81.       return search;
  82.     }
  83.  
  84.  // the multi function actually performs the multiple searches given
  85.  // the input parameters.  if the user's reuseBrowserWindowMode parameter
  86.  // is set to 1, multi will not work.  Also, if the user's launchmode
  87.  // is not set to zero, multi will pause between searches
  88.  // to allow multi to work with browsers other than IE.
  89.     function multi(q)
  90.     {
  91.       if ( reuseBrowserWindowMode == 1 )
  92.       {
  93.         alert("Multisearch requires the reuseBrowserWindowMode parameter to be set to zero or two.  Otherwise, all the searches will be spawned in the same window.");
  94.         return false;
  95.       }
  96.       if ( nullArgs("multi", q) )
  97.         return false;
  98.  
  99.       var multiCmdSets = new Array();
  100.       var mySuperMultiModeEnabled =  (typeof superMultiModeEnabled != "undefined" && superMultiModeEnabled != "");
  101.       var mySuperSepChar = (typeof superMultiModeSepChar != "undefined" && superMultiModeSepChar != "") ? superMultiModeSepChar : ";";
  102.       if (mySuperMultiModeEnabled == true)
  103.       {
  104.     var myCmds = q.split(mySuperSepChar);
  105.         for (var i=0; i < myCmds.length; i++)
  106.     {
  107.        var oneCmd = myCmds[i];
  108.        multiCmdSets[i] = oneCmd;   
  109.         }
  110.       } else {
  111.         multiCmdSets.push(q);
  112.       }
  113.  
  114.       for (var m=0; m < multiCmdSets.length; m++)
  115.       {
  116.         if (result = (multiCmdSets[m]).split( /[\s]+/ ) )
  117.         {
  118.  
  119.           var arrCmds = new Array(0);
  120.           var arrParams = new Array(0);
  121.  
  122.           // Loop through the arguments to filter out the commands.
  123.           // if an argument is not a command, then no future arguments
  124.           // can be commands either.  The following variable keeps track of this.
  125.           var fLoopBool = 1;
  126.           var strCommandName;
  127.  
  128.           for ( var i = 1; i <= result.length; i++ )
  129.           {
  130.             strCommandName = multiIsCommand(result[i - 1]);
  131.             if (strCommandName != false && fLoopBool == 1)
  132.             {
  133.               // Append the command list with this command
  134.               arrCmds.push(strCommandName);
  135.             }
  136.             else
  137.             {
  138.               // Set the fLoopBool to zero since no more commands should be found
  139.               fLoopBool = 0;
  140.  
  141.               // Append the parameter string with this word
  142.               arrParams.push(result[i - 1].replace("\x27","\\x27"));
  143.             }
  144.           }
  145.           // Loop through the command list and perform the search
  146.           if (arrCmds.length == 0)
  147.           {
  148.             alert("Multisearch needs at least one search type parameter.");
  149.             return false;
  150.           }
  151.           else
  152.           {
  153.             // Perform each of the searches
  154.             for ( var j = 1; j <= arrCmds.length; j++ )
  155.             {
  156.               // if the user's launchmode is anything but zero, pause between searches.
  157.               if (launchmode != 0)
  158.               {
  159.                 var Timeoutms = 1500;
  160.                 var SearchString = "performsearch('" + arrCmds[j - 1] + "','" + arrParams.join(" ") + "');";
  161.                 setTimeout( SearchString, Timeoutms * (j-1) );
  162.               }
  163.               else
  164.                 performsearch(arrCmds[j - 1], arrParams.join(" "));
  165.             }
  166.           }
  167.         }
  168.       }
  169.     }
  170.   ]]></script>
  171.  
  172.   <copyright>
  173.     Copyright (c) 2002 David Bau
  174.     Distributed under the terms of the
  175.     GNU Public License, Version 2 (http://www.gnu.org/copyleft/gpl.txt)
  176.   </copyright>
  177. </search>
  178.