[Plugin] Popular post Hitskin_logo Hitskin.com

This is a Hitskin.com skin preview
Install the skinReturn to the skin page

The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.
4 posters

    [Plugin] Popular post

    Daemon
    Daemon
    Forumember


    Posts : 104
    Reputation : 91
    Language : Português

    [Plugin] Popular post Empty [Plugin] Popular post

    Post by Daemon July 13th 2015, 8:20 pm

    Introduction:
    This plugin will serve to make a special post "popular", according to the number of votes.

    Below is the code that should be added with placement in topics:
    Code:
    /*
     *  Application: Popular post
     *  Date: 14/07/2015
     *  Version: 1.323072017
     *  Copyright (c) 2017 Daemon <help.forumotion.com>
     *  This work is free. You can redistribute it and/or modify it
     */
    $(function() {

    var qtd = 5; // Number of votes for the post to become popular

    $("head").append(
    '<style type="text/css">' +
    '.popular_post {' +
    ' background: #D5DEE5;' +
    ' border-radius: 5px 5px 5px 5px;' +
    ' color: #1D3652;' +
    ' float: right;' +
    ' font-size: 0.8em;' +
    ' font-weight: bold;' +
    ' margin: 5px 10px 10px;' +
    ' padding: 5px;' +
    ' text-align: center;' +
    '}' +
    '.popular_post img {' +
    ' max-width: 20px;' +
    '}' +
    '</style>'
    );

    var x = $(".vote");
    var popular = "<p class='popular_post'><img src='http://imgur.com/hds8Nup.png'><br>POPULAR</p>";
    var value, votebar, numbar;
    for(var i = 0, l = x.length; i < l; i++) {
        var v = x[i];
        value = 0;
        votebar = $(".vote-bar", v)[0];
        if(votebar) {
            numbar = votebar.title.match(/\d+/g);
            value = Math.round(parseInt(numbar[1]) * parseInt(numbar[0])) / 100;
        }
        if(value >= qtd) {
            v.insertAdjacentHTML("afterbegin", popular);
        }
    }
    });

    Result:
    [Plugin] Popular post EdQFHGs


    Last edited by Daemon on July 23rd 2017, 7:21 pm; edited 3 times in total
    JScript
    JScript
    Forumember


    Male Posts : 741
    Reputation : 175
    Language : PT-BR, EN
    Location : Brazil

    [Plugin] Popular post Empty Re: [Plugin] Popular post

    Post by JScript July 14th 2015, 12:52 am

    @Daemon
    hummm, I had already made a similar to my old forum, you remember?

    However your code is pretty clean!

    5* from me,

    JS
    Van-Helsing
    Van-Helsing
    Hyperactive


    Male Posts : 2431
    Reputation : 116
    Language : English, Greek

    [Plugin] Popular post Empty Re: [Plugin] Popular post

    Post by Van-Helsing July 14th 2015, 6:24 pm

    Hello,
    I installed it on my forum but it is not working Sad Is LGLike affecting it?
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13246
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    [Plugin] Popular post Empty Re: [Plugin] Popular post

    Post by Ange Tuteur July 14th 2015, 6:36 pm

    Black-Shadow wrote:Hello,
    I installed it on my forum but it is not working Sad Is LGLike affecting it?
    That would most likely be the case as LG's like system removes the default reputation system. Bars and buttons included. Wink
    Van-Helsing
    Van-Helsing
    Hyperactive


    Male Posts : 2431
    Reputation : 116
    Language : English, Greek

    [Plugin] Popular post Empty Re: [Plugin] Popular post

    Post by Van-Helsing July 14th 2015, 6:40 pm

    Hello @Ange Tuteur,
    Yes it is affecting it. I disabled temporary the LGLike and enabled this code and it is working.
    Is there a way to adapt it to work with LGLike?
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13246
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    [Plugin] Popular post Empty Re: [Plugin] Popular post

    Post by Ange Tuteur July 14th 2015, 6:42 pm

    Black-Shadow wrote:Hello @Ange Tuteur,
    Yes it is affecting it. I disabled temporary the LGLike and enabled this code and it is working.
    Is there a way to adapt it to work with LGLike?
    You could contact him to replace remove() with hide(), although I highly doubt he will, or you can host his source elsewhere and modify it to work with your forum.

    EDIT :
    This almost slipped my mind, but you could also try to execute LG's like system later.
    Daemon
    Daemon
    Forumember


    Posts : 104
    Reputation : 91
    Language : Português

    [Plugin] Popular post Empty Re: [Plugin] Popular post

    Post by Daemon July 14th 2015, 7:02 pm

    The code has been updated!
    I realized that the code had a small error of interpretation in finding the correct value of positive votes.
    Van-Helsing
    Van-Helsing
    Hyperactive


    Male Posts : 2431
    Reputation : 116
    Language : English, Greek

    [Plugin] Popular post Empty Re: [Plugin] Popular post

    Post by Van-Helsing July 16th 2015, 2:01 pm

    I tried it on a test forum without LGLike but it is displaying only voting green bar. Sad

    I tried the @Daemon 's IPB Voting script

    Code:

    /*
        * Codigo: IPB Like System.
        * Data de criacao: 18/07/2014.
        * Atualizacao: 18/11/2014.
        * Autor: Daemon.
        * Versao: 1.1.
        * Inspirado: IPB.
        * Acesse: http://bestskins.net.
        * Nao distribuir, ou remover os creditos do autor.
        */
        function bestskins_ls() {
           for(var x = $('.vote'), i = 0, vote; (vote = x[i++]); ) {
                        var count = 0,
                              qtd = 0,
                              barra = $('.vote-bar', vote)[0],
                              botao = $('.vote-button', vote)[0];                     
                        if (barra) {
                                var numbarra = barra.title.match(/\d+/g);
                                qtd = Math.round(parseInt( numbarra[1] ) * parseInt( numbarra[0] )) / 100;
                        }
                      
                        //Imagem de reputacao
                        var reputation_UP = 'http://i.imgur.com/PTraX1a.png';
        
                        botao = botao ? '<li><span onclick="bestskinsVoto(\'' + botao.firstChild.href + '\',this);" class="BS_like"><img src="' + reputation_UP + '" alt="+" class="rep_up"></span></li>' : '<li style="display: none;"><img src="' + reputation_UP + '" alt="+" class="rep_up"></li>';
                        var numrep = '<li>' + (qtd == 0 ? '<span class="reput_vote zero">' + qtd + '</span>' : '<span class="reput_vote positive">' + qtd + '</span>') + '</li>';
                        var htmlFinal =
                        '<div class="rep_bar clearfix" id="rep_post">' +
                        '       <ul class="bs_inline">' + botao + numrep  + '</ul>' +
                        '</div>';
             $('.postfoot', vote.parentNode.parentNode.parentNode.parentNode).before( htmlFinal );
           }
           x.remove();
        };
        function bestskinsVoto(b,a) {
          a.onclick = '#';
            $.get(b, function() {
             a.parentNode.style.display = 'none';
             var verify = a.parentNode.nextSibling.firstChild.innerHTML;
             if(verify == 0) {
             a.parentNode.nextSibling.firstChild.classList.remove('zero'),
             a.parentNode.nextSibling.firstChild.classList.add('positive');
             }
             var c = a.parentNode.nextSibling.firstChild, b = parseInt(/\d+/.exec(c.innerHTML)[0])+1;
             c.innerHTML = c.innerHTML.replace(/\d+/,b);
            });
        };
        if (document.readyState ===  'complete') {
                 bestskins_ls();
        } else {
               document.addEventListener('DOMContentLoaded', function() {
                 bestskins_ls();
               });
        }
    but it conflicts most popular javascript.
    Daemon
    Daemon
    Forumember


    Posts : 104
    Reputation : 91
    Language : Português

    [Plugin] Popular post Empty Re: [Plugin] Popular post

    Post by Daemon July 17th 2015, 4:49 am

    Black-Shadow wrote:I tried it on a test forum without LGLike but it is displaying only voting green bar. Sad

    I tried the @Daemon 's IPB Voting script

    Code:

    /*
        * Codigo: IPB Like System.
        * Data de criacao: 18/07/2014.
        * Atualizacao: 18/11/2014.
        * Autor: Daemon.
        * Versao: 1.1.
        * Inspirado: IPB.
        * Acesse: http://bestskins.net.
        * Nao distribuir, ou remover os creditos do autor.
        */
        function bestskins_ls() {
           for(var x = $('.vote'), i = 0, vote; (vote = x[i++]); ) {
                        var count = 0,
                              qtd = 0,
                              barra = $('.vote-bar', vote)[0],
                              botao = $('.vote-button', vote)[0];                     
                        if (barra) {
                                var numbarra = barra.title.match(/\d+/g);
                                qtd = Math.round(parseInt( numbarra[1] ) * parseInt( numbarra[0] )) / 100;
                        }
                      
                        //Imagem de reputacao
                        var reputation_UP = 'http://i.imgur.com/PTraX1a.png';
        
                        botao = botao ? '<li><span onclick="bestskinsVoto(\'' + botao.firstChild.href + '\',this);" class="BS_like"><img src="' + reputation_UP + '" alt="+" class="rep_up"></span></li>' : '<li style="display: none;"><img src="' + reputation_UP + '" alt="+" class="rep_up"></li>';
                        var numrep = '<li>' + (qtd == 0 ? '<span class="reput_vote zero">' + qtd + '</span>' : '<span class="reput_vote positive">' + qtd + '</span>') + '</li>';
                        var htmlFinal =
                        '<div class="rep_bar clearfix" id="rep_post">' +
                        '       <ul class="bs_inline">' + botao + numrep  + '</ul>' +
                        '</div>';
             $('.postfoot', vote.parentNode.parentNode.parentNode.parentNode).before( htmlFinal );
           }
           x.remove();
        };
        function bestskinsVoto(b,a) {
          a.onclick = '#';
            $.get(b, function() {
             a.parentNode.style.display = 'none';
             var verify = a.parentNode.nextSibling.firstChild.innerHTML;
             if(verify == 0) {
             a.parentNode.nextSibling.firstChild.classList.remove('zero'),
             a.parentNode.nextSibling.firstChild.classList.add('positive');
             }
             var c = a.parentNode.nextSibling.firstChild, b = parseInt(/\d+/.exec(c.innerHTML)[0])+1;
             c.innerHTML = c.innerHTML.replace(/\d+/,b);
            });
        };
        if (document.readyState ===  'complete') {
                 bestskins_ls();
        } else {
               document.addEventListener('DOMContentLoaded', function() {
                 bestskins_ls();
               });
        }
    but it conflicts most popular javascript.
    Try that:
    Code:
    function bestskins_ls() {
      $('head').append(
      '<style type="text/css">' +
      '.popular_post {' +
      ' background: #D5DEE5;' +
      ' border-radius: 5px 5px 5px 5px;' +
      ' color: #1D3652;' +
      ' float: right;' +
      ' font-size: 0.8em;' +
      ' font-weight: bold;' +
      ' margin: 5px 10px 10px;' +
      ' padding: 5px;' +
      ' text-align: center;' +
      '}' +
      '.popular_post img {' +
      ' max-width: 20px;' +
      '}' +
      '</style>'
      );
      // Imagem de reputação
      var reput_UP = 'http://i.imgur.com/PTraX1a.png',
          qtd = 5; // Number of votes for the post to become popular   
     
      for(var x = $('.vote'), i = 0, vote; (vote = x[i++]); ) {
                    var val = 0,
                        barra = $('.vote-bar', vote)[0],
                        botao = $('.vote-button', vote)[0];                     
                    if (barra) {
                        var numbarra = barra.title.match(/\d+/g);
                        val = Math.round(parseInt( numbarra[1] ) * parseInt( numbarra[0] )) / 100;
                    }
                    if(val >= qtd) {
                      var pop = '<p class="popular_post"><img src="http://imgur.com/hds8Nup.png"><br>POPULAR</p>';
                      barra.parentNode.insertAdjacentHTML('beforebegin', pop);
                    }
                    botao = botao ? '<li><span onclick="bestskinsPlus(\'' + botao.firstChild.href + '\',this);" class="BS_like"><img src="' + reput_UP + '" alt="+" class="rep_up"></span></li>' : '<li style="display: none;"><img src="' + reput_UP + '" alt="+" class="rep_up"></li>';
                    var numrep = '<li>' + (val == 0 ? '<span class="reput_vote zero">' + val + '</span>' : '<span class="reput_vote positive">' + val + '</span>') + '</li>';
                    var htmlFinal =
                    '<div class="rep_bar clearfix" id="rep_post">' +
                    '      <ul class="bs_inline">' + botao + numrep  + '</ul>' +
                    '</div>';

        $('.postfoot', vote.parentNode.parentNode.parentNode.parentNode).before( htmlFinal );
      }
      x.remove();
    };
    function bestskinsPlus(b,a) {
      a.onclick = '#';
        $.get(b, function() {
        a.parentNode.style.display = 'none';
        var verify = a.parentNode.nextSibling.firstChild.innerHTML;
        if(verify == 0) {
        a.parentNode.nextSibling.firstChild.classList.remove('zero'),
        a.parentNode.nextSibling.firstChild.classList.add('positive');
        }
        var c = a.parentNode.nextSibling.firstChild, b = parseInt(/\d+/.exec(c.innerHTML)[0])+1;
        c.innerHTML = c.innerHTML.replace(/\d+/,b);
        });
    };
    if (document.readyState === 'complete') {
            bestskins_ls();
    } else {
          document.addEventListener('DOMContentLoaded', function() {
            bestskins_ls();
          });
    }
    Wink


    Last edited by Daemon on July 17th 2015, 1:35 pm; edited 1 time in total
    Van-Helsing
    Van-Helsing
    Hyperactive


    Male Posts : 2431
    Reputation : 116
    Language : English, Greek

    [Plugin] Popular post Empty Re: [Plugin] Popular post

    Post by Van-Helsing July 17th 2015, 11:26 am

    Hello @Daemon,
    Now seems ok, you combined two javascripts into one Smile
    Great job
    ~1~
    Thank you.
    Daemon
    Daemon
    Forumember


    Posts : 104
    Reputation : 91
    Language : Português

    [Plugin] Popular post Empty Re: [Plugin] Popular post

    Post by Daemon July 23rd 2017, 7:22 pm

    Updated! ^^