Solved

Javascript pause before next execution help

Posted on 2009-03-31
7
2,156 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

815 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now