Javascript Codes

//Change Left Menu (Eassay)
function ChangeEssayStyle()
{
   var oLeftMenu = document.getElementById("leftmenu");
   var oListTitle =  oLeftMenu.childNodes[0].childNodes[1];
   var arrA = oListTitle.getElementsByTagName('a');
  
   var reg1 = /<a(.*)<//a>/ig;
   for( var i=0; i<arrA.length;)
   {
      //Change <a>...</a> as <span>...</span>
      var strtmp = arrA[i].outerHTML;
      arrA[i].outerHTML = strtmp.replace(reg1,"<span style='cursor:hand;color:blue;' status='out' onmouseover='mhovItem(this)' onmouseout='motItem(this)' onclick='mclItem(this)' $1 <//span>");
     
      //Delete "(RSS)"
      arrA[i].innerText=='(RSS)'?arrA[i].parentElement.removeChild(arrA[i]):i++;
   }
}
function mhovItem( oItem )
{
    oItem.status = oItem.status=="clicked"?click:"over";
    oItem.style.border = "1px solid rgb(128,128,128)";
    oItem.style.backgroundColor = "rgb(192,192,192)";
}
function motItem( oItem )
{
    if( oItem.status=="clicked" )
       return;
    oItem.status = "out";
    oItem.style.border = "";
    oItem.style.backgroundColor = "Transparent";
}
function mclItem( oItem )
{
    var oListItem = oItem.parentElement;
    if( oItem.status=="clicked" )
    {
        oItem.status="over"; 
        mhovItem(oItem); 
        for( var i=0; i<oListItem.childNodes.length; i++ )
        {
          if(oListItem.childNodes[i].name=="AddItem")
          {
             oListItem.removeChild(oListItem.childNodes[i]);
             i--;
          }
        }
        return;
    }
    oItem.status="clicked";
    oItem.style.backgroundColor = "white";
    oItem.style.border="1px solid gray";
     
    if( typeof(oItem.myHref)=="undefined" )
       oItem.myHref = String(oItem.href);
    var strHref = oItem.myHref;
    oItem.href = "#";

    //Add Loading.... Element
    var tmpDiv = document.createElement("<div style='background-color:transparent;font-Size:8pt;'>");
    tmpDiv.name="AddItem";
    tmpDiv.innerText = "Loading...";
    oListItem.appendChild(tmpDiv);
    //Add Loading.... Element END
   
    setTimeout(_threadLoadSubItem(oItem),100);
}
function _threadLoadSubItem(oHref)
{
    return function(){
    var oListItem = oHref.parentElement;
    var xmlhttp = MyXmlhttp("GET",oHref.myHref,false);

    oListItem.removeChild(oListItem.childNodes[oListItem.childNodes.length-1]);
   
    var strContent = xmlhttp.responseText;
    var re1 = /<div class="postTitle"[/w|/W]*?//div>/g ;
    var arr1 = new Array();
    while( arr1 = re1.exec(strContent) )
    {
        var strPassageInfo = strContent.substring(arr1.index,arr1.lastIndex);
       
        // Get PassageInfo;
        var re2 = /">.*?</i;//PassageTitle;
        var re3 = /href=/".*/"/i;//Passage href
        var arr2 = re2.exec(strPassageInfo);
        var str2 = strPassageInfo.substring(arr2.index+2,arr2.lastIndex-1);
        var arr3 = re3.exec(strPassageInfo);
        var strHref = strPassageInfo.substring(arr3.index+6,arr3.lastIndex-1);

        var oSubItem = document.createElement("<div name='AddItem'>");
        oListItem.appendChild(oSubItem);
        oSubItem.innerText="     ";
        var oChild = document.createElement("<span style='background-color:transparent;font-Size:8pt;cursor:hand;' onmousemove=mhovSubItem(this) onmouseout=motSubItem(this) onclick=mclSubItem(this)>");
        oChild.myHref = strHref;
        oChild.oriText = str2;
        oChild.bShowTip = "false";
        oChild.innerHTML = AdjustStringAccordingParent(str2,oChild,oSubItem);
        oSubItem.appendChild(oChild);
    }
   
    }

}

function mhovSubItem( oItem )
{
   if( oItem.bShowTip!="true")
   {
   oItem.style.backgroundColor="rgb(157,254,129)";
   oItem.style.border = "1px solid rgb(0,255,128)";
  
   var nLeft = event.clientX + 6;
   var nTop  = oItem.offsetTop+oItem.offsetHeight+2;
   var toolTip = document.createElement("div");
   toolTip.id="tooltip";
   toolTip.style.position="absolute";
   toolTip.style.left = nLeft;
   toolTip.style.top = nTop;
   toolTip.style.border = "1px solid rgb(241,239,226)";
   toolTip.style.borderBottom = "1px solid rgb(113,111,100)";
   toolTip.style.borderRight = "1px solid rgb(113,111,100)";
   toolTip.style.backgroundColor = "white";
   toolTip.innerHTML = "<div style='border:/"2px solid rgb(223,223,223)/"; color:/"rgb(53,53,53)/";font-family:/"monospace/"; font-weight:/"bold/";'><nobr>"+oItem.oriText+"<//nobr><//div>";
   oItem.parentElement.appendChild(toolTip);
   oItem.bShowTip = "true";
   }
}
function motSubItem( oItem )
{
   oItem.style.background="transparent";
   oItem.style.border="none";
   var oToolTip = document.getElementById("tooltip");
   var oTmp = oItem.parentElement;
   oTmp.removeChild(oToolTip);
   oItem.bShowTip = "false";
}

function mclSubItem( oItem )
{
   var xmlhttp = MyXmlhttp("GET",oItem.myHref,false);
   var strContent = xmlhttp.responseText;
   var re3 = /<div id=/"main/">[/w|/W]*<//div>/ig;
   var arrIndex = re3.exec(strContent);
   if( arrIndex==null)
   {
       alert("Locate Eassay Content Error!");
       return;
   }
   var strUseful = strContent.substring(arrIndex.index,arrIndex.lastIndex);
   ShowNewEssay(strUseful);
}
function AdjustStringAccordingParent( strData , oTmpObj , oParentObj)
{
     oTmpObj.innerText = strData.substr(0,1);
     oParentObj.appendChild(oTmpObj);
     var nPerHeight = oTmpObj.offsetHeight + 3;//
    
     oTmpObj.innerText = strData;
     if( oTmpObj.offsetHeight<=nPerHeight )
        return strData;//Only one line, return original string.
    
     var strTmp = strData;;
     while( oTmpObj.offsetHeight > nPerHeight )
     {
         strTmp = strTmp.substr(0,strTmp.length-2);
         oTmpObj.innerText = strTmp+"...";
     }
     var strReturn = oTmpObj.innerText;
     oParentObj.removeChild(oTmpObj);
     return  strReturn;  
}
function ShowNewEssay( strContent )
{
     var oMain = document.getElementById('main');
     oMain.style.display="none";
     var oNewEassay = document.getElementById('newEassay')==null?document.createElement('<div id=newEassay>'):document.getElementById('newEassay');
    
     oNewEassay.innerHTML = strContent;
     for(var i=0; i<oMain.parentElement.childNodes.length; i++ )
     {
        if(oMain.parentElement.childNodes[i].id=='main')
           break;
     }
     oMain.parentElement.childNodes[i+1].style.display = "none";// Hide "Power by....." . Because new Eassay has already copy that from other eassay!
     oMain.parentElement.insertBefore(oNewEassay,oMain.parentElement.childNodes[i]);
}
//Change Left Menu (Eassay) End
//Tools Functions
function MyXmlhttp( sMethod, sUrl, bAsync)
{
        var xmlhttp = (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
        if( !xmlhttp )
        {
           alert("XmlhttpRequest cannot be created");
           return false;
        }
        xmlhttp.open(sMethod,sUrl,bAsync);
        if( xmlhttp.readyState == 4 )
        {
             if( xmlhttp.state == 404)
                alert("As url:"+DstPath+" cannot be opened/nDeclareFns Failed");
        }
        xmlhttp.send();
        return xmlhttp;
}
//Tools Functions End
//SCRIPTEND

posted on 2006-08-04 09:40  norsd  阅读(147)  评论(0编辑  收藏  举报

导航