⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ajax.js

📁 分析APACHE访问日志。并按IP或者访问的页面进行统计。
💻 JS
字号:
/*
  配置基本信息,DEBUG:true(出错时调试);false(出错时不调试);__TIMEOUT:执行时间;TIMEOUT:超时;__TIME:定时刷新
*/
var DEBUG=false;
var __TIMEOUT="10000";
var TIMEOUT="3000";
var __TIME="8000";

/******************************检测浏览器版本******************************/
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var isFirefox = (navigator.userAgent.indexOf("Firefox") != -1) ? true : false;
var IEVer = getIEVer();
//获取IE版本号
function getIEVer(){
	var iVerNo = 0;
	var sVer = navigator.userAgent;
	if(sVer.indexOf("MSIE")>-1){
		var sVerNo = sVer.split(";")[1];
		sVerNo = sVerNo.replace("MSIE","");
		iVerNo = parseFloat(sVerNo);
	}
	return iVerNo;
}
/*
为array增加一个查找、删除及插入的属性
*/
Array.prototype.inArray = function (value){
var i;
for (i=0; i < this.length; i++) {
if (this[i] === value) {
return true;
}
}
return false;
}; 
Array.prototype.insertAt = function( index, value ) {
var part1 = this.slice( 0, index );
var part2 = this.slice( index );
part1.push( value );
return( part1.concat( part2 ) );
};
Array.prototype.removeAt = function( index )
{
var part1 = this.slice( 0, index );
var part2 = this.slice( index );
part1.pop();
return( part1.concat( part2 ) );
}
/*
  获得客户端浏览器大小
*/
var getWindowInfo=function()
{
var scrollX=0,scrollY=0,width=0,height=0,contentWidth=0,contentHeight=0;
if(typeof(window.pageXOffset)=='number')
{
scrollX=window.pageXOffset;
scrollY=window.pageYOffset;
}
else if(document.body&&(document.body.scrollLeft||document.body.scrollTop))
{
scrollX=document.body.scrollLeft;
scrollY=document.body.scrollTop;
}
else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop))
{scrollX=document.documentElement.scrollLeft;
scrollY=document.documentElement.scrollTop;
}
if(typeof(window.innerWidth)=='number')
{width=window.innerWidth;
height=window.innerHeight;
}
else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight))
{
width=document.documentElement.clientWidth;
height=document.documentElement.clientHeight;
}
else if(document.body&&(document.body.clientWidth||document.body.clientHeight))
{width=document.body.clientWidth;
height=document.body.clientHeight;
}
if(document.documentElement&&(document.documentElement.scrollHeight||document.documentElement.offsetHeight)){
if(document.documentElement.scrollHeight>document.documentElement.offsetHeight){
contentWidth=document.documentElement.scrollWidth;
contentHeight=document.documentElement.scrollHeight;
}
else
{contentWidth=document.documentElement.offsetWidth;
contentHeight=document.documentElement.offsetHeight;
}}
else if(document.body&&(document.body.scrollHeight||document.body.offsetHeight))
{if(document.body.scrollHeight>document.body.offsetHeight)
{contentWidth=document.body.scrollWidth;
contentHeight=document.body.scrollHeight;
}else{
contentWidth=document.body.offsetWidth;
contentHeight=document.body.offsetHeight;
}
}else
{contentWidth=width;
 contentHeight=height;
}
if(height>contentHeight)
height=contentHeight;
if(width>contentWidth)
width=contentWidth;
var rect=new Object();
rect.ScrollX=scrollX;
rect.ScrollY=scrollY;
rect.Width=width;
rect.Height=height;
rect.ContentWidth=contentWidth;
rect.ContentHeight=contentHeight;
return rect;
}
/*
var sDT = new Date("2007/1/20 10:10:10");
var eDT = new Date("2007/1/21 10:10:10");
document.writeln("秒差 : "+sDT.dateDiff("s",eDT)+"<br>");
document.writeln("分差 : "+sDT.dateDiff("n",eDT)+"<br>");
document.writeln("时差 : "+sDT.dateDiff("h",eDT)+"<br>");
document.writeln("日差 : "+sDT.dateDiff("d",eDT)+"<br>");
document.writeln("周差 : "+sDT.dateDiff("w",eDT)+"<br>");
document.writeln("月差 : "+sDT.dateDiff("m",eDT)+"<br>");
document.writeln("年差 : "+sDT.dateDiff("y",eDT)+"<br>");
*/
Date.prototype.dateDiff = function(interval,objDate){
    //若参数不足或 objDate 不是日期物件则回传 undefined
    if(arguments.length<2||objDate.constructor!=Date) return undefined;
    switch (interval) {
      //计算秒差
      case "s":return parseInt((objDate-this)/1000);
      //计算分差
      case "n":return parseInt((objDate-this)/60000);
      //计算時差
      case "h":return parseInt((objDate-this)/3600000);
      //计算日差
      case "d":return parseInt((objDate-this)/86400000);
      //计算週差
      case "w":return parseInt((objDate-this)/(86400000*7));
      //计算月差
      case "m":return (objDate.getMonth()+1)+((objDate.getFullYear()-this.getFullYear())*12)-(this.getMonth()+1);
      //計算年差
      case "y":return objDate.getFullYear()-this.getFullYear();
      //输入有误
      default:return undefined;
    }
  }
  /*
  获得节点信息
*/
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
		element = document.getElementById(element);
		if (arguments.length == 1)
		return element;
		elements.push(element);
	}
	return elements;
}
/*
AJAXRequest Class
*/
function AJAXRequest() {
	var xmlObj = false;
	var CBfunc,ObjSelf;
	ObjSelf=this;
	try { xmlObj=new XMLHttpRequest; }
	catch(e) {
		try { xmlObj=new ActiveXObject("MSXML2.XMLHTTP"); }
		catch(e2) {
			try { xmlObj=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(e3) { xmlObj=false; }
		}
	}
	if (!xmlObj) return false;
	this.method="POST";
	this.url;
	this.async=true;
	this.content="";
	this.callback=function(cbobj) {return;};
	this.error=function(){return;};
	this.send=function() {
		if(!this.method||!this.url||!this.async) return false;
		xmlObj.open (this.method, this.url, this.async);
		xmlObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=gb2312');
		xmlObj.setRequestHeader("If-Modified-Since","0");
		if(this.method=="POST") xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlObj.onreadystatechange=function() {
			if(xmlObj.readyState==4) {
				if(xmlObj.status==200) {
					ObjSelf.callback(xmlObj);
				}else{
					ObjSelf.error();
				}
			}
		}
		if(this.method=="POST") xmlObj.send(this.content);
		else xmlObj.send(null);
	}
}
/*
   解析XML文件:用法,注意此处返回的值为查询xml的长度和内容的一个数组。可以利用长度来循环读取数据并显示在某些地方。
   url="http://www.antsnet.com/shop/usercontrol/xml.php?userName=M0l9PCVCcXQuLDE1Q0lZU1haJilCcXQuLGZQKildMTVDSVk=&orderby=eHpLU14=,bXNfPXs=,Q25KUVg=,M3FzR0g=,NWtvKT0=";
   xpath="/rss/order/order_no/product_name";
   var s=XML(url,xpath);
   alert(s["2"][0]);
*/
function XML(Url,Xpath){
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
var xml=[];
var currNode;
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load(Url);
var nodes=xmlDoc.documentElement;   
var xmlNode=nodes.selectNodes(Xpath);
var xmlLen=xmlNode.length;
for(var i=0;i<xmlLen;i++){
xml.push(xmlNode[i].text);
}
return {"1":xmlLen,"2":xml};
}
/*动态加载CSS*/
function loadCss(file){
    var cssTag = document.getElementById("loadCss");
    var head = document.getElementsByTagName("head").item(0);
    if(cssTag) head.removeChild(cssTag);
    css = document.createElement('link');
    css.href =file;
    css.rel = "stylesheet";
    css.type = "text/css";
    css.id = "loadCss";
    head.appendChild(css);
}
/*
  创建一个全屏窗口
*/
var FULLSCREEN=function(message){
	if($("fullscreen")){
		document.body.removeChild($("fullscreen"));
	}
	var INFO=getWindowInfo();

	var fullwidth=INFO.Width+"px";
	var fullheight=INFO.ContentHeight+"px";
	var top=((INFO.Height/2)+INFO.ScrollY)+"px";
	var left=((INFO.ContentWidth/2)-200)+"px";
	var fulldiv=document.createElement("div");
	fulldiv.setAttribute("id","fullscreen");
	fulldiv.setAttribute("align","left");
	fulldiv.style.background="white";
	fulldiv.style.opacity="0.6";
	fulldiv.style.position="absolute";
	fulldiv.style.left=0;
	fulldiv.style.top=0;
	fulldiv.style.filter="Alpha(opacity=60) ";
	fulldiv.style.width=fullwidth;
	fulldiv.style.height=fullheight;
	fulldiv.style.zIndex="1000";
	fulldiv.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
	fulldiv.style.textAlign = "center";
	document.body.appendChild(fulldiv);
	$("fullscreen").innerHTML="<div id=\"__message\" style=\"float:center;width:400px;height:200px;margin-left:"+left+";margin-top:"+top+";\"><div id=\"_message_title\" style=\"background:#336699;text-align:right;\"><a href=\"javascript:void('close');\" onclick=\"CLOSE('fullscreen');\"><span class=\"red\">关闭</span></a> </div><div id=\"_message_message\" style=\"border:1px solid #336699;width:398px;height:200px;over-flow:hidden;\">"+message+"</div></div>";
}
var Cover=function(message){
	if($("coverscreen")){
		document.body.removeChild($("coverscreen"));
	}
	var INFO=getWindowInfo();
	var fullwidth=INFO.Width+"px";
	var fullheight=INFO.ContentHeight+"px";
	var top=((INFO.Height/2)+INFO.ScrollY)+"px";
	var left=((INFO.ContentWidth/2)-200)+"px";
	
	var fulldiv=document.createElement("div");
	fulldiv.setAttribute("id","fullscreen");
	fulldiv.setAttribute("align","left");
	fulldiv.style.background="white";
	fulldiv.style.opacity="0.6";
	fulldiv.style.position="absolute";
	fulldiv.style.left=0;
	fulldiv.style.top=0;
	fulldiv.style.filter="Alpha(opacity=60) ";
	fulldiv.style.width=fullwidth;
	fulldiv.style.height=fullheight;
	fulldiv.style.zIndex="1000";
	fulldiv.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
	fulldiv.style.textAlign = "center";
	document.body.appendChild(fulldiv);
	$("coverscreen").innerHTML="<div id=\"__message_coverscreen\" style=\"float:center;width:400px;height:200px;margin-top:"+top+";\"><div id=\"_message_title_coverscreen\" style=\"background:#336699;text-align:right;\">&nbsp; </div><div id=\"_message_message_coverscreen\" style=\"border:1px solid #336699;width:398px;height:200px;over-flow:hidden;\">"+message+"</div></div>";
}
/*
  移除全屏窗口,延长TIMEOUT时间才关闭
*/
var REMOVESCREEN=function(){
	function remove(){
		var fullscreen=$("fullscreen");
		if(fullscreen){
			document.body.removeChild(fullscreen);
		}
	}
	clearTimeout(__TIMEOUT);
	__TIMEOUT=setTimeout(remove,TIMEOUT);
}
/*
  移出全屏窗口
*/
var CLOSE=function(Cover){
	var fullscreen=$(Cover);
	if(fullscreen){
		document.body.removeChild(fullscreen);
	}
}
/*
 复制Textare中的内容
*/
function doCopy()
{
	document.all.codeArea.select();
	rgn = document.all.codeArea.createTextRange();
	rgn.execCommand("Copy");
}
/*
  脚本错处信息
*/
var errorHandler=function(message,url,line)
{
	if(DEBUG){
		var errorMessage = "Error:"+message+"\n";
		errorMessage += "URL:"+url+"\n";
		errorMessage += "Line Number:"+line+"\n";
		FULLSCREEN(errorMessage);
		REMOVESCREEN();
		return true;
	}else{
		return "";
	}
}

onerror = errorHandler;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -