<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>tianya filter</title>

<script type="text/javascript">...

function $(o)...{ return document.getElementById(o); }


function XmlHttpRequest()...{

if(window.ActiveXObject)...{
//var ver = ["MSXML5.XMLHTTP","MSXML4.XMLHTTP","MSXML3.XMLHTTP","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
var ver = ["Microsoft.XMLHTTP","MSXML.XMLHTTP"];

for(var i=0; i<ver.length; i++)...{

try...{
return new window.ActiveXObject(ver[i]);

}catch(e)...{}
}

}else...{

try...{
return new XMLHttpRequest();

}catch(e)...{}
}
alert("创建XmlHttpRequest失败!");
}


var Ajax = function()...{
this.xmlHttp = XmlHttpRequest();
this.url = "http://cache.tianya.cn/pub/list/0/free.shtml";
//this.url = "http://cache.tianya.cn/new/publicforum/articleslist.asp?strItem=free&Part=1&strSubItem=&strSubItem2=";
}

Ajax.prototype = ...{

init : function()...{},

get : function(fnCallBack)...{
this.xmlHttp.open("GET", this.url, true);
var objThis = this;

this.xmlHttp.onreadystatechange = function()...{

if(objThis.xmlHttp.readyState == 4 && objThis.xmlHttp.status == 200)...{
fnCallBack(objThis.xmlHttp.responseText);
}
}
this.xmlHttp.setRequestHeader("If-Modified-Since","0");
this.xmlHttp.send(null);
},

post : function(fnCallBack)...{
this.xmlHttp.open("POST", this.url, true);
var objThis = this;

this.xmlHttp.onreadystatechange = function()...{

if(objThis.xmlHttp.readyState == 4 && objThis.xmlHttp.status == 200)...{
fnCallBack(objThis.xmlHttp.responseText);
}
}
this.xmlHttp.setRequestHeader("If-Modified-Since","0");
this.xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
//this.xmlHttp.setRequestHeader("Content-Type","text/html; charset=gb2312");
this.xmlHttp.send(null);
}
}


function Show(str)...{
str = CutString(str);
var obj = document.createElement("div");

if(obj)...{ //解析
obj.innerHTML = str;
var tables = obj.getElementsByTagName("table");
var len = tables.length - 1;
var row;
var arrOut = new Array();

for(var i=1; i<len; i++)...{
row = tables[i].rows[0];

if(row.cells.length>4 && parseInt(row.cells[4].innerText) == 0 )...{
arrOut.push(row.cells[1].innerHTML);
}
}

if(arrOut.length > 0)...{
Print(arrOut.join("<br/>"));

}else...{ Print("无")};
}
}


function Print(str)...{
$("divContent").innerHTML = str;
}


function CutString(str)...{
var nStart, nEnd;
str = str.toLowerCase();
nStart = str.indexOf("google3.js");
nEnd = str.indexOf("cache.tianya.cn/new/publicforum", parseInt(nStart));

if(nStart > 0 && nEnd > 0 && nStart < nEnd)...{ //found 1
str = str.substring(nStart, nEnd);
nStart = str.indexOf("<table");
nEnd = str.lastIndexOf("</table>");

if(nStart > 0 && nEnd > 0 && nStart < nEnd)...{ //found 2
str = str.substring(nStart, nEnd + 8);
return str;
}

else...{ alert("Error2");}
}

else...{
alert("Error1");
}
}

function Start()...{
var ajax = new Ajax();
ajax.post(Show);
}
</script>
</head>

<body onload="Start()">
<div id="divContent"></div>
</body>
</html>


能自动获取天涯杂谈最新发表0回复的贴子,显示时乱码,还不能自动回复,有空再改...