loadedNode

检测节点是否完全加载

Tính đến 10-04-2020. Xem phiên bản mới nhất.

Script này sẽ không được không được cài đặt trực tiếp. Nó là một thư viện cho các script khác để bao gồm các chỉ thị meta // @require https://update.greatest.deepsurf.us/scripts/399868/790606/loadedNode.js

// ==UserScript==
// @name         loadedNode
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  检测节点是否完全加载
// @author       YiJie
// @require      https://code.jquery.com/jquery-1.10.2.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
	jQuery.fn.loadedNode = function (selector, func, times, interval) {
		var _times = times || -1,
		_interval = interval || 100,
		_self = $(_selector),
		_selector = selector,
		_iIntervalID;
		if( _self.length ){
			func && func.call(_self);
		} else {
			_iIntervalID = setInterval(function() {
				if(!_times) {
					clearInterval(_iIntervalID);
				}
				_times <= 0 || _times--;
				_self = $(_selector);
				if( _self.length ) {
					func && func.call(_self);
					clearInterval(_iIntervalID);
				}
			}, _interval);
		}
		return this;
	}
})();