Unallow users to like/dislike their own posts 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
SLGray
Ape
jkh
mSyx
8 posters

    Unallow users to like/dislike their own posts

    mSyx
    mSyx
    Forumember


    Male Posts : 155
    Reputation : 47
    Language : French & English
    Location : France

    Unallow users to like/dislike their own posts Empty Unallow users to like/dislike their own posts

    Post by mSyx June 27th 2020, 10:00 pm

    Hey there,
    After the announcement of the new Like and Dislike system nearly a week ago, I've seen some users wishing they could unallow users to like or dislike their own posts. This quite short JS code should do the job.

    06/03 edit: Now removes only the like/dislike buttons and still shows the likes list.

    Adding the JS:

    Admin Panel » Modules » HTML & JAVASCRIPT: Javascript codes management; then, click on the CREATE A NEW JAVASCRIPT button.

    Title * : As you wish.
    Placement : In the topics
    Javascript Code:


    PHPBB2:



    PHPBB3:



    PUNBB:



    INVISION:



    MODERNBB:



    AWESOMEBB:






    Last edited by mSyx on March 6th 2021, 1:18 pm; edited 3 times in total

    YoshiGM, Nefadar, SarkZKalie, TonnyKamper, trajce, mc nabulsy and tester101 like this post

    jkh
    jkh
    Forumember


    Posts : 622
    Reputation : 17
    Language : english

    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by jkh June 27th 2020, 11:00 pm

    I've tried this code, but it didn't work for me.

    sivastar and trajce like this post

    Ape
    Ape
    Administrator
    Administrator


    Male Posts : 19168
    Reputation : 1995
    Language : fluent in dork / mumbojumbo & English haha

    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by Ape June 28th 2020, 1:31 am

    jkh wrote:I've tried this code, but it didn't work for me.

    Hello @jkh are you putting this in your JavaScript and putting all pages ?



    Unallow users to like/dislike their own posts Left1212Unallow users to like/dislike their own posts Center11Unallow users to like/dislike their own posts Right112
    Unallow users to like/dislike their own posts Ape_b110
    Unallow users to like/dislike their own posts Ape1010

    jkh likes this post

    mSyx
    mSyx
    Forumember


    Male Posts : 155
    Reputation : 47
    Language : French & English
    Location : France

    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by mSyx June 28th 2020, 1:32 am

    @jkh Hi,
    Just tried on your forum, it seems to work for me.

    Try this version ?:
    Code:
    $(function() {
    $('div.post').each(function() {
    var postauthor = $(this).find('.postprofile dl dt').children().last().text();
    var myname = _userdata.username;
     
    if (postauthor === myname) { $(this).find('.fa_like_div').remove(); }
    }); });

    jkh likes this post

    jkh
    jkh
    Forumember


    Posts : 622
    Reputation : 17
    Language : english

    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by jkh June 28th 2020, 7:21 am

    @Ape - yes I did.

    @mSyx Brilliant! That new one works much better, thank you.

    Maybe it was because I'd tried it on my test forum rather than my main forum? But it works on both now.

    How are you able to put a javascript on my forum?
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51515
    Reputation : 3519
    Language : English
    Location : United States

    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by SLGray June 28th 2020, 7:26 am

    It is not exactly placing it on your forum, but using the browser's console you can add CSS and scripts.



    Unallow users to like/dislike their own posts Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.

    mSyx likes this post

    jkh
    jkh
    Forumember


    Posts : 622
    Reputation : 17
    Language : english

    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by jkh June 28th 2020, 7:45 am

    I see thumleft 

    Actually, I don't   Unallow users to like/dislike their own posts 1f602 

    I should learn coding  Unallow users to like/dislike their own posts 1f631

    It's taken me long enough to learn html when I'm editing blogger...it's all fun, and very interesting, though.

    tikky likes this post

    mSyx
    mSyx
    Forumember


    Male Posts : 155
    Reputation : 47
    Language : French & English
    Location : France

    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by mSyx June 28th 2020, 6:27 pm

    Thread updated with each version. Once again, any feedback is welcome I love you
    tester101
    tester101
    New Member


    Posts : 1
    Reputation : 1
    Language : english

    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by tester101 August 20th 2020, 1:13 pm

    hello guys can u fix the delay is a known issue during page refresh
    we can still see the like and dislike buttons can we add the time based on during page refresh so we not see the buttons

    and it seems to have a little bug i mean u cant see who have liked or dislike your own posts ?

    @mSyx


    Last edited by tester101 on August 20th 2020, 1:16 pm; edited 1 time in total
    YoshiGM
    YoshiGM
    Active Poster


    Male Posts : 1502
    Reputation : 144
    Language : Spanish & English
    Location : Mexico

    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by YoshiGM August 20th 2020, 4:03 pm

    I've tested you code in my forum and works very good!
    Great job Bravo
    avatar
    Simone Boi
    Forumember


    Posts : 92
    Reputation : 2
    Language : Italian

    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by Simone Boi February 23rd 2021, 7:57 am

    Hi! Thank for the tutorial, I've an issue to report, but I don't know if it's my fault or not.

    I'm on ModernBB but if I use this code:

    Code:
    $(function() {
    $('div.post').each(function() {
    var postauthor = $(this).find('.postprofile .postprofile-name').children().last().text();
    var myname = _userdata.username;
     
    if (postauthor === myname) { $(this).find('.fa_like_div').remove(); }
    }); });

    Then I can't see my or others likes on my posts, so if an user gives me like i can't see that

    While if I use this:

    Code:
    $(function() {
    $('div.post').each(function() {
    var postauthor = $(this).find('.postprofile dl dt').children().last().text();
    var myname = _userdata.username;
     
    if (postauthor === myname) { $(this).find('.fa_like_div').remove(); }
    }); });

    I can see other's likes but still I can like my own posts.



    mSyx
    mSyx
    Forumember


    Male Posts : 155
    Reputation : 47
    Language : French & English
    Location : France

    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by mSyx March 6th 2021, 1:11 pm

    Sorry for the late answers.

    tester101 wrote:hello guys can u fix the delay is a known issue during page refresh
    we can still see the like and dislike buttons can we add the time based on during page refresh so we not see the buttons

    and it seems to have a little bug i mean u cant see who have liked or dislike your own posts ?

    @mSyx

    Remove the current JS in the javascript modules.
    In your viewtopic_body template, find:
    Code:
    <!-- END postrow -->

    Put the following code right after:
    Code:
    <script type="text/javascript">
    $('div.post').each(function() {
    var postauthor = $(this).find('.postprofile .postprofile-name').children().last().text();
    var myname = _userdata.username;
     
    if (postauthor === myname) { $(this).find('.fa_like_div').remove(); }
    });
    </script>

    Simone Boi wrote:Hi! Thank for the tutorial, I've an issue to report, but I don't know if it's my fault or not.

    I'm on ModernBB but if I use this code:

    Code:
    $(function() {
    $('div.post').each(function() {
    var postauthor = $(this).find('.postprofile .postprofile-name').children().last().text();
    var myname = _userdata.username;
     
    if (postauthor === myname) { $(this).find('.fa_like_div').remove(); }
    }); });

    Then I can't see my or others likes on my posts, so if an user gives me like i can't see that

    While if I use this:

    Code:
    $(function() {
    $('div.post').each(function() {
    var postauthor = $(this).find('.postprofile dl dt').children().last().text();
    var myname = _userdata.username;
     
    if (postauthor === myname) { $(this).find('.fa_like_div').remove(); }
    }); });

    I can see other's likes but still I can like my own posts.

    I can't reproduce the same thing. This may be linked to your templates modifications (if any).

    EDIT

    tester101 wrote:and it seems to have a little bug i mean u cant see who have liked or dislike your own posts ?

    True, didn't think about that. Working on it ~
    Done, codes updated in the first post

    TonnyKamper likes this post

    avatar
    Simone Boi
    Forumember


    Posts : 92
    Reputation : 2
    Language : Italian

    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by Simone Boi March 7th 2021, 7:22 am

    Thank you, now I can see likes, but I can still like my own post from mobile
    mSyx
    mSyx
    Forumember


    Male Posts : 155
    Reputation : 47
    Language : French & English
    Location : France

    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by mSyx March 7th 2021, 10:19 am

    Simone Boi wrote:Thank you, now I can see likes, but I can still like my own post from mobile

    That is because mobile & web templates are different. I'll try doing the same for the mobile version soon enough. I love you

    Simone Boi likes this post

    avatar
    Guest
    Guest


    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by Guest January 16th 2023, 12:43 am

    I would like to do an update for this tutorial. Instead of separating scripts for each version, I modified script to make only one script for all forum versions where version is selected automatically.

    Code:
    $(document).ready(function() {

        const FORUM_VERSION = _userdata["tpl_used"];

        var versions = {
            'subsilver': $('tr.post'),
            'prosilver': $('div.post'),
            'punbb': $('div.post'),
            'invision': $('div.post'),
            'modernbb': $('div.post'),
            'awesomebb': $('div.post-wrap')
        };

        var versionFind = {
            'prosilver': '.postprofile dl dt',
            'punbb': '.user-ident h4.username',
            'invision': '.postprofile .popmenubutton',
            'modernbb': '.postprofile .postprofile-name',
            'awesomebb': '.post-aside .post-author-name'
        };



        versions[FORUM_VERSION].each(function() {
            var myname = _userdata.username;

            if (FORUM_VERSION == "subsilver") {
                var postauthor = $(this).find('td').first().find('.name').children().last().text();
                if (postauthor === myname) {
                    $(this).find('.fa_like_div button').remove();
                }
                return;
            }

            var postauthor = $(this).find(versionFind[FORUM_VERSION]).children().last().text();
            if (postauthor === myname) {
                $(this).find('.fa_like_div button').remove();
            }

        });

    });


    Last edited by System32 on January 16th 2023, 10:36 am; edited 2 times in total
    brandon_g
    brandon_g
    Manager
    Manager


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

    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by brandon_g January 16th 2023, 4:49 am

    System32 wrote:I would like to do an update for this tutorial. Instead of separating scripts for each version, I modified script to make only one script for all forum versions where version is selected automatically.

    Code:
    $(document).ready(function() {

        const FORUM_VERSION = _userdata["tpl_used"];

        var versions = {
            'subsilver': $('tr.post'),
            'prosilver': $('div.post'),
            'punbb': $('div.post'),
            'invision': $('div.post'),
            'modernbb': $('div.post'),
            'awesomebb': $('div.post-wrap')
        };

        var versionFind = {
            'prosilver': '.postprofile dl dt',
            'punbb': '.user-ident h4.username',
            'invision': '.postprofile .popmenubutton',
            'modernbb': '.postprofile .postprofile-name',
            'awesomebb': '.post-aside .post-author-name'
        };



        versions[FORUM_VERSION].each(function() {
            var myname = _userdata.username;

            if (FORUM_VERSION == "subsilver") {
                var postauthor = $(this).find('td').first().find('.name').children().last().text();
                if (postauthor === myname) {
                    $(this).find('.fa_like_div button').remove();
                }
            }

            var postauthor = $(this).find(versionFind[FORUM_VERSION]).children().last().text();
            if (postauthor === myname) {
                $(this).find('.fa_like_div button').remove();
            }

        });

    });

    That is some pretty nice code there @System32, clever use of a key/value dictionary Very Happy. Have you tested this on all versions already?



    Unallow users to like/dislike their own posts Brando10
    Remember to mark your topic Unallow users to like/dislike their own posts Solved15 when a solution is found.
    General Rules | Tips & Tricks | FAQ | Forgot Founder Password?

    Unallow users to like/dislike their own posts Scre1476
    Team Leader
    Review Section Rules | Request A Review | Sticker Points
    avatar
    Guest
    Guest


    Unallow users to like/dislike their own posts Empty Re: Unallow users to like/dislike their own posts

    Post by Guest January 16th 2023, 10:13 am

    Yes, I have. Razz
    And thanks. I always use that to adapt script for all versions Wink

    Script edited. I added return statement for phpBB2. Missed it.