Solved

Javascript pause before next execution help

Posted on 2009-03-31
7
2,157 Views
Last Modified: 2012-05-06
Hello everyone,

I created a script for a game and basically it goes through and goes to the add request page for myspace.  Then all the user has to do is click the button and finish a captcha after 5 adds.  What I did was went down a pre-made list of id's for this and had the script wait 30 seconds in-between each page.  However, it seems to be rather consuming and will completely halt firefox while until it finishes reading the script.  Then it'll execute.  Is there a way to make a better pause function that won't be so hard on browsers?
<script type="text/javascript">
function open_window(url) {
	mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=1000,height=1400');
}
function pause(millis) {
var date = new Date();
var curDate = null;
do { 
curDate = new Date(); 
}
while(curDate-date < millis);
} 
</script>
</head>
 
<BR><BR>
Pop-ups must be enabled.  This script will go through every Silver-Mob member.  Please go through and invite everyone into your friend list and mob.  Captcha's typically happen every 5 adds, so be aware.
<script> 
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=417501204');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=107831660');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=54575935');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=11412696');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=169412488');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=403745266');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=138121891');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=73199523');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=406204413');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=184499963');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=91247815');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=65981723');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=55955177');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=204988332');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=133698825');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=396135369');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=121214428');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=320969254');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=204971887');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=426039187');
pause(30000);
open_window('http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=134224164');
</script>

Open in new window

0
Comment
Question by:TurboBorland
  • 4
  • 3
7 Comments
 
LVL 2

Expert Comment

by:captaincagemen
ID: 24034225
setInterval !
0
 
LVL 2

Expert Comment

by:captaincagemen
ID: 24034234
Or if you want it only to happen once use this:
setTimeout('alert(\'5 seconds passed!\')', 5000)"

Open in new window

0
 
LVL 4

Author Comment

by:TurboBorland
ID: 24034257
I have tried getting setTimeout() to work, however I was not successful.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 2

Expert Comment

by:captaincagemen
ID: 24034325
Very strange, I just tested it myself to be sure (see code snippet), and its working perfect for me
<html>
<head>
</head>
<body>
<script type="text/javascript">
setTimeout('alert(\'5 seconds passed!\')', 5000);
</script>
</body>
</html>

Open in new window

0
 
LVL 4

Author Comment

by:TurboBorland
ID: 24034351
I mean I was unable to get my script to work with the function.  Probably on how I used it.  However, I need the pause to be performed after every open_window function is performed.
0
 
LVL 2

Accepted Solution

by:
captaincagemen earned 250 total points
ID: 24034451
I changed your script, its working now!
<html>
<head>
</head>
<body>
<script type="text/javascript">
 
var c = 0;
var urls = new Array();
urls[0] = 'http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=417501204';
urls[1] = 'http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=107831660';
urls[2] = 'http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=54575935';
urls[3] = 'http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=11412696';
 
function startWindowPopups() {
  
  if(urls[c] != null) {
     open_window(urls[c]);
     c++;
     setTimeout('startWindowPopups()', 30000);
  }
  
  
}
 
function open_window(url) {
        mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=1000,height=1400');
}
 
startWindowPopups();
</script>
</head>
 
<BR><BR>
Pop-ups must be enabled.  This script will go through every Silver-Mob member.  Please go through and invite everyone into your friend list and mob.  Captcha's typically happen every 5 adds, so be aware.
</script>
</body>
</html>

Open in new window

0
 
LVL 4

Author Closing Comment

by:TurboBorland
ID: 31565089
Exactly what I needed.  Works like a charm. ;)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question