Made more adjustments to the spam protection.

This commit is contained in:
dwebmm 2025-01-21 01:56:08 -06:00
parent 6418e37d67
commit 4cd41100fd

View file

@ -182,14 +182,10 @@
<div id="warningModal" class="modal warning-modal"> <div id="warningModal" class="modal warning-modal">
<div class="modal-content"> <div class="modal-content">
<span class="close-button" style="display: none">&times;</span> <h2>⚠️ Rate Limited</h2>
<h2>⚠️ Slow Down!</h2> <p>To protect Wiby.me from excessive requests, fumbling is limited to 20 times per minute.</p>
<p>Clicking too quickly may get you flagged as spam by Wiby.me.</p> <p>Please wait <span id="cooldownSeconds">0</span> seconds before fumbling again.</p>
<p>Please wait a moment between fumbles.</p> <button id="warningCloseBtn" class="warning-close-btn">
<div id="cooldownTimer" class="cooldown-timer">
You can close this warning in: <span id="cooldownSeconds">5</span>s
</div>
<button id="warningCloseBtn" class="warning-close-btn" disabled>
I Understand I Understand
</button> </button>
</div> </div>
@ -218,57 +214,43 @@
} }
let lastFumbleTime = 0; let lastFumbleTime = 0;
const warningThreshold = 3; // Trigger warning after 3 rapid fumbles const minInterval = 2000; // Minimum 2 seconds between fumbles
const rapidPeriod = 5000; // 5 second window for counting rapid fumbles const maxPerMinute = 20; // Maximum 20 fumbles per minute
const resetPeriod = 3000; // Reset counter if no rapid fumbles in 3 seconds let recentFumbles = []; // Track fumble timestamps for rate limiting
let fumbleTimes = []; // Track timestamps of recent fumbles
let cooldownTimer = null;
const fumble = () => { const fumble = () => {
const currentTime = Date.now(); const currentTime = Date.now();
const timeSinceLastFumble = currentTime - lastFumbleTime;
// Add current fumble time and remove old ones (older than 5 seconds) // Prevent rapid clicks (2 second minimum interval)
fumbleTimes.push(currentTime); if (timeSinceLastFumble < minInterval) {
fumbleTimes = fumbleTimes.filter(time => currentTime - time < rapidPeriod);
// If we have 3 or more fumbles within 5 seconds, show warning
if (fumbleTimes.length >= warningThreshold) {
// Show warning modal
const warningModal = document.getElementById('warningModal');
const cooldownSeconds = document.getElementById('cooldownSeconds');
const closeBtn = document.getElementById('warningCloseBtn');
warningModal.classList.add('show');
closeBtn.disabled = true;
// Update countdown timer
let remainingTime = 5;
cooldownSeconds.textContent = remainingTime;
if (cooldownTimer) clearInterval(cooldownTimer);
cooldownTimer = setInterval(() => {
remainingTime--;
if (remainingTime <= 0) {
cooldownSeconds.textContent = '0';
closeBtn.disabled = false;
clearInterval(cooldownTimer);
fumbleTimes = []; // Reset fumble history
} else {
cooldownSeconds.textContent = remainingTime;
}
}, 1000);
return; return;
} }
// If there are 2 fumbles, check if they're more than 3 seconds apart // Clean up old fumbles (older than 1 minute)
if (fumbleTimes.length >= 2) { recentFumbles = recentFumbles.filter(time =>
const lastTwoInterval = fumbleTimes[fumbleTimes.length - 1] - fumbleTimes[fumbleTimes.length - 2]; currentTime - time < 60000
if (lastTwoInterval > resetPeriod) { );
fumbleTimes = [currentTime]; // Reset to just the current fumble
} // Check rate limit (20 per minute)
if (recentFumbles.length >= maxPerMinute) {
const warningModal = document.getElementById('warningModal');
const cooldownSeconds = document.getElementById('cooldownSeconds');
warningModal.classList.add('show');
// Calculate remaining cooldown time
const oldestFumble = recentFumbles[0];
const cooldownRemaining = Math.ceil((60000 - (currentTime - oldestFumble)) / 1000);
cooldownSeconds.textContent = cooldownRemaining;
return;
} }
// Record this fumble
lastFumbleTime = currentTime; lastFumbleTime = currentTime;
recentFumbles.push(currentTime);
// Perform the fumble
const frame = document.getElementById("contentFrame"); const frame = document.getElementById("contentFrame");
frame.src = "https://wiby.me/surprise/"; frame.src = "https://wiby.me/surprise/";