Wednesday, May 2, 2012


Top Commentators Gadget with avatars

I had a request of this gadget in one blog comment. There are some top commentators gadgets around, most relying on a Yahoo pipe. I knew it can be done with just javascript, with no pipes. Demo: it is installed on this blog, look at the right sidebar. Hope you like it. :)


You can configure the maximum number of top commentators, and minimum number of comments one must have to get on the list (to weed out the 1 comment commentators, if wanted, for example). Own nick and a list of other nicks (for example "Anonymous") can be excluded from the list. Output strings can be translated.

The Script, installing

Add a HTML/Javascript gadget to your blog, and paste the following code into it.

Script configuration

There are two CSS definitions at first, which can be changed to your liking. After that there comes javascript code and configurable variables. Here is a list of the variables and a short explanation.

maxTopCommenters: how big the list is at maximum
minComments: how many comments must top commentator have at least
numDays: from how many days (ex. 30), or 0 from "all the time" (max 500 comments)
excludeMe: true, if own comments excluded
excludeUsers: array of usernames to exclude
maxUserNameLength: if 0, don't cut; if > 4, cut lenghty usernames

txtTopLine: specifies, what is output on each line. This text can have simple variables, which are: [#], [image], [user], and [count]. [#] is substituted by position on the list, [image] by commentator's avatar image, [user] by commentator name and [count] by number of comments. Text can also contain html.
txtNoTopCommenters: what to display, if list is empty
txtAnonymous: "Anonymous" username localized, or empty if English text "Anonymous" is to be used
getTitles: if true, fetch titles from post feed; if false, titles are generated from url
blogger favico [B]
urlMyAvatar: especially if trueAvatars = false, set here the url to your avatar image
urlMyProfile: if you don't have a profile gadget on page, put your profile url here!
urlAnoAvatar: anonymous avatar, you can change from mystery man to a custom one, if you want, possibly this
urlNoAvatar: comment feed offers the icon (Blogger logo) for those Bloggers who have not set their profile image. You can override the icon with this setting (default: ).

cropAvatar: crop avatar to square (true) or stretch (false) to square
sizeAvatar: size of avatar in x and y direction, pixels

If you have very much comments (thousands and thousands of them), I suggest you to use this as "top commentators of 30 days" gadget or something like that (set numDays variable to 30), so that it won't take too long to load and calculate all the comments.

June 5th 2012: Small CSS update: Blogger changed the paddings of .profile-name-link, that's why I added this line (line 3.):
.top-commenter-line .profile-name-link {padding-left:0;}

August 1st 2017: To fix avatars, please change lines 48 and 49 (article code is updated).
[Hide comments] - [Show comments]
Click on a single comment to hide/show its text


Anonymous said... [reply]

WOW! That's what I was talking about. :D
Thank you very much. :)

Ismail Sossé Alaoui said... [reply]

Hi admin thanks a lot for this great work.
i want to say that the gadget doesn't on my internet explorer
thanks to answer

MS-potilas said... [reply]

@Mr Admin Hi, thanks for the report on IE, reminds me that I always should test on Internet Explorer, too... Sorry about the incompatibility.

I've updated the code in this article to work also with Internet Explorer, lines 31-36 are new (implements indexOf if it does not exist).

Beben Koben said... [reply]'s me, top commentator :D

Ismail Sossé Alaoui said... [reply]

thanks MS-potilas for this, and i want to make you knowing that i have the same problem with recent comment...
thanks to answer

MS-potilas said... [reply]

@Mr Admin Hi, there's some bug in IE7 emulate mode with feeds with "foreign characters". It can be fixed by editing the template and changing this:

<meta content='IE=EmulateIE7' http-equiv='X-UA-Compatible'/>

to this:

<meta content='IE=EmulateIE8' http-equiv='X-UA-Compatible'/>

Hope it helps. :)

Ismail Sossé Alaoui said... [reply]

thanks a lot now it work normally@MS-potilas

Taufik Nurrohman said... [reply]

Very nice. This is really use the original Blogger feed URL!

Unknown said... [reply]

Good are a genius...:)

Blackswan said... [reply]

This is great! Tried installing but my comments are also showing. How can I exclude them? Thks!

MS-potilas said... [reply]

@Shirley Tay
Hi, you probably don't have Profile gadget on your blog, so you must set variable urlMyProfile to point to your profile page, like this:

var urlMyProfile = '';

Blackswan said... [reply]

Thks for your prompt response! I should've included my link for your reference earlier! I'm not sure what's Profile Gadget but I think I've got one. I'm not tech savvy. Could u kindly take a look at my blog? If I don't have one, do I just copy & paste this "" inside the code? Thks so much!

Blackswan said... [reply]

Sorry, my blog link: Shirley's Luxury Haven. Thanks again!

MS-potilas said... [reply]

@Shirley Tay
Hi, it seems that with Google plus the profile link leads directly there, so yes, the profile link must be set. Now line 28. reads:

var urlMyProfile = ''; // set if you have no profile gadget on page

Change it to:

var urlMyProfile = '';

That should do it.

Another way to make it block your own comments is to change "someotherusertoexclude" to "Shirley Tay" in line 16, if the profile link thing won't work.

Blackswan said... [reply]

Thks again! Slow loading to your blog & the code doesn't load even when I clicked on Download Raw. Will come back later to get the code later & try installing :)

Blackswan said... [reply]

Hey, the first method didn't work but the 2nd one works like magic. Chk it out! Thks so much! How can I exclude 2 names? Tried putting punctuation but didn't work. Lol! Pls advise! You've been a great help!

MS-potilas said... [reply]

@Shirley Tay

Hi, good you got it working. For more exclusions, try changing the line to this:

var excludeUsers = ["Anonymous", "Shirley Tay", "OtherName"];

(change OtherName to the username you want). If you want still one more, then it looks like this:

var excludeUsers = ["Anonymous", "Shirley Tay", "OtherName", "StillOtherName"];

etc. :)

Blackswan said... [reply]

Thks a million! It's working :) U're a genius! Actually, I've been directed by Aratina Cage's blog at Last Comments. I was searching for solution to the Recent Comments which I've installed previously. It worked fine until lately, my comments are showing. Wonder if you can help? I only want to show visitors comments but not mine. Thks again!

MS-potilas said... [reply]

@Shirley Tay Hi, I did a hack for my recent comments hack, maybe this is what you're after: Hack for my recent comments hack: don't show own comments. :)

Hiyacynthia said... [reply]

I just installed this and I think mine needs some tweaking because I have no avatars or clickable links to my followers. Can you help?
I can be reached at for going back and forth.

MS-potilas said... [reply]

@Cindy Brown
Hi, I think the problem is with Discus commenting system, that you have on your blog. If you look at the comments feed the author uri's are missing. So the gadget sees them as non-registered, and have nowhere to link the name/avatar.

I think this could help you: Add Disqus Top Commentators Widget To Blogger Blog :)

Unknown said... [reply]

The article is very useful,Thanks for sharing.

Velarah said... [reply]

Hmm...seems not to work on my blog.

The Comments should be displayed in the "Test" gadget, which is an html/js gadget.

Even if I use your raw code, it wont show up, like the gadget isnt function correctly.

Any suggestions?
Thanks for your great work.

MS-potilas said... [reply]

Hi, when I looked your blog's html source, it seems that you have only the first 135 lines of the gadget code there, and the rest is missing.

Unknown said... [reply]


Nah, doesnt know, why copy & paste messed it up.

Thanks for your help


Streuterklamotte said... [reply]

Thank you so much... I was looking for it since several weeks, because I really like it!
Viele liebe Grüße,

Gaby Cortez said... [reply]

Hello :)
Great tip, loved it! I'm using in my blog. *-*

Unknown said... [reply]

Can anyone tell me how can i reset or update the Top commentators after month. I wan to reset Top Commentators in my Blog...
Blog URL is

Plz Help me....

MS-potilas said... [reply]

@Shiv Kumar Gupta
You can set the numDays variable:

var numDays = 30;

This way the gadget calculates top commenters only from the last 30 days, older comments are ignored.

Nanda. said... [reply]

I'm a brazilian blogger and I just came to say Thank you for create this code, it has transformed the way we can interact with our followers. :)
So that's it. I'm really glad to know that r people like u in the world.
Sorry for my bad english and thank u, one more time.
If you feel like you want you, visit my blog:
Nandalandia :D

Beatriz Ramirez said... [reply]

Hi!Brazilian here!I loved your gadget! Thank you.
♥ Blog da Mirez

Post a Comment

Related Posts Plugin for WordPress, Blogger...
See the hack
for this dynamic
views icon: