From 0cbcdf73aa5b782cf71c90953c5a3197ddf3c276 Mon Sep 17 00:00:00 2001 From: Aleksandr Filatov Date: Tue, 19 Dec 2023 11:06:17 -0800 Subject: [PATCH] added interval 5 mins between set of searches --- src/index.ts | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5d9e576..850d5f8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,7 +29,7 @@ const startSearch = () => { return randomWordsArray.join(' '); } - const func = () => { + const makeSearch = () => { const searchString = randomText(); iframe.src = `https://www.bing.com/search?q=${searchString}&PC=U316&FORM=CHROMN`; counter++; @@ -40,13 +40,37 @@ const startSearch = () => { } else { // Schedule the next search with a random delay const delay = getRandomDelay(); - setTimeout(func, delay); + setTimeout(makeSearch, delay); + } + } + + const makeSetOfSearches = () => { + // Make a set of 4 searches with intervals + let searchIndex = 0; + const makeSearchWithInterval = () => { + makeSearch(); + searchIndex++; + if (searchIndex < 4) { + // Schedule the next search with an interval + const intervalDelay = getRandomDelay(); + setTimeout(makeSearchWithInterval, intervalDelay); + } else { + // After the set of 4 searches, schedule the next set after a 5-minute delay + setTimeout(func, 5 * 60 * 1000); + } } + + // Start making the set of searches + makeSearchWithInterval(); + } + + const func = () => { + // Start the initial set of searches + makeSetOfSearches(); } - // Start the initial search - const initialDelay = getRandomDelay(); - setTimeout(func, initialDelay); + // Start the initial set of searches + func(); }; -startSearch() +startSearch();