CC_JS

 //SCRIPT_START
function  processArticle( strChaos,strHref )
{
      this.thisObj = this;
      this.strChaos = strChaos;
      this.strHref = strHref;
      this.ndComment = null;
      this.ndArticle = null;
      this.ndCommentForm = null;
    var reText  = /<div class=/"postText/">.*<//div>/i;
    var reTitle = /<div class=/"postTitle/">.*<//div>/i;
    var reFoot  = /<div class=/"postFoot/">.*<//div>/i;
    var reCommentForm = /<div id=/"commentform/"[/w|/W]*<//div>/i;
    var reForm1 = /<form name=/"Form1/"[/w|/W]*?<//div>/i;
    var reEVENTVALIDATION = /<input type=/"hidden/" name=/"__EVENTVALIDATION/".*>/i;
    var arrIndex;
    //---->Get Text<----//
    arrIndex = reText.exec(strChaos);
    if( arrIndex==null)
      alert("Locate postText  Error!");
    this.strContent = SysTool.matchTag(arrIndex[0],'div');
    //---->Get Title<----//   
    arrIndex = reTitle.exec(strChaos);
    if( arrIndex==null )
      alert("Locate postTitle error!");
    this.strTitle = SysTool.matchTag(arrIndex[0],'div');
    //---->Get Foot<----//  
    arrIndex = reFoot.exec(strChaos);
    if( arrIndex==null)
      alert("Locate postFoot error!");
    this.strFoot = SysTool.matchTag(arrIndex[0],'div');
    //---->Get Comment<----//
    if( (arrIndex = reCommentForm.exec(strChaos)) ==null )
      alert("Locate comment  error!");
    this.strCommentForm = SysTool.matchTag( arrIndex[0],'div' );
    //---->Get Form1's submit parameters<----//
    if( (arrIndex = reForm1.exec(strChaos)) == null )
      alert("Loacate Hidden Parameter1 of form error!");
    this.strHiddenParameters = SysTool.matchTag( arrIndex[0],'div');
    //---->Get EVENTVALIDATION<----//
    if( (arrIndex = reEVENTVALIDATION.exec(strChaos)) == null )
       alert("Loacate EVENTVALIDATION of form error!");
    this.strHiddenParameters += arrIndex[0];
   
   this.ShowArticle = function()
    {
         var oMain = document.getElementById('main');
       var arrPosts = SysTool.getElementsByClassName(oMain, 'post');
       //Show Title
       var oPostTitle = SysTool.getElementsByClassName( arrPosts[0], 'postTitle')[0];
           oPostTitle.innerHTML = this.strTitle;
       //Show Content
       var arrPostTexts = SysTool.getElementsByClassName( arrPosts[0],'postText');
       var oPostText = arrPostTexts[0];
       var oScript = oPostText.getElementsByTagName('script')[0];
       oPostText.innerHTML = this.strContent;
       //Show postFoot  
       var oPostFoot = SysTool.getElementsByClassName( arrPosts[0],'postFoot')[0];
           oPostFoot.innerHTML = this.strFoot;
    }
    this.ShowComment = function( oParent ,nStyle,bDebug)
    {
      var oComment = null;
            oComment  = document.getElementById('comment');
      if( oComment==null )
      {
          oComment = document.createElement('div');
          oComment.id = 'comment';
          oParent.appendChild(oComment);
      }
      this.ndComment = oComment;
      oComment.innerHTML = 'Loading comments......';
      var   oTime = new Date();
      var  xmlHref = "http://blog.csdn.net"+getCommentFileName( this.strHref )+"?id="+oTime.getTime();
      if( bDebug )
      {
             alert(this.strHref);
            alert(xmlHref);
      }
      var  xmlhttp = new _xmlhttp( xmlHref,true);
           xmlhttp.openRef("GET",false,null,null);
           xmlhttp.sendRef();
      var oHideCmt = document.createElement('div');
             oHideCmt.style.display='none';
      oComment.appendChild(oHideCmt);
      if( nStyle==1)
      {
          var strRspsText = xmlhttp.getResponseText();
          var arrCmts = new Array();
          var reRsps = /<a.*?br>/ig;
          var arrRe = new Array();
          while( arrRe = reRsps.exec(strRspsText))
          {
                arrCmts.push(arrRe[0]);
          }
          oComment.innerHTML = '';
          for( var i=arrCmts.length-1; i>=0; i-- )
                oComment.innerHTML += arrCmts[i];
      }
      else
      {
          oComment.innerHTML = xmlhttp.getResponseText();
      }
    }
    this.GetCommentNode = function()
    {
           return this.ndComment;
    }
    this.ShowCommentForm = function(oParent)
    {
         var oCommentForm = null;
       if( (oCommentForm = document.getElementById('commentform')) == null )
       {
            oCommentForm = document.createElement('div');
            oCommentForm.id = 'commentform';
            oParent.appendChild(oCommentForm);
      }
      oCommentForm.innerHTML = (this.strCommentForm+this.strHiddenParameters);
      //Show Verify Code
      var oImgPath,oImgArea,oImg;
      try
      {
        if( (oImgPath=document.getElementById('VCImageSrc'))==null )
            throw "cannot find [VCImageSrc] Element ";
        if( (oImgArea = document.getElementById('VCImageSpan'))==null )
            throw "cannot find [VCImageSpan] Element ";
        oImg = document.createElement('img');
        oImg.alt = 'Verify Code';
        oImg.src = "http://blog.csdn.net"+oImgPath.value;
        oImgArea.appendChild(oImg);
        oImgArea.parentNode.parentNode.style.display = "";
      }
      catch(e1)
      {
           alert(e1);
           return false;
      }
      //Change Submit Button to Normal Button for AJAX
      try
      {
        var oEVENTTARGET,oEVENTARGUMENT,oVIEWSTATE,oName,oNetAddr,oComment,oVerifyCodes,oBtnSubmit,oEVENTVALIDATION;
            oEVENTTARGET = getElementById('__EVENTTARGET',document,2);
            oEVENTARGUMENT = getElementById('__EVENTARGUMENT',document,2);
            oVIEWSTATE = getElementById('__VIEWSTATE',document,2);
            oName = getElementById('PostComment.ascx_tbName',document,2);
            oNetAddr = getElementById('PostComment.ascx_tbUrl',document,2);
            oComment = getElementById('PostComment.ascx_tbComment',document,2);
            oVerifyCodes = getElementById('PostComment.ascx_ValidationKey',document,2);    
            oBtnSubmit= getElementById('PostComment.ascx_btnSubmit',document,2);
            oEVENTVALIDATION = getElementById('__EVENTVALIDATION',document,2);     
        var arrPostData = new Array(oEVENTTARGET,oEVENTARGUMENT,oVIEWSTATE,oName,oNetAddr,oComment,oVerifyCodes,oBtnSubmit,oEVENTVALIDATION);
        var oMyBtn = document.createElement('input');
            oMyBtn.type = 'button';
            oMyBtn.className = 'Button';
            oMyBtn.NormalValue = 'Submit';
            oMyBtn.DisableValue = 'Posting......';
            oMyBtn.value = oMyBtn.NormalValue ;
            oMyBtn.onclick = this.OnAjaxSubmit(this.thisObj,strHref,arrPostData,strHref,oParent);   
        oBtnSubmit.parentNode.insertBefore(oMyBtn,oBtnSubmit);
        oBtnSubmit.style.display = 'none';
      }
      catch(e2)
      {
           alert('Exception:'+e2);
           return false;
      }
    }
   
    this.OnAjaxSubmit = function(oProcessArticle,strHref,arrSendContent,strCommentHref,oCommentParent)
    {
      return function()
        {
           this.disabled = true;
           this.value = this.DisableValue;
           var xmlhttp = new _xmlhttp(strHref,true);
                 xmlhttp.OnStatus200 = oProcessArticle.OnAjaxSubmit_CallBack(oProcessArticle,this,oCommentParent);
                 xmlhttp.openRef("POST",true,null,null);
                 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        var  strSend='';
        try
        {
             if( arrSendContent.constructor!=Array)
                throw("Exception: arrSendContent is not an Array");
             for( var i=0; i<arrSendContent.length; i++ )
                strSend += (encodeURIComponent(arrSendContent[i].name)+'='+encodeURIComponent(arrSendContent[i].value)+'&');
             strSend = strSend.substr(0,strSend.length-1);
        }
        catch(e1)
        {
             alert(e1+"/nPadding Post Data Error");
        }
        xmlhttp.sendRef(strSend);
       }//return function End
    }//function OnAjaxSubmit End
    this.OnAjaxSubmit_CallBack = function( oProcessArticle,oButton,oCommentParent )
    {
        return function()
  {
        oButton.disabled = false;
        oButton.value = oButton.NormalValue;
        var strTmp = this.getResponseText();
        var reTestVC  = /span id=/"PostComment.ascx_VKValidator/" style=/"color:Red;/"/i;
        if( reTestVC.exec(strTmp ) == null )
            oProcessArticle.ShowComment(oCommentParent,document.getElementById('commentRadio').actionRadio);
        else
             alert('VC error!');
       }
    }
}

function getCommentFileName(url){   
      //url= "http://blog.csdn.net/norsd/archive/2006/09/10/1203705.aspx";
        var r = /^https?:[^/]+//([^/]+)//[^/]+///d{4}///d{1,2}///d{1,2}//(/d+)/.aspx/i;
      //^start: http :  / /xxxxx /(xxxxxx)/xxxx  /0000  / 0-99   / 0-99   /(000..).aspx
        if(r.test(url))
        {
            var tmp = "/CachedHTML/comments/"+ RegExp.$1 +"."+ RegExp.$2 +".html";
            //alert(tmp);
            return tmp;           
        }
       
        return "";
    }
//SCRIPT_END
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值