当前位置: 首页 > 工具软件 > CC-CEDICT > 使用案例 >

CC_JS

空成天
2023-12-01
 //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
 类似资料:

相关阅读

相关文章

相关问答