AJAX plugin for IML

ajax plugin used by Iron Man

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name           AJAX plugin for IML
// @description    ajax plugin used by Iron Man
// @namespace      https://greasyfork.org/users/136230
// @description:ru ajax плагин от Iron Man
// @include        *
// @author         Iron_man
// @date           2018.02.04
// @version        1.0.2
// @grant          none
// ==/UserScript==
(function(){
	IML.extend({
		ajax: function( request ){
			if( !request )
				return;
			var evt_types = ['onload', 'onreadystatechange', 'onerror', 'onprogress'],
				xhr, key;
			request.method = request.method || 'GET';
			if( request.method.toUpperCase() === 'GET' && request.data ){
				request.url += '?' + request.data;
				request.data = '';
			}
			request.async = request.async === false ? request.async : true;
			if( window.XMLHttpRequest )
				xhr = new XMLHttpRequest();
			else if( window.ActiveXObject ){
				xhr = new ActiveXObject('Msxml2.XMLHTTP');
			}
			if( !xhr ){
				console.error("[IML.ajax] can't create xhr");
				return;
			}
			xhr.open( request.method, request.url, request.async );
			for( key in request.headers )
				xhr.setRequestHeader( key, request.headers[key] );
			evt_types.forEach( function(type){
				if( request[type] )
					xhr[type] = function(event){request[type].call( xhr, xhr.responseText, event );};
			});
			xhr.send( request.data || null );
		},
	});
})();