Category: Latest Jobs

    class HumanLikeScroller { constructor(options = {}) { // Configuration with defaults this.config = { scrollSpeed: 0.5, // pixels per second (base speed) speedVariation: 0.5, // +-50% speed variation pauseProbability: 0.2, // 20% chance to pause minPauseDuration: 500, // ms maxPauseDuration: 3000, // ms scrollVariation: 0.3, // +-30% random scroll distance variation directionChangeProbability: 0.1, // 10% chance to scroll up briefly maxScrollUp: 100, // max pixels to scroll up smoothScrolling: true, // smooth scroll or instant ...options }; this.isScrolling = false; this.scrollInterval = null; this.lastScrollTime = 0; this.currentDirection = 1; // 1 for down, -1 for up this.requestAnimationId = null; } start() { if (this.isScrolling) return; this.isScrolling = true; this.lastScrollTime = performance.now(); this._scrollStep(); } stop() { this.isScrolling = false; if (this.scrollInterval) { clearInterval(this.scrollInterval); this.scrollInterval = null; } if (this.requestAnimationId) { cancelAnimationFrame(this.requestAnimationId); this.requestAnimationId = null; } } _scrollStep() { if (!this.isScrolling) return; const now = performance.now(); const deltaTime = now - this.lastScrollTime; this.lastScrollTime = now; // Randomly decide if we should pause if (Math.random() < this.config.pauseProbability) { const pauseDuration = this._randomBetween( this.config.minPauseDuration, this.config.maxPauseDuration ); setTimeout(() => { this._scrollStep(); }, pauseDuration); return; } // Randomly decide if we should change direction briefly if (Math.random() < this.config.directionChangeProbability) { this.currentDirection = -1; // scroll up const scrollUpDistance = this._randomBetween( 20, this.config.maxScrollUp ); this._performScroll(scrollUpDistance); // After scrolling up, return to normal direction setTimeout(() => { this.currentDirection = 1; this._scrollStep(); }, this._randomBetween(200, 800)); return; } // Calculate scroll distance with random variations const baseScroll = (this.config.scrollSpeed * deltaTime) / 1000; const variedScroll = baseScroll * this._randomBetween( 1 - this.config.scrollVariation, 1 + this.config.scrollVariation ); const speedVariedScroll = variedScroll * this._randomBetween( 1 - this.config.speedVariation, 1 + this.config.speedVariation ); this._performScroll(speedVariedScroll * this.currentDirection); // Continue scrolling this.requestAnimationId = requestAnimationFrame(() => this._scrollStep()); } _performScroll(distance) { if (this.config.smoothScrolling) { window.scrollBy({ top: distance, behavior: 'smooth' }); } else { window.scrollBy(0, distance); } } _randomBetween(min, max) { return Math.random() * (max - min) + min; } } // Usage example: const scroller = new HumanLikeScroller({ scrollSpeed: 80, // faster base speed pauseProbability: 0.15, // slightly less pausing maxPauseDuration: 2000 // shorter maximum pauses }); // Start scrolling scroller.start(); // To stop scrolling later: // scroller.stop();