无须外挂,通过JS实现评论输出

原文地址

找到一个通过JS调用评论到首页的方法,不过似乎与我的页面不打配,所以只试了一下,还是有些效果的,但有些地方仍值得修改.如果你愿意可以试一下.

  1. 将留言时间格式改成 mm/dd/yyyy hh:mm:ss (02/11/2005 8:37:08 PM)
  2. 在侧边栏里适当的地方添加以下代码:                   
    <!-- **** FARRAGO RECENT COMMENTS HACK **** -->
    <!-- Version 1.03 -->
    <!-- Copyright © 2004 Ebenezer Orthodoxy -->
    <!-- http://www.pkblogs.com/boggerhacks -->
    <!-- ************** OPTIONS *************** -->
    <script type="text/javascript" language=" JavaScript1.2">
    var titleText = "Recent Comments";
    var numberToShow = 5;
    var displayTemplate = "[name]:<br/>[title]";
    var nameIsLink = true;
    </script>
    <!-- ********* CODE DO NOT CHANGE ******** -->
    <script type="text/javascript" language="JavaScript1.2">
    var comments=new Array(0);var title = "";
    var itemurl = "";
    function getSortDate(strDate){var d=new Date(strDate);
    var day=''+d.getDate();if(day.length==1)day='0'+day;
    var month=''+(d.getMonth()+1);if(month.length==1)
    month='0'+month;var hour=''+d.getHours();
    if(hour.length==1)hour='0'+hour;var min=''+
    d.getMinutes();if( min.length==1)min='0'+min;var sec=''+
    d.getSeconds();if(sec.length==1)sec= '0'+sec;
    var sortDate=''+d.getFullYear()+month+day+hour+min+sec;
    return sortDate;}
    function recentComment(t,u,i,a,d){var rcmnt=
    document.getElementById ('frch'+i).innerHTML;
    while(rcmnt.indexOf("\n") > -1)rcmnt=
    rcmnt.replace("\n","");while(rcmnt.indexOf(" />") > -1)
    rcmnt=rcmnt.replace(" />","/>");
    while(rcmnt.indexOf(" <a/>") > -1)rcmnt=
    rcmnt.replace(" <a/>","<a/>");var author=a;var pos=
    rcmnt.toLowerCase ().lastIndexOf('<br><a></a>posted by');
    var pos2=
    rcmnt.toLowerCase().lastIndexOf('<br><a></a><a></a>');
    var pos3=
    rcmnt.toLowerCase().lastIndexOf('<br/><a/><a/>');
    var pos4=
    rcmnt.toLowerCase().lastIndexOf('<br/><a></a><a></a>');
    var aoffset=pos+6;if (pos3 > -1) pos2=pos3;
    if (pos4 > -1) pos2=pos4;
    if (pos2 > -1){pos=pos2;aoffset=
    rcmnt.toLowerCase().lastIndexOf('<a><b> </b></a>');
    if (aoffset==-1)aoffset=
    rcmnt.toLowerCase().lastIndexOf('<a><b></b></a>')-1;}
    if (pos > -1){author=
    rcmnt.substr (aoffset+15,rcmnt.length-1);var expt="";
    expt=rcmnt.substr(0,pos-4).replace(/(<([^>]+)>)/ig,"");}
    else expt=rcmnt.replace(/(<([^>]+)>)/ig,"");
    author=author.replace ("<A ","<a ");
    if (expt.length > 50){expt=expt.substr(0,50);
    if (expt.lastIndexOf(' ') > -1)
    expt=expt.substr(0,expt.lastIndexOf(' '));expt+='...';}
    expt=expt.replace('"',"\"");expt= expt.replace("'","\'");
    if (!nameIsLink)author=author.replace(/(<([^>]+)>)/ig,"");
    var st=getSortDate(d)+'<li>'+displayTemplate+'</li>';
    st=st.replace('[name]',author);
    st=st.replace('[title]','<a title="'+expt+'" href="'+
    u+'#c'+i+'">'+t+'</a>');comments.push(st);}</script>
    <MainPage><h2 class="sidebar-title">
    <script type="text/javascript" language=" JavaScript1.2">
    document.write(titleText+'</h2>');</script>
    <Blogger>
    <span id="frcht<$BlogItemNumber$>"
    style="visibility:hidden;position:absolute;">
    <BlogItemTitle><$BlogItemTitle$></BlogItemTitle></span>
    <script type="text/javascript" language=" JavaScript1.2">
    title=
    document.getElementById('frcht<$BlogItemNumber$>').innerHTML;
    itemurl='<$BlogItemPermalinkURL$>';</script>
    <BlogItemCommentsEnabled><BlogItemComments>
    <span id="frch<$BlogCommentNumber$>"
    style="visibility:hidden;position:absolute;">
    <$BlogCommentBody$></span>
    <script type="text/javascript" language=" JavaScript1.2">
    recentComment(title,itemurl,'<$BlogCommentNumber$>',
    '<$BlogCommentAuthor$>','<$BlogCommentDateTime$>');
    </script></BlogItemComments>
    </BlogItemCommentsEnabled></Blogger><ul>
    <script type="text/javascript" language="JavaScript1.2">
    comments.sort();comments.reverse();
    for (i=0; i<10 && i < comments.length && i < numberToShow; i++){
    var s=comments[i];s=s.substr(14,s.length-1); document.write(s);}
    </script><br/><br/><span
    style="font-size:7pt;text-align:center;width:100%;border-top:1px dashed;">
    <a title="Farrago Recent Comments Hack from BloggerHacks"
    href=" http://www.pkblogs.com/bloggerhacks">BloggerHacks</a> </span>
    </ul></MainPage>
    <!-- END FARRAGO RECENT COMMENTS HACK -->
  3. 代码分很明显的两部分,第一部分可以修改显示的评论数(1-10),以及显示内容

4 条评论:

韩乾 说...

会拖慢速度

匿名 说...

gfdsgds

匿名 说...

仔细阅读并测试过,似乎我没有成功?请问是否更新过?

能否发段语言?

咖啡鱼 说...

这是针对以前的BLogger的