docsReady

A JavaScript to run script when docs is ready

Tính đến 06-06-2018. 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/29782/603417/docsReady.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.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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!)

// ==UserScript==
// @name			docsReady
// @namespace		[email protected]
// @description		A JavaScript to run script when docs is ready
// @author			xymopen
// @version			1.1.0
// @grant			none
// @license			BSD 2-Clause
// ==/UserScript==

// @updateURL		https://raw.githubusercontent.com/xymopen/JS_Misc/master/docsReady.js

"use strict";

function domReady( contextWindow ) {
	if ( undefined === contextWindow ) {
		contextWindow = window;
	}

	if ( "loading" == contextWindow.document.readyState ) {
		return new Promise( function ( resolve ) {
			contextWindow.document.addEventListener( "DOMContentLoaded", function () {
				resolve( contextWindow );
			} );
		} );
	} else if ( "interactive" == contextWindow.document.readyState ) {
		return Promise.resolve( contextWindow );
	} else if ( "complete" == contextWindow.document.readyState ) {
		return Promise.reject( "document is already loaded" );
	} else {
		return Promise.reject( "unknow document ready state" );
	}
}

function allReady( contextWindow ) {
	if ( undefined === contextWindow ) {
		contextWindow = window;
	}

	if ( "complete" == contextWindow.document.readyState ) {
		return Promise.resolve( contextWindow );
	} else {
		return new Promise( function ( resolve ) {
			contextWindow.addEventListener( "load", function () {
				resolve( contextWindow );
			} );
		} );
	}
}

function frameReady( contextFrame ) {
	if ( "complete" == contextFrame.contentDocument.readyState ) {
		return Promise.resolve( contextFrame );
	} else {
		return new Promise( function ( resolve ) {
			contextFrame.addEventListener( "load", function () {
				resolve( contextFrame );
			} );
		} );
	}
}