GoExisting - open path, focusing existing tab if found on either side

For a long time now I have used a series of buttons tied to a modified GO script that defaults to NEWTAB=findexisting but my version did not check both sides of a DUAL. This is a very nice addition @jon and @playful and @jon's ++index[e.item().right ? 1 : 0]; technique taught me something I had not seen in action before.

I like to use ctrl and shift qualifiers to open in dual or open in NEW. Here is a version that does that.

// GoExisting
// Original code written by @jon
// Tweaked by @playful and posted as version 1
// USEQUALKEYS support added by @aussieboykie
// 
// This is a script for Directory Opus.
// See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.
// 
// Also see https://resource.dopus.com/t/findexisting-anyside/20095/6
//
// Called by Directory Opus to initialize the script
function OnInit(initData)
{
   initData.name = "GoExisting";
   initData.desc = "";
   initData.copyright = "";
   initData.version = "1.1";
   initData.default_enable = false;

   var cmd = initData.AddCommand();
   cmd.name = "GoExisting";
   cmd.method = "OnGoExisting";
   cmd.desc = "Equivalent of Go NEWTAB=findexistingdual";
   cmd.label = "GoExisting";
   cmd.template = "PATH";
}

// Implement the GoExisting command
function OnGoExisting(scriptCmdData)
{
   var cmdPfx = 'Go "' + scriptCmdData.func.args.path + '"';
   var cmdSfx = (scriptCmdData.func.qualifiers == "none") ? "":" USEQUALKEYS";
   var cmdString = cmdPfx + cmdSfx;
   if (scriptCmdData.func.sourcetab.lister.dual == 0) {
      cmdString = cmdString + " NEWTAB=findexisting";
      scriptCmdData.func.command.RunCommand(cmdString);
   }
   else {
      if (!DoGoExisting(scriptCmdData, scriptCmdData.func.sourcetab.lister.tabs)) {
         cmdString = cmdString + " NEWTAB";
         scriptCmdData.func.command.RunCommand(cmdString);
      }
   }
}

function DoGoExisting(scriptCmdData, tabs)
{
   var FSUtil = DOpus.FSUtil();
   var e = new Enumerator(tabs);
   var index =  new Array(0, 0);
   e.moveFirst();
   while (!e.atEnd())
   {
      if (FSUtil.ComparePath(e.item().path, scriptCmdData.func.args.path))
      {
         if (scriptCmdData.func.sourcetab.right != e.item().right)
            scriptCmdData.func.command.AddLine('Set FOCUS=toggle');
         scriptCmdData.func.command.AddLine('Go TABSELECT ' + index[e.item().right ? 1 : 0]);
         scriptCmdData.func.command.Run();
         return true;
      }
      ++index[e.item().right ? 1 : 0];
      e.moveNext();
   }
   return false;
}

Regards, AB