Web search from Opus using multiple search engines and browsers

PURPOSE
This elementary button JScript was suggested by the thread about launching internet searches from DOpus. Any number of search engines can be configured into the script, and any number of browsers can be configured. To search:

  • The user types the search text into an input box.
  • The user then selects any configured search engine, or all of them.
  • The first configured browser is the default - other browsers are selected using the down arrows, or Shift and Ctrl.

Some search engines are already configured in the downloaded script. They are only intended as examples:

  • DuckDuckGo Search
  • Google Search
  • Bing Search
  • Wikipedia
  • DOpus Forum
  • Stack Overflow
  • Oxford English Dictionary
  • Duden Online Deutsches Wörterbuch
  • Beolingus Deutsch-Englisch Wörterbuch
  • Google Images
  • Google Maps

INSTALLATION
Download the button script below, put DOpus into Customise mode, and drag the button script onto a toolbar.

CONFIGURATION
To edit the button, right-click on it while holding the Alt key. Accelerator keys and hotkeys may be added to the button. Then the search engines, and the browsers, need to be configured at the top of the actual script:

A. Each search engine command should be the engine's whole URL up to the point where the search string starts. I've been able to perform a search on an engine's website, then copy the resulting URL and chop off my search string.

B. Each browser command may be a simple alias, if the system allows it, or it may be the full path to the .exe file or the Start Menu .lnk file. If the path to the .exe or .lnk file is given, an inner set of double quotes is needed, followed by a space, inside a set of single quotes, as in:
'"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Mozilla Firefox.lnk" '
Note that each backslash \ must be changed to a double backslash \ (escape backslash). I could not test the Chrome and Opera aliases, and the command for the Edge browser is only a best guess because I have Windows 7.

USAGE AND LIMITATIONS

  • The search text is handled naively, except only that each unescaped double quote " is replaced within the JScript code by an escaped double quote " so that it will eventually appear again as " in the search field (the user won't notice anything). Some other characters are more problematic, and no other characters are handled individually - given the variations in URL syntax, it could very difficult to accommodating such characters, which work naively on some websites but not on others.

  • When 'All search engines' is selected, Firefox launches multiple tabs, but the others all launch multiple windows, which may be very slow. (These settings could be changed by editing the code - note how the code handles Firefox separately).

  • Sandboxie options have not been given, but a Sandboxie browser command may be added in the browser configuration, which could even have sandboxed and non-sandboxed versions of each browser.

  • Multiple copies of this button could be created, each offering a set of specialist search engines. For example, one button could offer language searches, another coding searches, and a third music searches.

V1.0, 17/03/16
Search Engines.dcf (11.2 KB)

SCRIPT CODE
The script code from the download above is reproduced below so you can see how it works without downloading it:

DOpus.Output ("- - - - - - - ->")

// SearchEngines
// (C) 2016 JulianON
// V1.0 17/30/16
// This is a script for Directory Opus.
// See https://resource.dopus.com/viewtopic.php?f=35&t=25994 for development information. 

// CONFIGURATION A: Enter any number of search engines, using the two-line pattern below:
// Numbering must be consecutive.
var aEngines = new Array // These are the display names for the search engines.  
var aEngineCommands = new Array // The search text will be appended without spaces to these URLs.
aEngines [0] = "Duc&k" // DuckDuckGo Search
aEngineCommands [0] = "https://duckduckgo.com?q=" 
aEngines [1] = "&Google" // Google Search
aEngineCommands [1] = "https://encrypted.google.com/search?as_q="
aEngines [2] = "&Bing" // Bing Search
aEngineCommands [2] = "https://www.bing.com/search?q="
aEngines [3] = "&Wiki" // Wikipedia
aEngineCommands [3] = "https://en.wikipedia.org/wiki/" 
aEngines [4] = "D&Opus" // DOpus Forum
aEngineCommands [4] = "https://resource.dopus.com/search.php?keywords="
aEngines [5] = "&Stack" // Stack Overflow
aEngineCommands [5] = "https://stackoverflow.com/search?q="
aEngines [6] = "Ox&ford" // Oxford English Dictionary (requires paid login)
aEngineCommands [6] = "http://www.oed.com/search?q="
aEngines [7] = "&Duden" // Duden Online Deutsches Wörterbuch  
aEngineCommands [7] = "http://www.duden.de/suchen/dudenonline/"
aEngines [8] = "Beo&lingus" // Beolingus Deutsch-Englisch Wörterbuch  
aEngineCommands [8] = "http://dict.tu-chemnitz.de/dings.cgi?lang=de&query="
aEngines [9] = "&Images" // Google Images
aEngineCommands [9] = "https://www.google.com/search?tbm=isch&q="
aEngines [10] = "&Maps" // Google Maps
aEngineCommands [10] = "https://www.google.com.au/maps/place/"

// CONFIGURATION B: Enter any number of browsers using the two-line pattern below.  
// Numbering must be consecutive.
// Browser [0] is the default.  
// Browsers [1], {2] and [3] are displayed using the arrows, or by Shift, Ctrl and Shift+Ctrl.
// Browsers [4], {5], . . . can only be displayed using the down arrows.
// WARNING: When using the full path, follow the example on the next line:
// '"C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Mozilla Firefox.lnk" '
var aBrowsers = new Array // These are the display names for the browsers.
var aBrowserCommands = new Array // These aliases may need to be full paths.
aBrowsers [0] = "Firefox"
aBrowserCommands [0] = "Firefox " // The space is important to separate the URL that follows.
aBrowsers [1] = "IE"
aBrowserCommands [1] = "IExplore " // The space is important to separate the URL that follows.
aBrowsers [2] = "Chrm" 
aBrowserCommands [2] = "Chrome " // The space is important to separate the URL that follows.
aBrowsers [3] = "Edge"
aBrowserCommands [3] = "start microsoft-edge:" // No space at the end here.  But is the command correct???
aBrowsers [4] = "Opera"
aBrowserCommands [4] = "Opera " // The space is important to separate the URL that follows.

// ********** END OF CONFIGURATION **********

function OnClick (clickData) { 

// STEP 1: The user dialogue.  Enter Search text, choose search engine and browser.
  var oDlg = DOpus.dlg
  oDlg.title = "Search Text and Search Engine"
  sMessage = 'Enter the search text, which may include double quotes " .\r\n\r\n'
  sMessage = sMessage + "The default browser is " + aBrowsers [0].replace ("&", "") 
  oDlg.message = sMessage + " --- select other browsers using the arrows." 
  var sButtons = "" // Setup for the buttons and down arrows.
  for (nn = 0; nn < aEngines.length; nn++) {
    sButtons = sButtons + aEngines [nn]
	for (ii = 1; ii < 4; ii++) // Shift, Ctrl and Shift+Ctrl reach the 2nd, 3rd and 4th browser.
	  if (ii < aBrowsers.length)
	    sButtons = sButtons + "+" + aBrowsers [ii] + "=" + aEngines [nn] + " " + aBrowsers [ii]
    for (ii = 4; ii < aBrowsers.length; ii++) // Any remaining browsers require the down arrow.
      sButtons = sButtons + "+" + aBrowsers [ii]
	sButtons = sButtons + "|"
  }  
  sButtons = sButtons + "&All"
  for (ii = 1; ii < 4; ii++) {
    if (ii < aBrowsers.length)
      sButtons = sButtons + "+" + aBrowsers [ii] + "=All " + aBrowsers [ii]
  }
  for (ii = 4; ii < aBrowsers.length; ii++)
    sButtons = sButtons + "+" + aBrowsers [ii]
  oDlg.buttons = sButtons + "|&Cancel"
  oDlg.max = 512 // The search text box
  var nChoice = oDlg.show
  
// STEP 2: Act on the choice.
  if (nChoice > 0) {
    var sSearchText = oDlg.input
    for (nn = 0; nn < sSearchText.length; nn++) { // Deal with " in the search text.
      if (sSearchText.charAt (nn) == '\"') {
        if (!(sSearchText.charAt (nn-1) == '\\'))
          sSearchText = sSearchText.substr (0, nn) + '\\' + sSearchText.substr (nn)
      }
    } 

    var oDivision = new doDivision (nChoice - 1, aBrowsers.length)
    var nEngine = oDivision.q // Identify search engine and browser.
    var nBrowser = oDivision.r

    if (nEngine > -1 && nEngine < aEngines.length) { // If one engine is chosen.
      DOpus.Output (aBrowserCommands [nBrowser] + '"' + aEngineCommands [nEngine] + sSearchText + '"')
      clickData.func.command.RunCommand (aBrowserCommands [nBrowser] + '"' + aEngineCommands [nEngine] + sSearchText + '"')
    }
	
    if (nEngine == aEngines.length) { // if all engines are chosen.
      if (aBrowsers [nBrowser].replace ("&", "") == "Firefox") { // Tabs for Firefox.
        var sCommand = "Firefox "
        for (nn = 0; nn < aEngines.length; nn++) 
          sCommand = sCommand + '"' + aEngineCommands [nn] + sSearchText + '" '
        DOpus.Output (sCommand)
        clickData.func.command.RunCommand (sCommand) 
      } else { // Separate windows for all other browsers.
        for (nn = 0; nn < aEngines.length; nn++) {
          DOpus.Output (aBrowserCommands [nBrowser] + '"' + aEngineCommands [nn] + sSearchText + '"')
          clickData.func.command.RunCommand (aBrowserCommands [nBrowser] + '"' + aEngineCommands [nn] + sSearchText + '"')
        }
      }
    }
  }
DOpus.Output ("<- - - - - - - -")
}

// **********************************************
function doDivision (nDividend, nDivisor) { // No "return" - requires "New"
  this.n = nDividend // This is the Dividend.
  this.d = nDivisor // This is the Divisor.
  this.r =  this.n % this.d
  if (this.r < 0) // The remainder should be positive.
    this.r = this.r + Math.abs (this.d) // This is the remainder.
  this.q = Math.round ((this.n - this.r) / this.d) // This is the quotient.
}
2 Likes