2020年8月23日 星期日

如何在BLOGSPOT顯示留言

最近見友好BLOGGER張留言放在首頁, GOOGLE 一下, 得左.......

https://www.wfublog.com/2015/10/blogger-recent-comments-v2-avatar-post-title-https.html 

二、安裝程式碼


如果安裝過舊版本的話,先刪除原本的小工具,按以下步驟重新新增一個「HTML/JavaScript」小工具即可。

如果沒有安裝過的話,請到後台 → 版面配置 → 新增小工具 → 選擇「HTML/JavaScript」→ 填入標題、以及以下程式碼:

  1. <script src='//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js'></script>
  2. <div id="rc2_area"></div>
  3. <div id="rc2_info"><a href="https://www.wfublog.com/2015/10/blogger-recent-comments-v2-avatar-post-title-https.html">ⓦ Recent Comments</a></div>
  4. <script>
  5. var brc2 = {
  6. startIndex: 1,
  7. showComment: 5, // 顯示幾則最新留言
  8. summaryLength: 25, // 留言摘要字數
  9. headWidth: 35, // 頭像寬度, 若不要顯示頭像請改為 0
  10. blogger: "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1P8A9W_FVw4vIggHySlggNFC-iwpAAK-soK27eBrYYQ0j2scP5ErR0tboIxyL70e7l0m60kINKMU6NIh6IAFwmEolcxzj8js8_812Mb7dgQdOA6lDGb6OZWoyr8RzTIlhR3nP_o55n3gm/s70/blogger.png",
  11. openID: "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqSmKAlYr_1f_F4tW3JsF6VmROTAG7NBXxkJ2gPeqdfsvgTDGGQXmONxHfRDgDwPbuqu7PZcLio6DhoRNkqZ6Dtox70C0N5imStUwVyVZ9vMi_rXs4ks0xGcmoTWi7mrUj5ABFcASbbNZg/s70/openid.png",
  12. anonymous: "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEt72DQAkUNIzjHSgDS3Xc5hLuPDZjXJP1FMi6r5uoWOdD6LSVD98W19Fzi7HCaV3ob42cSgyH6p7RJ6DVdtY9sri8eafMCJlRluXC9bLEUa5duagmQx7KFRWT8vS1PFIQ1rQaJzw9VEw4/s70/wfublog-comment.jpg",
  13. showTitle: "Y", // 不需要顯示文章標題則改為 "N"
  14. showDate: "Y", // 不需要顯示日期改為 "N"
  15. showCommentAmount: "Y", // 不需要顯示網站總留言數改為 "N"
  16. dateFormat: "Y-M-D", // 預設日期格式為 "年-月-日"; 若要改為 "月-日-年" 請將參數改為 "M-D-Y"
  17. openLogo: "", // 展開留言圖示
  18. closeLogo: "", // 收合留言圖示
  19. nextLogo: "", // 下一頁圖示
  20. prevLogo: "", // 上一頁圖示
  21. serialText: "編號",
  22. totalText: "總共:"
  23. };
  24.  
  25. brc2.openLogo=$("<a>"+brc2.openLogo+"</a>").html();brc2.closeLogo=$("<a>"+brc2.closeLogo+"</a>").html();brc2.fetch=0;brc2.total=0;brc2.postUrl=[];brc2.postTitle=[];brc2.anonymousLink="https://www.wfublog.com/2015/10/blogger-recent-comments-v2-avatar-post-title-https.html";brc2.switchPage=function(b,a,g){var d=brc2.showComment,e=(b>d),f=$("#rc2_commentIndex"),c="";b=e?d:b;c+="<a href='javascript:' class='rc2_openAll' title='留言全部展開'>"+brc2.openLogo+"</a><a href='javascript:' class='rc2_closeAll' title='留言全部收起'>"+brc2.closeLogo+"</a>";if(a>brc2.startIndex){c+="<a class='rc2_prevPage' href='javascript:' title='上一頁'>"+brc2.prevLogo+"</a>"}else{c+="<span class='rc2_prevPage'>"+brc2.prevLogo+"</span>"}if(e){c+="<a class='rc2_nextPage' href='javascript:' title='下一頁'>"+brc2.nextLogo+"</a>"}else{c+="<span class='rc2_nextPage'>"+brc2.nextLogo+"</a>"}$("#rc2_switchPage").html(c);$(".rc2_openAll").click(function(){$(".rc2_summary").hide();$(".rc2_content").show();$(".rc2_toggleLogo").html(brc2.closeLogo)});$(".rc2_closeAll").click(function(){$(".rc2_content").hide();$(".rc2_summary").show();$(".rc2_toggleLogo").html(brc2.openLogo)});$("a.rc2_prevPage").click(function(){brc2.init(a-d)});$("a.rc2_nextPage").click(function(){brc2.init(a+d)});if(f.length){f.html(brc2.serialText+" "+a+"-"+(a+b-1)+", "+brc2.totalText+" "+g)}};brc2.main=function(json){var feed=json.feed;if(!feed.entry){$("#rc2_area").html("<div style='text-align: center;'>目前尚無留言</div>");return}var nFetch=feed.entry.length,nIndex=parseInt(feed.openSearch$startIndex.$t),nTotalComment=parseInt(feed.openSearch$totalResults.$t),total=(brc2.showComment>nFetch)?nFetch:brc2.showComment,width=brc2.headWidth,summaryLength=brc2.summaryLength,anonymousLink=brc2.anonymousLink,openLogo=brc2.openLogo,closeLogo=brc2.closeLogo,dateFormat=brc2.dateFormat.split("-"),size="/s"+width*2+"-c/",reg1=/<.*?>/g,reg2=/\/s\d{2}.*?\//ig,html="",j=0,newAvatar="",noPost="",dateObj={},i,entry,authorName,content,summary,avatar,avatarLink,aboutAuthor,link,dateStr,dateArray,info;brc2.fetch=nFetch;brc2.total=total;html+="<ul>";for(i=0;i<total;i++){entry=feed.entry[i];authorName=entry.author[0].name.$t;content=entry.content.$t.replace(reg1,"");summary=(content.length>summaryLength)?content.substr(0,summaryLength):content;dateArray=entry.published.$t.substr(0,10).split("-");dateObj.Y=dateArray[0];dateObj.M=dateArray[1];dateObj.D=dateArray[2];dateStr=dateObj[dateFormat[0]]+"-"+dateObj[dateFormat[1]]+"-"+dateObj[dateFormat[2]];avatar=entry.author[0].gd$image.src;avatarLink=(entry.author[0].uri)?entry.author[0].uri.$t:"";aboutAuthor="關於"+authorName;if(entry.title.$t){while(j<entry.link.length&&entry.link[j].rel!="alternate"){j++}link=entry.link[j].href}else{link=(entry["thr$in-reply-to"])?entry["thr$in-reply-to"].href:anonymousLink}if(!entry["thr$in-reply-to"]){noPost="文章已刪除"}if(avatar.search("blank.gif")>0){if(avatarLink){avatar=brc2.openID}else{avatar=brc2.anonymous;avatarLink=anonymousLink;aboutAuthor="WFU BLOG 最新留言 V2"}}if(avatar.search("openid16-rounded.gif")>0){avatar=brc2.openID}if(avatar.search("b16-rounded.gif")>0){avatar=brc2.blogger}newAvatar=avatar.replace(reg2,size);html+="<li>";if(brc2.showDate=="Y"){html+="<i class='rc2_date'>"+dateStr+"</i>"}if(width>0){html+="<span class='rc2_avatar' style='float:left; width:"+width+"px;'><a href='"+avatarLink+"' target='_blank'><img src='"+newAvatar+"' onerror='this.src=\""+avatar+"\"' style='width:"+width+"px; height: "+width+"px;' title='"+aboutAuthor+"'/></a></span>"}html+="<div style='margin-left: "+((width>0)?(width+10):0)+"px; word-wrap: break-word;'><b class='rc2_author'>"+authorName+":</b>";if(summary!=content){html+="<div class='rc2_text'><span class='rc2_summary' title='展開留言'>"+summary+"... </span><span class='rc2_content' style='display:none;' title='收起留言'>"+content+" </span><a class='rc2_toggleLogo' href='javascript:' title='展開留言'>"+openLogo+"</a></div>"}else{html+="<div class='rc2_text'><span class='rc2_summary'>"+summary+"</span><span class='rc2_content' style='display:none;'>"+content+" </span></div>"}if(brc2.showTitle=="Y"){html+="<div class='rc2_postTitle'>-- <a href='"+link+"' target='_blank'>"+noPost+"</a></div>"}html+="</div><div style='clear: both;'/></li>"}html+="</ul>";if(brc2.showCommentAmount=="Y"){html+="<div id='rc2_commentIndex'></div>"}html+="<div id='rc2_switchPage'></div>";var _0xbc1b=["\x24\x28\x22\x23\x33\x22\x29\x2E\x31\x28\x31\x29\x3B\x37\x2E\x38\x28\x39\x2C\x62\x2C\x63\x29\x3B\x32\x3D\x22\x3C\x61\x20\x64\x3D\x27\x34\x3A\x2F\x2F\x65\x2E\x66\x2E\x67\x2F\x68\x2F\x69\x2F\x6A\x2D\x6B\x2D\x6C\x2D\x6D\x2D\x6F\x2D\x70\x2D\x35\x2D\x34\x2E\x31\x27\x20\x71\x3D\x27\x72\x27\x20\x35\x3D\x27\u6700\u65B0\u56DE\u61C9\uFF0B\u7559\u8A00\u8005\u982D\u50CF\uFF0B\u6587\u7AE0\u6A19\u984C\x5C\x6E\u7A0B\u5F0F\u8A2D\u8A08\uFF1A\x73\x20\x74\x27\x3E\u24E6\x20\x75\x20\x76\x3C\x2F\x61\x3E\x22\x3B\x77\x20\x24\x30\x3D\x24\x28\x22\x23\x30\x22\x29\x3B\x78\x28\x24\x30\x2E\x79\x29\x7B\x24\x30\x2E\x31\x28\x32\x29\x7D\x7A\x7B\x24\x28\x22\x23\x33\x22\x29\x2E\x41\x28\x22\x3C\x36\x20\x42\x3D\x27\x30\x27\x3E\x22\x2B\x32\x2B\x22\x3C\x2F\x36\x3E\x22\x29\x7D\x3B","\x7C","\x73\x70\x6C\x69\x74","\x72\x63\x32\x5F\x69\x6E\x66\x6F\x7C\x68\x74\x6D\x6C\x7C\x69\x6E\x66\x6F\x7C\x72\x63\x32\x5F\x61\x72\x65\x61\x7C\x68\x74\x74\x70\x73\x7C\x74\x69\x74\x6C\x65\x7C\x64\x69\x76\x7C\x62\x72\x63\x32\x7C\x73\x77\x69\x74\x63\x68\x50\x61\x67\x65\x7C\x6E\x46\x65\x74\x63\x68\x7C\x7C\x6E\x49\x6E\x64\x65\x78\x7C\x6E\x54\x6F\x74\x61\x6C\x43\x6F\x6D\x6D\x65\x6E\x74\x7C\x68\x72\x65\x66\x7C\x77\x77\x77\x7C\x77\x66\x75\x62\x6C\x6F\x67\x7C\x63\x6F\x6D\x7C\x32\x30\x31\x35\x7C\x31\x30\x7C\x62\x6C\x6F\x67\x67\x65\x72\x7C\x72\x65\x63\x65\x6E\x74\x7C\x63\x6F\x6D\x6D\x65\x6E\x74\x73\x7C\x76\x32\x7C\x7C\x61\x76\x61\x74\x61\x72\x7C\x70\x6F\x73\x74\x7C\x74\x61\x72\x67\x65\x74\x7C\x5F\x62\x6C\x61\x6E\x6B\x7C\x57\x46\x55\x7C\x42\x4C\x4F\x47\x7C\x52\x65\x63\x65\x6E\x74\x7C\x43\x6F\x6D\x6D\x65\x6E\x74\x73\x7C\x76\x61\x72\x7C\x69\x66\x7C\x6C\x65\x6E\x67\x74\x68\x7C\x65\x6C\x73\x65\x7C\x61\x66\x74\x65\x72\x7C\x69\x64","","\x66\x72\x6F\x6D\x43\x68\x61\x72\x43\x6F\x64\x65","\x72\x65\x70\x6C\x61\x63\x65","\x5C\x77\x2B","\x5C\x62","\x67"];eval(function(_0x57c2x1,_0x57c2x2,_0x57c2x3,_0x57c2x4,_0x57c2x5,_0x57c2x6){_0x57c2x5=function(_0x57c2x3){return(_0x57c2x3<_0x57c2x2?_0xbc1b[4]:_0x57c2x5(parseInt(_0x57c2x3/_0x57c2x2)))+((_0x57c2x3=_0x57c2x3%_0x57c2x2)>35?String[_0xbc1b[5]](_0x57c2x3+29):_0x57c2x3.toString(36))};if(!_0xbc1b[4][_0xbc1b[6]](/^/,String)){while(_0x57c2x3--){_0x57c2x6[_0x57c2x5(_0x57c2x3)]=_0x57c2x4[_0x57c2x3]||_0x57c2x5(_0x57c2x3)}_0x57c2x4=[function(_0x57c2x5){return _0x57c2x6[_0x57c2x5]}];_0x57c2x5=function(){return _0xbc1b[7]};_0x57c2x3=1}while(_0x57c2x3--){if(_0x57c2x4[_0x57c2x3]){_0x57c2x1=_0x57c2x1[_0xbc1b[6]](new RegExp(_0xbc1b[8]+_0x57c2x5(_0x57c2x3)+_0xbc1b[8],_0xbc1b[9]),_0x57c2x4[_0x57c2x3])}}return _0x57c2x1}(_0xbc1b[0],38,38,_0xbc1b[3][_0xbc1b[2]](_0xbc1b[1]),0,{}));$(".rc2_text").click(function(){var $this=$(this);$this.children(".rc2_summary, .rc2_content").toggle();$this.children(".rc2_toggleLogo").html(function(){return $(this).html()==openLogo?closeLogo:openLogo})});$(".rc2_postTitle a").each(function(){var postLink=this.href.split("?")[0].replace(/http:\/\/|https:\/\//,""),path=postLink.substr(postLink.indexOf("/")),postFeed="/feeds/posts/summary?alt=json-in-script&callback=?&path="+path,index=brc2.postUrl.indexOf(path),$this=$(this),title;if(index<0){if(path.indexOf("/p/")>-1){$this.html("非文章頁面");return}$.getJSON(postFeed,function(json){var title=json.feed.entry[0].title.$t;$this.html(title).attr("title",title);if(brc2.postUrl.indexOf(path)<0){brc2.postUrl.push(path);index=brc2.postUrl.indexOf(path);brc2.postTitle[index]=title}})}else{title=brc2.postTitle[index];$this.html(title).attr("title",title)}})};brc2.init=function(a){a=a||brc2.startIndex;var b="/feeds/comments/default?orderby=published&start-index="+a+"&max-results="+(brc2.showComment+1)+"&alt=json-in-script&callback=brc2.main";$("#rc2_area").html("<div style='text-align: center; margin: 20px auto;'><img src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi72sxNjXyOlOWat_7v7fWxFYrDNfo6UP-Wv_k0o-YA2yu8r25NcFCEVaGnC-X5_N_FPPM4udRwTMECsVeP0IDQbAtrITjfsg5LJwJ3y-hH_SX5nwDgY0MZzce6iEnTEbLrP8-Y7_-ux_ee/s512/indicator-light.gif'/></div>");$.getScript(b)};brc2.init();
  26. </script>
  27.  
  28. <style>
  29. #rc2_area ul,
  30. #rc2_area li {
  31. list-style: none; margin: 0;
  32. }

  33. #rc2_area li {
  34. padding: 5px 0;
  35. border-bottom: 1px solid #eee;
  36. text-indent: 0;
  37. font-size: 14px;
  38. }

  39. #rc2_area a,
  40. #rc2_info a {
  41. text-decoration: none;
  42. }

  43. #rc2_info {
  44. float: right;
  45. font-size: 11px;
  46. font-family: helvetica, arial, sans-serif
  47. }

  48. #rc2_info a {
  49. color: #ccc;
  50. }

  51. .rc2_date {
  52. color: #aaaaaa;
  53. font-size: 80%;
  54. float: right;
  55. }

  56. .rc2_avatar img {
  57. padding: 0px;
  58. border: 2px solid #fff;
  59. box-shadow: 0px 1px 9px #666;
  60. border-radius: 7px;
  61. opacity: 0.9;
  62. }

  63. .rc2_avatar img:hover {
  64. opacity: 1;
  65. }

  66. .rc2_author {
  67. font-size: 110%;
  68. }

  69. .rc2_text {
  70. cursor: pointer;
  71. margin: 5px 0px;
  72. opacity: 0.8;
  73. }

  74. .rc2_text:hover {
  75. opacity: 1;
  76. }

  77. .rc2_toggleLogo {
  78. display: none;
  79. }

  80. #rc2_area li:hover .rc2_toggleLogo {
  81. display: inline;
  82. }

  83. .rc2_postTitle {
  84. font-size: 85%;
  85. font-weight: bold;
  86. line-height: 110%;
  87. width: 100%;
  88. overflow: hidden;
  89. white-space: nowrap;
  90. text-overflow: ellipsis;
  91. }

  92. #rc2_commentIndex {
  93. margin: 5px 0;
  94. text-align: center;
  95. }

  96. #rc2_switchPage {
  97. background-color: #eee;
  98. margin: 5px 0;
  99. padding: 3px;
  100. font-size: 20px;
  101. line-height: 16px;
  102. }

  103. #rc2_switchPage a,
  104. #rc2_switchPage span {
  105. box-sizing: border-box;
  106. display: inline-block;
  107. width: 25%;
  108. padding: 0;
  109. border-left: 1px dashed #aaa;
  110. text-align: center;
  111. }

  112. #rc2_switchPage a:hover {
  113. background-color: rgba(100, 100, 100, 0.1);
  114. }

  115. #rc2_switchPage a:first-child {
  116. border-left: 0;
  117. }
  118. </style>

如果都使用預設值的話,直接存檔就可開始使用。

如果要修改參數請參照以上程式碼行號:

 

 

沒有留言: