Really new to JS, but want someone to show me how to write code that will do the following:
I have a list of URLs
Open new window & visit URL #1.
Wait on page for random interval between 20 and 40 seconds.
Close window.
Wait random interval between 10 - 15 minutes
Open new window & visit URL #2.
Wait on page for random interval between 20 and 40 seconds.
Close window.
Wait random interval between 10 - 15 minutes
Keep repeating until the array of URL’s is empty.
you only need a couple of functions for that
The problem is… I have no idea how to pull it all together…
did you read the linked pages?
I did, but I am a complete noob to JS. I understand basic concepts, but writing a whole piece of code confuses me…
Here is the function that does what you want:
function openNextURL(opts){
if (!opts.urls.length) { return; }
var url = opts.urls.shift();
var w = window.open(url);
setTimeout(function(){
w.close();
setTimeout(function(){
openNextURL(opts);
}, getRandomInt(opts.waitBetween[0] * 1000, opts.waitBetween[1] * 1000));
}, getRandomInt(opts.waitOpened[0] * 1000, opts.waitOpened[1] * 1000));
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
}
and this is how to use it:
// config
var options = {
//list of urls:
urls: ['http://google.com', 'http://yahoo.com', 'http://bing.com'],
//intervals in seconds:
waitOpened: [20, 40],
waitBetween: [600, 900],
}
// start
openNextURL(options);
1 Like
Wow! Thanks so much. You just made my day!
This works perfect in Chrome. But when I try to run it in TOR, it opens the new tab for a second, then closes it. Any ideas?
Any messages in the console?
system
Closed
10
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.