Unallow users to like/dislike their own posts
+4
SLGray
Ape
jkh
mSyx
8 posters
Page 1 of 1
Unallow users to like/dislike their own posts
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.
Title * : As you wish.
Placement : In the topics
Javascript Code:
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:
- Code:
$(function() {
$('tr.post').each(function() {
var postauthor = $(this).find('td').first().find('.name').children().last().text();
var myname = _userdata.username;
if (postauthor === myname) { $(this).find('.fa_like_div button').remove(); }
}); });
- PHPBB3:
- 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 button').remove(); }
}); });
- PUNBB:
- Code:
$(function() {
$('div.post').each(function() {
var postauthor = $(this).find('.user-ident h4.username').children().last().text();
var myname = _userdata.username;
if (postauthor === myname) { $(this).find('.fa_like_div button').remove(); }
}); });
- INVISION:
- Code:
$(function() {
$('div.post').each(function() {
var postauthor = $(this).find('.postprofile .popmenubutton').children().last().text();
var myname = _userdata.username;
if (postauthor === myname) { $(this).find('.fa_like_div button').remove(); }
}); });
- MODERNBB:
- 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 button').remove(); }
}); });
- AWESOMEBB:
- Code:
$(function() {
$('div.post-wrap').each(function() {
var postauthor = $(this).find('.post-aside .post-author-name').children().last().text();
var myname = _userdata.username;
if (postauthor === myname) { $(this).find('.fa_like_div button').remove(); }
}); });
Last edited by mSyx on Sat 6 Mar 2021 - 13:18; edited 3 times in total
YoshiGM, Nefadar, SarkZKalie, TonnyKamper, trajce, mc nabulsy and tester101 like this post
Re: Unallow users to like/dislike their own posts
I've tried this code, but it didn't work for me.
sivastar and trajce like this post
Re: Unallow users to like/dislike their own posts
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 ?
jkh likes this post
Re: Unallow users to like/dislike their own posts
@jkh Hi,
Just tried on your forum, it seems to work for me.
Try this version ?:
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
Re: Unallow users to like/dislike their own posts
It is not exactly placing it on your forum, but using the browser's console you can add CSS and scripts.
Lost Founder's Password |Forum's Utilities |Report a Forum |General Rules |FAQ |Tricks & Tips
You need one post to send a PM.
You need one post to send a PM.
When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
mSyx likes this post
Re: Unallow users to like/dislike their own posts
I see
Actually, I don't
I should learn coding
It's taken me long enough to learn html when I'm editing blogger...it's all fun, and very interesting, though.
Actually, I don't
I should learn coding
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
Re: Unallow users to like/dislike their own posts
Thread updated with each version. Once again, any feedback is welcome
Re: Unallow users to like/dislike their own posts
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
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 Thu 20 Aug 2020 - 13:16; edited 1 time in total
Re: Unallow users to like/dislike their own posts
I've tested you code in my forum and works very good!
Great job
Great job
Re: Unallow users to like/dislike their own posts
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:
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:
I can see other's likes but still I can like my own posts.
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.
Re: Unallow users to like/dislike their own posts
Sorry for the late answers.
Remove the current JS in the javascript modules.
In your viewtopic_body template, find:
Put the following code right after:
I can't reproduce the same thing. This may be linked to your templates modifications (if any).
EDIT
True, didn't think about that. Working on it ~
Done, codes updated in the first post
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 ?
Done, codes updated in the first post
TonnyKamper likes this post
Re: Unallow users to like/dislike their own posts
Thank you, now I can see likes, but I can still like my own post from mobile
Re: Unallow users to like/dislike their own posts
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.
Simone Boi likes this post
Re: Unallow users to like/dislike their own posts
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 Mon 16 Jan 2023 - 10:36; edited 2 times in total
Guest- Guest
Re: Unallow users to like/dislike their own posts
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 . Have you tested this on all versions already?
Remember to mark your topic when a solution is found.
General Rules | Tips & Tricks | FAQ | Forgot Founder Password?
Team Leader
Review Section Rules | Request A Review | Sticker Points
Re: Unallow users to like/dislike their own posts
Yes, I have.
And thanks. I always use that to adapt script for all versions
Script edited. I added return statement for phpBB2. Missed it.
And thanks. I always use that to adapt script for all versions
Script edited. I added return statement for phpBB2. Missed it.
Guest- Guest
Similar topics
» posts and users gone
» Tag users in posts?
» Users can not edit their own posts
» Users able to delete own posts ??
» Can users use html in posts?
» Tag users in posts?
» Users can not edit their own posts
» Users able to delete own posts ??
» Can users use html in posts?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum