# stockpack/3.7.1/assets/js/utils/stockpack-timer.js

StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more, version 3.7.1. 66 lines.

- Page: https://pluginprobe.com/plugins/stockpack/3.7.1/code/assets/js/utils/stockpack-timer.js
- Raw: https://pluginprobe.com/plugins/stockpack/3.7.1/raw/assets/js/utils/stockpack-timer.js
- Modified: 2026-09-10T12:57:42+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/stockpack/3.7.1/code/assets/js/utils/stockpack-timer.js#L10-L20`.

```javascript
export default class StockpackTimer {
	/**
	 * @param {Object} $element
	 */
	constructor( $element ) {
		this.$ = {};
		this.$.element = $element;
		this.timerTimeout = null;
		this.seconds = 0;
		this.timer();
	}

	timer() {
		if ( ! this.$.element.length ) {
			return false;
		}
		if ( ! this.$.element.hasClass( 'parsed' ) ) {
			this.seconds = 0;
			const time = this.$.element.text().split( ':' );
			let increment = 1;
			time.reverse().forEach( ( element ) => {
				this.seconds += increment * element;
				increment = increment * 60;
			} );
			this.$.element.addClass( 'parsed' );
		}

		const days = Math.floor( this.seconds / 24 / 60 / 60 );
		const hoursLeft = Math.floor( ( this.seconds ) - ( days * 86400 ) );
		const hours = Math.floor( hoursLeft / 3600 );
		const minutesLeft = Math.floor( ( hoursLeft ) - ( hours * 3600 ) );
		const minutes = Math.floor( minutesLeft / 60 );
		const remainingSeconds = this.seconds % 60;

		function pad( n ) {
			return ( n < 10 ? '0' + n : n );
		}

		let text = pad( hours ) + ':' + pad( minutes ) + ':' + pad( remainingSeconds );
		if ( days ) {
			text = pad( days ) + ':' + text;
		}
		this.$.element.text( text );
		if ( this.seconds === 0 ) {
			clearTimeout( this.timerTimeout );
			this.$.element.parent().text( wp.media.view.l10n.stockpack.limit.reset );
			return false;
		} else {
			this.seconds--;
		}
		clearTimeout( this.timerTimeout );
		this.timerTimeout = setTimeout(
			() => {
				this.timer();
			}, 1000, this,
		);
	}

	destroy() {
		if ( this.$.el ) {
			this.$.el.remove();
		}
		clearTimeout( this.timerTimeout );
	}
}

```
