以前写的读取博客园RSS最新文章的脚本备份

<!--读取RSS-->
<script>
var xmlHttp;
var xmlRequest;
//获取当前月份用作当月随笔比较
var month = new Date().getMonth()-2;
//文章,标题,连接

var title = new Array();
var link = new Array();

function $(id)
{
return document.getElementById(id);
}
//构造函数
function article(sURL,sTitle){
this._URL=sURL;
this._title=sTitle;
}
article.prototype 
= {
get_URL: 
function(){ return this._URL; },
set_URL: 
function(value){ this._sURL = value; },
get_title: 
function() { return this._title; },
set_title: 
function(value) { this._title = value; },

articleView:
function(){
var articleURL=this.get_URL();
var articleTitle=this.get_title();
var articleViewHTML="&nbsp;<img style=\"position:relative;top:3px;\"   src=\"http://www.cnblogs.com/images/cnblogs_com/junyistar/119926/o_ss.gif\" alt=\"最新随笔\" /> 最新随笔:" + "<a title=\"" + articleTitle + "\" href=\"" + articleURL + "\">" + articleTitle + "</a>";;
var mylinks=document.getElementById("navigator");
var newArticle=document.createElement('span');
newArticle.innerHTML
=articleViewHTML;
mylinks.appendChild(newArticle);
}

};



//构造XMLHTTPRequest
function createRequest()
{
    
    
if(window.ActiveXObject)
    {        
        
var MSXML = new Array('MSXML2.XMLHTTP''Microsoft.XMLHTTP''MSXML2.XMLHTTP.3.0''MSXML2.XMLHTTP.4.0''MSXML2.XMLHTTP.5.0');  //IE 5,6,7
        for(var i=0;i<MSXML.length;i++)
        {
            
try
            {        
                xmlRequest 
= new ActiveXObject(MSXML[i]);
                
break;
            }
            
catch(e)
            {
                xmlRequest 
= null;
            }    
        }
    }
    
else if(window.XMLHttpRequest) //for Firefox, Opera,IE 7
    {
        xmlRequest 
= new XMLHttpRequest();        
    }    

  
return xmlRequest;
}
//异步发送请求并处理返回
function callServer()
{

    xmlHttp 
= createRequest();
    
if(xmlHttp!=null)
    {    
var url = "";
         
var domain = "www.cnblogs.com";
        
if(window.location.host != domain)
        {
            url 
= "http://junyistar.cnblogs.com/rss";
        }
        
else
        {
            url 
= "http://www.cnblogs.com/junyistar/rss";
        }

            xmlHttp.open(
"GET",url,false);
            xmlHttp.onreadystatechange 
= updatePage;
            xmlHttp.send(
null);
                    
        
    }
}
function updatePage()
{
    
    
if(xmlHttp.readyState == 4)
    {
        
if(xmlRequest.status == 0 || (xmlRequest.status >= 200 && xmlRequest.status < 300))
        {
            
var myArticle = new Array();
            
var j = 0;
            
var content = xmlHttp.responseXML;
            
var items = content.getElementsByTagName("item");
                
if(items.length>0)
                {
                    
for(var i=0; i <items.length ; i++)
                    {
                        
if(new Date(items.item(i).childNodes[4].firstChild.nodeValue).getMonth() == month)
                        {
                            title[i]
=items.item(i).childNodes[0].firstChild.nodeValue;
                            link[i]
=items.item(i).childNodes[1].firstChild.nodeValue;
                            
//找到当月文章赋值
                            
                            myArticle[j] 
= new article(link[i],title[i]);
                            j
++;

                        }
                    }
                }
            
var randomNum = parseInt(myArticle.length*Math.random());
            myArticle[randomNum].articleView(
posted @ 2008-03-27 23:12  早班火车  阅读(324)  评论(0)    收藏  举报