🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

📂 缓存分发状态(共享加速已生效)
🕒 页面同步时间:2025/12/26 03:36:05
🔄 下次更新时间:2025/12/26 04:36:05
手动刷新缓存

Interval Looper

非同步数组枚举回调

Ovu skriptu ne treba izravno instalirati. To je biblioteka za druge skripte koje se uključuju u meta direktivu // @require https://update.greasyfork.org/scripts/3588/10916/Interval%20Looper.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// Interval Looper by Jixun:
// https://gist.github.com/JixunMoe/c77bb3936a68997fce22

var IntervalLoop = function (arrData, looper, delay) {
	if (!(this instanceof IntervalLoop))
		return new IntervalLoop (arrData, looper, delay);
 
	/**
	 * Status
	 * @type Number
	 * 0: 循环未开始
	 * 1: 正在循环
	 * 2: 循环结束
	 */
	this.status = 0;
	this.next = this._next.bind (this);
	this.index = 0;
 
	this.setDelay (delay || 50);
	this.data = (arrData instanceof Array) ? arrData : [];
	this.setLooper (looper);
};
 
IntervalLoop.prototype = {
	_getDelay: function () {
		if (!this.delay)
			return 50;
 
		if (this.delay.apply)
			return this.delay();
 
		return this.delay;
	},
	_next: function () {
		// 状态改为 进行中
		this.status = 1;
		if (this.index < this.data.length) {
			setTimeout (this.looper.bind(this, this.data[this.index]), this.delay);
			this.index ++;
			if (this.onProgress && this.onProgress.apply) {
				try {
					this.onProgress (this.index, this.data.length);
				} catch (e) {
					console.error ('Error while callback to `onProgress`');
					console.error (e);
				}
			}
		} else {
			this.status = 2;
			if (this.onComplete && this.onComplete.apply) {
				try {
					this.onComplete (this.data.length);
				} catch (e) {
					console.error ('Error while callback to `onComplete`');
					console.error (e);
				}
			}
		}
	},
	cleanup: function () {
		if (this.status == 2) {
			// 已经用过的数据就清掉。
			this.data.splice(0, this.index);
			this.index = 0;
			this.status = 0;
		}
 
		return this;
	},
	add: function () {
		if (arguments.length > 0) {
			// 将所有参数作为数据推入 this.data
			for (var i = 0; i<arguments.length; i++)
				this.data.push (arguments[i]);
 
			// 整个组已经完结,清理后自动继续
			if (this.status == 2)
				this.cleanup().next();
		}
 
		// 连锁
		return this;
	},
	setDelay: function (newDelay) {
		if (newDelay) this.delay = parseInt (newDelay);
		return this;
	},
	setLooper: function (fooCallback) {
		if (fooCallback && fooCallback.apply)
			this.looper = fooCallback.bind(this, this.next);
 
		return this;
	},
	loop: function () {
		if (this.status == 0)
			// 尚未启动, 从头开始
			this.next ();
 
		return this;
	}
};