Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
greybax authored Jan 12, 2024
1 parent 8a5fe51 commit ae9792d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 69 deletions.
11 changes: 0 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@
<body>
<iframe id="msBingFrame" width="100%" height="100%"> </iframe>
<script type="module" src="src/index.ts"></script>
<!-- Input elements for parameters -->
<label for="minDelay">Minimum Delay (ms): </label>
<input type="number" id="minDelay" value="10000">

<label for="maxDelay">Maximum Delay (ms): </label>
<input type="number" id="maxDelay" value="25000">

<label for="searchLimit">Search Limit: </label>
<input type="number" id="searchLimit" value="35">

<button onclick="startSearch()">Start Search</button>

<a href="https://www.buymeacoffee.com/IB2jYiCDf"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=☕&slug=IB2jYiCDf&button_colour=5F7FFF&font_colour=ffffff&font_family=Bree&outline_colour=000000&coffee_colour=FFDD00" /></a>
</body>
Expand Down
72 changes: 14 additions & 58 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,32 @@
import randomWords from 'random-words';

const startSearch = () => {
const main = () => {
const iframe = document.getElementById('msBingFrame') as HTMLIFrameElement;
const minDelayInput = document.getElementById('minDelay') as HTMLInputElement;
const maxDelayInput = document.getElementById('maxDelay') as HTMLInputElement;
const searchLimitInput = document.getElementById('searchLimit') as HTMLInputElement;

var counter = 0;
let counter = 0;
let intervalId: number;

const getRandomDelay = () => {
// Generate a random delay between user-defined minimum and maximum
const minDelay = parseInt(minDelayInput.value, 10);
const maxDelay = parseInt(maxDelayInput.value, 10);
return Math.floor(Math.random() * (maxDelay - minDelay + 1)) + minDelay;
}

const randomText = () => {
// Generate a random number between 1 and 10
// random number between 1 and 10
const wordCount = Math.floor(Math.random() * 10) + 1;
const randomWordsArray = randomWords(wordCount);

// Join words until the length is at least 100 symbols
while (randomWordsArray.join(' ').length < 100) {
randomWordsArray.push(randomWords(1)[0]);
}

return randomWordsArray.join(' ');
return randomWords(wordCount).join(' ');
}

const makeSearch = () => {
const func = () => {
const searchString = randomText();
iframe.src = `https://www.bing.com/search?q=${searchString}&PC=U316&FORM=CHROMN`;
counter++;
console.log('counter', counter);

if (counter >= parseInt(searchLimitInput.value, 10)) {
// browser
// 150 / 5 = 30 // search in bing
// 20 / 5 = 4 // search via bing
// mobile
// 100 / 5 = 20
if (counter === 35) {
clearInterval(intervalId);
} else {
// Schedule the next search with a random delay
const delay = getRandomDelay();
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 set of searches
func();
};
intervalId = setInterval(func, 30000) as any;
}

startSearch();
main();

0 comments on commit ae9792d

Please sign in to comment.