Como colocar widget top comentaristas no blogger

Uma boa maneira de tornar o nosso Website mais agradável é com comentários, os comentários ao nosso blog podem dar-nos muitas vantagens para a sua evolução e também são uma marca de confiança para os novos visitantes que entrem dia após dia no nosso blog.
Muitas das pessoas que passam no nosso blog, apenas lêem a informação e vão-se embora, pois o que eles ganham em comentar? A maioria absolutamente nada. Mas já pensaram em colocar um Widget dos melhores comentadores do blog?
É uma óptima maneira de incentivar todos os visitantes e comentar e a participar no vosso blog, pois assim eles ficaram na nossa barra lateral com um link apontando para os seus blogs.
Podem ver o exemplo do Widget Top Comentaristas na imagem abaixo:
widget_thumb
Implementação: A implementação desta “aplicação” para o blogger é relativamente fácil, para o colocares basta:
    1. Entra no blogger
    2. Clica em modelo
    3. Clica em adicionar uma mini-aplicação
    4. Escolhe um HTML/JavaScript
    5. Cola nele o código abaixo, sem efetuar nenhuma alteração:

</ol>
<blockquote><span><span> </span></span>

<style type=”text/css”><!–
</span></span><span><span>.top-commenter-line     {margin: 3px 0;}</span></span><span><span>.top-commenter-avatar   {vertical-align:middle;}</span></span><span><span>
–></style>&nbsp; <span><span><script type=”text/javascript”>// <![CDATA[ </span></span><span><span>//</span></span><span><span>// Top Commentators gadget with avatars, by MS-potilas 2012.</span></span><span><span>// Gets a list of top commentators from all comments, or specified number of days in the past.</span></span><span><span>// See http://yabtb.blogspot.com/2012/05/top-commenters-gadget-with-avatars.html</span></span><span><span>//</span></span><span><span>// CONFIG:</span></span><span><span>var maxTopCommenters = 5;   // how big a list of top commentators</span></span><span><span>var minComments = 1;        // how many comments must top commentator have at least</span></span><span><span>var numDays = 0;            // from how many days (ex. 30), or 0 from “all the time”</span></span><span><span>var excludeMe = true;       // true: exclude my own comments</span></span><span><span>var excludeUsers = [“Anonymous”, “someotherusertoexclude”];     // exclude these usernames</span></span><span><span>var maxUserNameLength = 42; // 0: don’t cut, >4: cut usernames</span></span><span><span>//</span></span><span><span>var txtTopLine = ‘<b>[#].</b> [image] [user] ([count])’;</span></span><span><span>var txtNoTopCommenters = ‘No top commentators at this time.’;</span></span><span><span>var txtAnonymous = ”;      // empty, or Anonymous user name localized if you want to localize</span></span><span><span>//</span></span><span><span>var sizeAvatar = 16;</span></span><span><span>var cropAvatar = true;</span></span><span><span>//</span></span><span><span>var urlNoAvatar = “http://lh4.googleusercontent.com/-069mnq7DV_g/TvgRrBI_JaI/AAAAAAAAAic/Iot55vywnYw/s”+sizeAvatar+”/avatar_blue_m_96.png”; // http://www.blogger.com/img/avatar_blue_m_96.png resizeable</span></span><span><span>var urlAnoAvatar = ‘http://www.gravatar.com/avatar/00000000000000000000000000000000?d=mm&#038;s=’ + sizeAvatar;</span></span><span><span>var urlMyProfile = ”; // set if you have no profile gadget on page</span></span><span><span>var urlMyAvatar = ”;  // can be empty (then it is fetched) or url to image</span></span><span><span>// config end</span></span><span><span>// for old IEs &#038; IE modes:</span></span><span><span>if(!Array.indexOf) {</span></span><span><span>Array.prototype.indexOf=function(obj) {</span></span><span><span>  for(var i=0;i

<this.length;i++) if(this[i]==obj) return i;</span>
</span><span><span>  return -1;</span></span><span><span>}}</span></span><span><span>function replaceTopCmtVars(text, item, position)</span></span><span><span>{</span></span><span><span>  if(!item || !item.author) return text;</span></span><span><span>  var author = item.author;</span></span><span>
</span><span><span>  var authorUri = “”;</span></span><span><span>  if(author.uri &#038;& author.uri.$t != “”)</span></span><span><span>    authorUri = author.uri.$t;</span></span><span>
</span><span><span>  var avaimg = urlAnoAvatar;</span></span><span><span>  var bloggerprofile = “http://www.blogger.com/profile/”;</span></span><span><span>  if(author.gd$image &#038;& author.gd$image.src &#038;& authorUri.substr(0,bloggerprofile.length) == bloggerprofile)</span></span><span><span>    avaimg = author.gd$image.src;</span></span><span><span>  else {</span></span><span><span>    var parseurl = document.createElement(‘a’);</span></span><span><span>    if(authorUri != “”) {</span></span><span><span>      parseurl.href = authorUri;</span></span><span><span>      avaimg = ‘http://www.google.com/s2/favicons?domain=’ + parseurl.hostname;</span></span><span><span>    }</span></span><span><span>  }</span></span><span><span>  if(urlMyProfile != “” &#038;& authorUri == urlMyProfile &#038;& urlMyAvatar != “”)</span></span><span><span>    avaimg = urlMyAvatar;</span></span><span><span>  if(avaimg == “http://img2.blogblog.com/img/b16-rounded.gif” &#038;& urlNoAvatar != “”)</span></span><span><span>    avaimg = urlNoAvatar;</span></span><span><span>  var newsize=”s”+sizeAvatar;</span></span><span><span>  avaimg = avaimg.replace(/\/s\d\d+-c\//, “/”+newsize+”-c/”);</span></span><span><span>  if(cropAvatar) newsize+=”-c”;</span></span><span><span>  avaimg = avaimg.replace(/\/s\d\d+(-c){0,1}\//, “/”+newsize+”/”);</span></span><span>
</span><span><span>  var authorName = author.name.$t;</span></span><span><span>  if(authorName == ‘Anonymous’ &#038;& txtAnonymous != ” &#038;& avaimg == urlAnoAvatar)</span></span><span><span>    authorName = txtAnonymous;</span></span><span><span>  var imgcode = ‘<img height=”‘+sizeAvatar+'” width=”‘+sizeAvatar+'” title=”‘+authorName+'” src=”‘+avaimg+'” />’;</span></span><span><span>  if(authorUri!=””) imgcode = ‘<a href=”‘+authorUri+'”>’+imgcode+'</a>’;</span></span><span>
</span><span><span>  if(maxUserNameLength > 3 &#038;& authorName.length > maxUserNameLength)</span></span><span><span>    authorName = authorName.substr(0, maxUserNameLength-3) + “…”;</span></span><span><span>  var authorcode = authorName;</span></span><span><span>  if(authorUri!=””) authorcode = ‘<a href=”‘+authorUri+'”>’+authorcode+'</a>’;</span></span><span>
</span><span><span>  text = text.replace(‘[user]’, authorcode);</span></span><span><span>  text = text.replace(‘[image]’, imgcode);</span></span><span><span>  text = text.replace(‘[#]’, position);</span></span><span><span>  text = text.replace(‘[count]’, item.count);</span></span><span><span>  return text;</span></span><span><span>}</span></span><span>
</span><span><span>var topcommenters = {};</span></span><span><span>var ndxbase = 1;</span></span><span><span>function showTopCommenters(json) {</span></span><span><span>  var one_day=1000*60*60*24;</span></span><span><span>  var today = new Date();</span></span><span>
</span><span><span>  if(urlMyProfile == “”) {</span></span><span><span>    var elements = document.getElementsByTagName(“*”);</span></span><span><span>    var expr = /(^| )profile-link( |$)/;</span></span><span><span>    for(var i=0 ; i<elements.length ; i++)</span></span><span><span>      if(expr.test(elements[i].className)) {</span></span><span><span>        urlMyProfile = elements[i].href;</span></span><span><span>        break;</span></span><span><span>      }</span></span><span><span>  }</span></span><span>
</span><span><span>  for(var i = 0 ; i < json.feed.entry.length ; i++ ) {</span></span><span><span>    var entry = json.feed.entry[i];</span></span><span><span>    if(numDays > 0) {</span></span><span><span>      var datePart = entry.published.$t.match(/\d+/g); // assume ISO 8601</span></span><span><span>      var cmtDate = new Date(datePart[0],datePart[1]-1,datePart[2],datePart[3],datePart[4],datePart[5]);</span></span><span>
</span><span><span>      //Calculate difference btw the two dates, and convert to days</span></span><span><span>      var days = Math.ceil((today.getTime()-cmtDate.getTime())/(one_day));</span></span><span><span>      if(days > numDays) break;</span></span><span><span>    }</span></span><span><span>    var authorUri = “”;</span></span><span><span>    if(entry.author[0].uri &#038;& entry.author[0].uri.$t != “”)</span></span><span><span>      authorUri = entry.author[0].uri.$t;</span></span><span>
</span><span><span>    if(excludeMe &#038;& authorUri != “” &#038;& authorUri == urlMyProfile)</span></span><span><span>      continue;</span></span><span><span>    var authorName = entry.author[0].name.$t;</span></span><span><span>    if(excludeUsers.indexOf(authorName) != -1)</span></span><span><span>      continue;</span></span><span>
</span><span><span>    var hash=entry.author[0].name.$t + “-” + authorUri;</span></span><span><span>    if(topcommenters[hash])</span></span><span><span>      topcommenters[hash].count++;</span></span><span><span>    else {</span></span><span><span>      var commenter = new Object();</span></span><span><span>      commenter.author = entry.author[0];</span></span><span><span>      commenter.count = 1;</span></span><span><span>      topcommenters[hash] = commenter;</span></span><span><span>    }</span></span><span><span>  }</span></span><span><span>  if(json.feed.entry.length == 200) {</span></span><span><span>    ndxbase += 200;</span></span><span><span>    document.write(‘<script type=”text/javascript” src=”http://’+window.location.hostname+’/feeds/comments/default?redirect=false&#038;max-results=200&#038;start-index=’+ndxbase+’&#038;alt=json-in-script&#038;callback=showTopCommenters”></’+’script>’);</span></span><span><span>    return;</span></span><span><span>  }</span></span><span>
</span><span><span>  // convert object to array of tuples</span></span><span><span>  var tuplear = [];</span></span><span><span>  for(var key in topcommenters) tuplear.push([key, topcommenters[key]]);</span></span><span>
</span><span><span>  tuplear.sort(function(a, b) {</span></span><span><span>    if(b[1].count-a[1].count)</span></span><span><span>        return b[1].count-a[1].count;</span></span><span><span>    return (a[1].author.name.$t.toLowerCase() < b[1].author.name.$t.toLowerCase()) ? -1 : 1;</span></span><span><span>  });</span></span><span>
</span><span><span>  // list top topcommenters:</span></span><span><span>  var realcount = 0;</span></span><span><span>  for(var i = 0; i < maxTopCommenters &#038;& i < tuplear.length ; i++) {</span></span><span><span>    var item = tuplear[i][1];</span></span><span><span>    if(item.count < minComments)</span></span><span><span>        break;</span></span><span><span>    document.write(‘<di’+’v class=”top-commenter-line”>’);</span></span><span><span>    document.write(replaceTopCmtVars(txtTopLine, item, realcount+1));</span></span><span><span>    document.write(‘</d’+’iv>’);</span></span><span><span>    realcount++;</span></span><span><span>  }</span></span><span><span>  if(!realcount)</span></span><span><span>    document.write(txtNoTopCommenters);</span></span><span><span>}  </span></span><span><span>document.write(‘<script type=”text/javascript” src=”http://’+window.location.hostname+’/feeds/comments/default?redirect=false&#038;max-results=200&#038;alt=json-in-script&#038;callback=showTopCommenters”></’+’script>’);</span></span><span><span>
// ]]></script></span></span></blockquote>

 

Agora basta guardar e arrastar a “caixa” do Widget para a sua barra lateral!

Qualquer dúvida ou opinião, não hesite em comentar!


One Response

  1. Donetzka 2 de Dezembro de 2016

Adicionar Comentário