用户:Darkstar88/backup/xmlhttpimportscript.js

来自口袋百科
跳转至: 导航搜索

注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox/Safari:按住“Shift”的同时单击“刷新”,或按“Ctrl-F5”或“Ctrl-R”(Mac为“⌘-R”)
  • Google Chrome:按“Ctrl-Shift-R”(Mac为“⌘-Shift-R”)
  • Internet Explorer:按住“Ctrl”的同时单击“刷新”,或按“Ctrl-F5”
  • Opera:在“工具→首选项”中清除缓存
/*  
 * ImportScriptHttp.模块
 * 版本: r1
 */
(function (){
if (window.ImportScriptEx != undefined) return;
ImportScriptEx = new Object();
window.ImportScriptEx = ImportScriptEx;
ImportScriptEx.loadedScripts = {};
ImportScriptEx.HttpURI = function(url,callback)
{
	if (ImportScriptEx.loadedScripts[url]) {
		return (null);
	}
	ImportScriptEx.loadedScripts[url] = true;
	function MakeHttpRequest()
	{
			var A;
			try {
					A = new XMLHttpRequest();
			} catch(e) {
					try {
							A = new ActiveXObject("Msxml2.XMLHTTP");
					} catch(e) {
							try {
									A = new ActiveXObject("Microsoft.XMLHTTP");
							} catch(oc) {
									A = null;
							}
					}
			}
			if (!A)
			alert("Could not create connection object.");
			return A;
	}
	var x = MakeHttpRequest();
	x.onreadystatechange = function()
	{
			if (this.readyState == 4)
			{
					if (this.status == 200 || this.status == 304)
					{
							if ((this.responseText != null))
							{
									var s = document.createElement("script");
									s.language = "javascript";
									s.type = "text/javascript";
									s.defer = false;
									s.text = this.responseText;
									document.getElementsByTagName('head').item(0).appendChild(s);
									if (callback)
										callback();
							}
					}
					else
					{
							alert('XML request error: ' + this.statusText + ' (' + this.status + ')');
							return (false);
					}
			}
	};
	x.open('GET', url, false);
	x.send(null);
	return (x);
};
window.ImportScriptExHttpURI = ImportScriptEx.HttpURI;
function ImportScriptExMakePageURI(page)
{
	var uri = wgScript + '?title=' + encodeURIComponent(page.replace(/ /g,'_')).replace('%2F','/').replace('%3A',':') + '&action=raw&ctype=text/javascript';
	return (uri)
}
ImportScriptEx.HttpPage = function(page,callback)
{
	return (ImportScriptExHttpURI(ImportScriptExMakePageURI(page,callback)));
};
window.ImportScriptExHttpPage = ImportScriptEx.HttpPage;
ImportScriptEx.URI = function(url,callback)
{
	if (loadedScripts[url])
		return null;
	loadedScripts[url] = true;
	var s = document.createElement('script');
	s.setAttribute('src',url);
	s.setAttribute('type','text/javascript');
	document.getElementsByTagName('head')[0].appendChild(s);
	if (callback){
		if (navigator.userAgent.indexOf("MSIE") != -1)
			s.onreadystatechange = callback;
		else
			s.onload = callback;
	}
	return s;
};
window.ImportScriptExURI = ImportScriptEx.URI;
ImportScriptEx.Page = function(page,callback)
{
	return (ImportScriptExURI(ImportScriptExMakePageURI(page),callback));
};
window.ImportScriptExPage = ImportScriptEx.Page;
})();
/*  ImportScriptHttp.模块,结束  */