Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <style type="text/css">
- .recent-comment { padding-bottom:10px; }
- .recent-comment-header {}
- .recent-comment-body {}
- .recent-comment-footer { font-size: 80%; }
- </style>
- <script type="text/javascript">
- // Recent Comments blogger gadget by MS-potilas 2011
- // see http://yabtb.blogspot.com
- var numRecentComments = 5;
- var numCommentChars = 80;
- var numPerPost = 2; // max comments per post (to try) or 0
- var txtWrote = 'wrote:';
- var txtMore = 'Continue >>';
- var getTitles = true;
- var maxResultsPosts = ""; // or for example "&max-results=200"
- var maxResultsComments = ""; // or for example "&max-results=400"
- var urlToTitle = {};
- function getPostUrlsForComments(json) {
- for(var i = 0 ; i < json.feed.entry.length ; i++ ) {
- var entry = json.feed.entry[i];
- var href;
- for (var k = 0; k < entry.link.length; k++ ) {
- if (entry.link[k].rel == 'alternate') {
- href = entry.link[k].href;
- break;
- }
- }
- urlToTitle[href] = entry.title.$t;
- }
- }
- function showRecentComments(json) {
- var postHandled = {};
- var j = 0;
- if(numPerPost) {
- while(numPerPost < numRecentComments) {
- for(var i = 0 ; i < json.feed.entry.length ; i++ ) {
- var entry = json.feed.entry[i];
- if(!postHandled[entry["thr$in-reply-to"].href])
- postHandled[entry["thr$in-reply-to"].href] = 1;
- else
- postHandled[entry["thr$in-reply-to"].href]++;
- if(postHandled[entry["thr$in-reply-to"].href] <= numPerPost)
- j++;
- }
- if(j >= numRecentComments)
- break;
- numPerPost++;
- j = 0;
- postHandled = {};
- }
- if(numRecentComments == numPerPost)
- numPerPost = 0;
- }
- postHandled = {};
- j = 0;
- for(var i = 0 ; j < numRecentComments && i < json.feed.entry.length ; i++ ) {
- var entry = json.feed.entry[i];
- if(numPerPost && postHandled[entry["thr$in-reply-to"].href] && postHandled[entry["thr$in-reply-to"].href] >= numPerPost)
- continue;
- if(!postHandled[entry["thr$in-reply-to"].href])
- postHandled[entry["thr$in-reply-to"].href] = 1;
- else
- postHandled[entry["thr$in-reply-to"].href]++;
- j++;
- var href='';
- for (var k = 0; k < entry.link.length; k++ ) {
- if (entry.link[k].rel == 'alternate') {
- href = entry.link[k].href;
- break;
- }
- }
- if(href=='') {j--; continue; }
- var hrefPost = href.split("?")[0];
- var comment = "";
- if("content" in entry)
- comment = entry.content.$t;
- else
- comment = entry.summary.$t;
- comment = comment.replace(/<br[^>]*>/ig, " ");
- comment = comment.replace(/<\S[^>]*>/g, "");
- var postTitle="-";
- if(urlToTitle[hrefPost]) postTitle=urlToTitle[hrefPost];
- else {
- if(hrefPost.match(/\/([^/]*)\.html/)) postTitle = hrefPost.match(/\/([^/]*)\.html/)[1].replace(/_\d{2}$/, "");
- postTitle = postTitle.replace(/-/g," ");
- postTitle = postTitle[0].toUpperCase() + postTitle.slice(1);
- }
- document.write('<div class="recent-comment"><div class="recent-comment-header"><a title="'+postTitle+'" href="' + href + '">' + entry.author[0].name.$t + ' ' + txtWrote + ' </a></div>');
- if(comment.length < numCommentChars)
- document.write('<div class="recent-comment-body">' + comment + '</div>');
- else {
- comment = comment.substring(0, numCommentChars);
- var indexBreak = comment.lastIndexOf(" ");
- comment = comment.substring(0, indexBreak);
- document.write('<div class="recent-comment-body">' + comment + '...</div><div class="recent-comment-footer"><a title="'+postTitle+'" href="' + href + '">' + txtMore + '</a></div>');
- }
- document.write('</div>');
- }
- }
- if(getTitles)
- document.write('<script type="text/javascript" src="http://'+window.location.hostname+'/feeds/posts/summary?redirect=false'+maxResultsPosts+'&alt=json-in-script&callback=getPostUrlsForComments"></'+'script>');
- document.write('<script type="text/javascript" src="http://'+window.location.hostname+'/feeds/comments/default?redirect=false'+maxResultsComments+'&alt=json-in-script&callback=showRecentComments"></'+'script>');
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement