Solved

Javascript pause before next execution help

Posted on 2009-03-31
7
2,154 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

707 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

21 Experts available now in Live!

Get 1:1 Help Now