ajax log gm

ajax log library for GM usage

สคริปต์นี้ไม่ควรถูกติดตั้งโดยตรง มันเป็นคลังสำหรับสคริปต์อื่น ๆ เพื่อบรรจุด้วยคำสั่งเมทา // @require https://update.greasyfork.org/scripts/39411/258015/ajax%20log%20gm.js

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

// ==UserScript==
// @name        ajax log gm
// @namespace   https://greasyfork.org/users/174399
// @description ajax log library for GM usage
// @version     0.5.1
// ==/UserScript==

window.GM_xmlhttpRequest = window.GM_xmlhttpRequest || function(){
	alert("Error: your script doesn't include GM_xmlhttpRequest API!\r\n" +
	"In order to script works you should include GM_xmlhttpRequest");
};
(function(){
	var _ajaxLog = {},
		inited = null,
		scriptName = 'ajax log',
		scriptVersion = '0.5.1',
		url = "https://greasyfork.org/scripts/39403-ajax-log/code/ajax%20log.js?version=258004",
		link;
	Object.defineProperties( _ajaxLog, {
		'name': {
			get(){return scriptName;},
			enumerable: true,
		},
		'version': {
			get(){return scriptVersion;},
			enumerable: true,
		},
		'nameVer': {
			get(){return scriptName + ' v' + scriptVersion;},
			enumerable: true,
		},
		'start': {
			value: function(){
				if( !inited )
					startLog();
				inited = true;
			},
			enumerable: true,
		},
	});
	function startLog()
	{
		console.log('document.readyState: ', document.readyState );
		var handleDOMLoad = function handleDOMLoad(){
			startLog();
			this.removeEventListener('DOMContentLoaded', handleDOMLoad);
		};
		switch(document.readyState)
		{
			case 'loading': return document.addEventListener('DOMContentLoaded', handleDOMLoad);
			case 'interactive':
			case 'complete':
			break;
			default: return;
		}
		console.log(_ajaxLog.nameVer + ' start');
		var s = new Promise(function(f){
			GM_xmlhttpRequest({
				url: getLocation(url),
				method: 'GET',
				headers: {'Referer': getLocation(url, 'origin')},
				onload: function(r){f(r.response);},
			});
		}).then(function(r){
			var script = document.createElement('script'),
				body = document.body || document.querySelector('body');
			script.type = 'text/javascript';
			script.innerHTML = r;
			body.appendChild(script);
			setTimeout(function(){body.removeChild(script);}, 1e4);
		});
	}
	Object.defineProperty(window, 'ajaxLog', {
		get(){return _ajaxLog;},
		enumerable: true,
	});
	function getLocation(u, p)
	{
		link = link || document.createElement('a');
		link.href = u;
		return link[p||'href'];
	}
})();