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.
The forum of the forums
5 posters

    Avatar problem in recent topic

    Mineko
    Mineko
    Forumember


    Female Posts : 57
    Reputation : 1
    Language : Hungarian
    Location : Hungary

    Solved Avatar problem in recent topic

    Post by Mineko October 29th 2020, 10:14 pm

    Hello ^^
    And again I... xD
    So, I have a question, I would have trouble from here I used the code. However, I want the avatar set by the users to appear, not the default.
    Version: phpbb2
    Link: https://blackmoonfrpg.hungarianforum.com
    I hope you can help again. Smile
    Thank you ^^
    SarkZKalie
    SarkZKalie
    Support Moderator
    Support Moderator


    Male Posts : 1442
    Reputation : 220
    Language : English

    Solved Re: Avatar problem in recent topic

    Post by SarkZKalie October 30th 2020, 8:07 am

    Could you please explain further? Smile



    Avatar problem in recent topic Sarkzk10
    skouliki
    skouliki
    Manager
    Manager


    Female Posts : 15321
    Reputation : 1705
    Language : English,Greek
    Location : Greece

    Solved Re: Avatar problem in recent topic

    Post by skouliki October 30th 2020, 8:13 am

    hello

    you must set on the code your own default image avatar
    this default avatar will appear only to the member that don't have an avatar

    tikky
    tikky
    Forumember


    Posts : 922
    Reputation : 159
    Language : 🇵🇹

    Solved Re: Avatar problem in recent topic

    Post by tikky October 30th 2020, 10:46 am

    Hello @Mineko,

    Change your code to:
    Code:
    $(function(){
      var style = document.createElement('STYLE'), css = '.mini_ava2>img{height:20px;margin-right:5px;width:20px;}';
      style.type = 'text/css';
      if (style.styleSheet) style.styleSheet.cssText = css;
      else style.appendChild(document.createTextNode(css));
      document.getElementsByTagName('HEAD')[0].appendChild(style);
       
          if(!window.localStorage) return;
       
          // Default avatar
            var default_avatar= 'https://2img.net/i/fa/invision/pp-blank-thumb.png';
       
          // Time of cache 24h*60m*60s*1000ms - one day
            var caching_time= 24*60*60*1000;
       
          // Time of cache in case of error 60s*1000ms - one minute
            var caching_error= 60*1000;
       
          var set_avatar= function(id) {
                $('.mini_ava2.member'+id).html('<img src="'+get_avatar(id)+'" />');
            };
       
          var get_avatar= function(id) {
                if(localStorage.getItem('t_ava'+id) < +new Date - caching_time || (localStorage.getItem('d_ava'+id)==default_avatar && localStorage.getItem('t_ava'+id) < +new Date - caching_error))
                {
                    localStorage.setItem('d_ava'+id, default_avatar);
                    $.get('/u'+id, function (d){
                        localStorage.setItem('t_ava'+id,+new Date);
                        localStorage.setItem('d_ava'+id, $('.avPFIL img, #profile-advanced-right .module:first div img:first,.forumline td.row1.gensmall:first > img, .frm-set.profile-view.left dd img,dl.left-box.details:first dd img, .row1 b .gen:first img, .real_avatar img',d).first().attr('src')||default_avatar);
                        set_avatar(id);
                    });
                }
                return localStorage.getItem('d_ava'+id);
            };
       
          var to_replace= {};
       
          $('#recentTopics a[href^="/u"]').each(function(){
                to_replace[$(this).attr('href').substr(2)]= 1;
                $(this).before('<span class="mini_ava2 member'+$(this).attr('href').substr(2)+'"></span>');
            });
       
          for(i in to_replace)
            {
                set_avatar(i);
            };
       
      });
    Mineko
    Mineko
    Forumember


    Female Posts : 57
    Reputation : 1
    Language : Hungarian
    Location : Hungary

    Solved Re: Avatar problem in recent topic

    Post by Mineko October 30th 2020, 12:06 pm

    Thank you very much @pedxz! <3

    Solved ^^

    tikky likes this post

    brandon_g
    brandon_g
    Manager
    Manager


    Male Posts : 10113
    Reputation : 923
    Language : English
    Location : USA

    Solved Re: Avatar problem in recent topic

    Post by brandon_g October 30th 2020, 1:09 pm

    Problem solved & topic archived.
    Please read our forum rules: ESF General Rules



    Avatar problem in recent topic Brando10
    Remember to mark your topic Avatar problem in recent topic Solved15 when a solution is found.
    General Rules | Tips & Tricks | FAQ | Forgot Founder Password?

    Avatar problem in recent topic Scre1476
    Team Leader
    Review Section Rules | Request A Review | Sticker Points

      Current date/time is September 23rd 2024, 6:20 pm