User:Thwblueboy/scripts/test.js

维基百科,自由的百科全书

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。

function testjs() {
	var xmlHttpRequest;
	var url = "http://en.wikipedia.org/w/api.php?action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment&format=xml"
	//XmlHttpRequest对象
	function createXmlHttpRequest(){
		if(window.ActiveXObject){ //如果是IE浏览器
			return new ActiveXObject("Microsoft.XMLHTTP");
		}else if(window.XMLHttpRequest){ //非IE浏览器
			return new XMLHttpRequest();
		}
	}
	//回调函数
	function zswFun(){
		if(xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 0){
			var b = xmlHttpRequest.responseText;
			//alert(b);
		}
	}
	this.init = function() {
		xmlHttpRequest = createXmlHttpRequest();
		xmlHttpRequest.onreadystatechange = zswFun;
		xmlHttpRequest.open("GET",url,false);
		xmlHttpRequest.send(null);
		
		//var text = xmlHttpRequest.responseText;
		//alert(text);
		
		try //Internet Explorer
		{
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";
			xmlDoc.loadXML(text);
		}
		catch(e)
		{
			try //Firefox, Mozilla, Opera, etc.
			{
				parser=new DOMParser();
				xmlDoc=parser.parseFromString(text,"text/xml");
			}
			catch(e) {//alert(e.message)}
		}
	};
}
var loadobj;
function Setup() {
	if (document.getElementById('firstHeading').textContent!="监视列表") return;
	loadobj= new testjs();
	loadobj.init();
}
hookEvent('load', Setup);