Hi everyone,

Attached is a function called "Sequence."  It allows the user to
(ideally through aliases) set up a sequence of sites to come up one
after the other in the same browser window.  Users can have the sites
come up after a specified amount of time, or after clicking on a confirm
dialog box.  Admittedly, testing has been limited to my one XP computer,
so please feel free to make modifications if necessary.  Also, the
confirm dialog box is a bit of an ugly solution, so if anyone is
interested in making a more elegant (but equally functional) mechanism,
I would certainly lend a hand.

Would one of you administrators mind adding this to the source if the
group deems it worthy?  I apologize for no longer having any CVS tools
set up.  Let me know if you wish me to send this in as an attachment.

Thanks,

Neel


<search function="sequence">
  <name>Sequence</name>
  <description>
    Sequence will load a number of sites in one browser window in
sequence.  The arguments are all urls to web pages.<br/>
    <div class="helpboxDescLabels">Usage:</div>
        <table class="helpboxDescTable">
                <tr><td>Set</td><td> - </td><td>sequence
&lt;<i>search1</i>&gt;<br/> [&lt;<i>search2</i>&gt; [...]]<br/>
/frequency:&lt;<i>frequency</i>&gt;
/repeat:&lt;<i>number</i>&gt;</td></tr>
        <tr><td>Cancel</td><td> - </td><td>sequence cancel</td></tr>
        </table>
    <div class="helpboxDescLabels">Switches:</div>
        <table class="helpboxDescTable">
                <tr><td>/frequency:&lt;<i>seconds or
ask</i>&gt;</td><td> - </td><td>Number of seconds between switches.
Frequency of "0" will ask the user before switching.   (default =
0)</td></tr>
                <tr><td>/repeat:&lt;<i>number</i>&gt;</td><td> -
</td><td>Number of times to repeat the sequence.  (default = 1, 0 =
forever)</td></tr>
        </table>
    <div class="helpboxDescLabels">Example:</div>
    <table class="helpboxDescTable">
                <tr><td>sequence http://www.gymamerica.com
http://www.whitehouse.gov</td></tr>
        </table>
  </description>
  <category>Functions</category>
  <contributor>Neel Doshi</contributor>

  <script><![CDATA[
    // Array used to keep track of sequence commands that are pending
completion
    sequenceTracker = new Array();


    function sequenceURLLoad(url_array, freq, repeat, sequence_code,
sequence_target)
    {
        // The repeat parameter is really the parameter the user entered
multiplied by the number of
        // URLS in the array.  This is done by the calling function.

                // When the function calls itself the url_array is
passed as a string
                // otherwise it is passed as an array.
                if (typeof url_array == 'string')
                        url_array = url_array.split(',');

                // Move the URL in the url_array from the top to the
bottom.
                var strURL = url_array.shift();
                url_array.push(strURL);

                // Open the URL in a browser window.
                // Note:  I am using window.open because I do not know
of another
                // way to ensure opening the page in the same window
everytime.
                // For some reasons, certain sites seem to break this
bit of functionality
                // i.e. www.nytimes.com.
                window.open(strURL, sequence_target);


                // See if the function should be called again.
                if (--repeat == 0)
                {
                        if (typeof sequenceTimeout != 'undefined')
                        {
                                clearInterval(sequenceTimeout);
                                delete sequenceTracker[sequence_code];
                        }
                        return false;
                }
                else
                {
                        // if the frequency is 0, ask the user if he
wants to continue:
                        if (freq == 0)
                                if(confirm("Click OK when you want to
load " + url_array[0] + "\nClick Cancel to cancel this sequence") ==
false)
                                {
                                        if (typeof sequenceTimeout !=
'undefined')
                                        {
        
clearInterval(sequenceTimeout);

                                        }
                                        delete
sequenceTracker[sequence_code];
                                        return true;
                                }

                        // otherwise use the frequency.
                        var strTimeout = "sequenceURLLoad('" + url_array
+ "', '" + freq + "', '" + repeat + "', '" + sequence_code + "', '" +
sequence_target + "');";
                        sequenceTimeout = setTimeout(strTimeout, freq *
1000);
                        sequenceTracker[sequence_code] =
sequenceTimeout;
                }
                return true;
        }

        function sequence(q)
        {
                var sequence_base = 1;
                if (nullArgs("sequence", q))
                        return false;

                // First parse the arguments
                var args = parseArgs(q, "frequency, repeat");

                var freq = 0;
                var repeat = 1;
                // set defaults if necessary
                if (typeof args.switch_val["frequency"] != 'undefined')
                {

                        freq = args.switch_val["frequency"];
                }
                if (typeof args.switch_val["repeat"] != 'undefined')
                {
                        repeat = args.switch_val["repeat"];
                }

                // Create an array with the URLS in them.
                // Make sure to add the http:// if necessary.

                var url_array = args.q.split(' ');


                // Check to see if the user wants to cancel a sequence.
                if (url_array[0] == 'cancel')
                {
                        // The member wants to cancel a particular
sequence
                        var sequence_code;
                        if (typeof url_array[1] == 'undefined')
                        {
                                url_array[1] = sequence_base;
                                sequence_code = "";
                        }
                        else
                                sequence_code = url_array[1] + " ";

                        if (typeof sequenceTracker[url_array[1]] !=
'undefined')
                        {
        
clearInterval(sequenceTracker[url_array[1]]);
                                delete sequenceTracker[url_array[1]];
                                document.deff.q.value = "Sequence " +
sequence_code + "canceled!";
        
setTimeout("document.deff.q.value='';",1000);
                                return true;
                        }
                        else
                        {
                                alert("Sequence code " + sequence_code +
" not found!");
                                return false;
                        }
                }

                for ( var j = 0; j < url_array.length; j++ )
                {
                        url_array[j] = isURL(url_array[j]);
                        if (url_array[j] == false)
                        {
                                alert("Only properly formatted URLs are
allowed.  Please try again.");
                                return false;
                        }
                }

          // Generate a sequence code and target name
          // The purpose of the sequencecode is to allow the user to
cancel a
          // sequence once it has begun.  The sequenceTracker array will
keep track of
          // all of the active sequences and associate a sequence code
to a setTimeout handle
          // so the user doesn't have to keep track of the changing
setTimeout handles.
      for (var sequence_code = sequence_base; typeof
sequenceTracker[sequence_code] != 'undefined'; ++sequence_code);
          var sequence_target = "target_" + sequence_code;

      // Start getting the URL
      repeat = repeat*url_array.length;
      sequenceURLLoad(url_array, freq, repeat, sequence_code,
sequence_target);

      // Display the cancel code in the search field
      if (sequence_code == sequence_base)
        sequence_code = "";
      else
        sequence_code = " " + sequence_code;

      document.deff.q.value = "To cancel: 'sequence cancel" +
sequence_code + "'";
      setTimeout("document.deff.q.value='';",2000);

      return true;
    }
  ]]></script>

  <copyright>
        Copyright (c) 2002 David Bau
        Distributed under the terms of the
        GNU Public License, Version 2
(http://www.gnu.org/copyleft/gpl.txt)
  </copyright>
</search>


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
DQSD-Devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dqsd-devel

Reply via email to