Hidden messages visible for Administrators only
3 posters
Page 1 of 1
Hidden messages visible for Administrators only
Hello, I have the code below (written by pedxz)
Now I want to add a button 'unhide this post' for the hidden post (based on the button 'hide this post'), after click it the post will be common visibility.
And modify 'opacity: 0.5' to 'display: none' (but visible for admin)
Can you help me ?
Thanks for reading!
Now I want to add a button 'unhide this post' for the hidden post (based on the button 'hide this post'), after click it the post will be common visibility.
And modify 'opacity: 0.5' to 'display: none' (but visible for admin)
- Code:
(function($) {
'use strict';
$(function() {
if (! /^\/t(\d+)(p\d+-|-).*$/i.test(location.pathname)) {
return;
}
$('.post').each(function() {
var $post = $(this);
var config = {
link: $post.find('a[href^="/post?p="][href$="&mode=editpost"]'),
message: (_userdata.user_level ? $post.find('a[href^="/post?p="][href$="&mode=editpost"]').attr('href').split('p=')[1].split('&')[0] : $post.attr('class').split('--')[1]),
title: $post.find('.post-head a[href^="/t"]'),
content: $post.find('.postbody > .content').html()
};
if (/> only_admin/.test(config.title.text())) {
config.title
.html('This post is <b>only visible for moderation</b>.')
;
$post
.attr('id', 'only_admin-' + config.message)
.css('opacity', '.5')
.find('.postbody > .content')
.html((_userdata.user_level ? config.content : '<span style="font-weight: 700; color: red;">[ You cannot see this message ]</span>'))
;
}
if (_userdata.user_level !== 1 && _userdata.user_level !== 2) {
return;
}
if (!config.link.length) {
return;
}
$.get(config.link.attr('href'))
.done(function(context) {
var $textarea = $('#text_editor_textarea', context);
if (!$textarea.length) return;
if ($('#only_admin-' + config.message).length) return;
$('<button>', {
'class': 'button1 rep-button',
'role': 'button',
'title': 'Hide this post',
'text': 'Hide post'
})
.appendTo($post.find('.postbody > .content'))
.on('click', function(event) {
event.preventDefault();
$.post("/post", {
p: config.message,
mode: 'editpost',
subject: '> only_admin',
message: $textarea.val(),
edit_reason: '',
attach_sig: 0,
notify: 0,
post: 1
}).done(function() {
location.reload(true);
}).fail(function() {
alert('[Erro]: Something went wrong when editing the post');
});
});
});
});
});
}(jQuery));
Can you help me ?
Thanks for reading!
Last edited by zest_n on January 30th 2023, 3:30 pm; edited 1 time in total
zest_n- New Member
- Posts : 17
Reputation : 7
Language : English
Joost likes this post
Re: Hidden messages visible for Administrators only
helloskouliki wrote:hello
please post our forum url and verison
my forum: https://fmt111.forumotion.com/
version: punbb
zest_n- New Member
- Posts : 17
Reputation : 7
Language : English
Re: Hidden messages visible for Administrators only
Hello @zest_n ,
You can use this Javascript. You can add members who can use the hide button.
You can translate the dutch language to your lanquage.
You can use this Javascript. You can add members who can use the hide button.
- Code:
(function($) {
'use strict';
$(function() {
var username = _userdata["username"];
var usersWithAccess = ["Admin", "Moderator"];
if (usersWithAccess.includes(username)) {
if (!/^\/t(\d+)(p\d+-|-).*$/i.test(location.pathname)) {
return;
}
$('.post').each(function() {
var $post = $(this);
var config = {
link: $post.next().find('a[href^="/post?p="][href$="&mode=editpost"]'),
message: $post.attr('class').split('--')[1],
title: $post.find('.postdetails:not(.poster-profile)'),
content: $post.find('.postbody div').html()
};
if (/> only_admin/.test(config.title.text())) {
config.title
.html('[VERBORGEN BERICHT] alleen zichtbaar voor leden met moderatierechten!</u>.');
$post
.attr('id', 'only_admin-' + config.message.match(/[0-9]+/))
.css('opacity', '.6')
.find('.postbody .content')
.html((_userdata.user_level ? config.content : '<span style="font-weight: 700; color: #ccff00 !important; text-shadow: 1px 1px 4px rgb(0 0 0 / 20%); user-select: none;">[ Dit bericht is verborgen en alleen voor moderatoren te bekijken! ]</span>'));
}
if (_userdata.user_level !== 1 && _userdata.user_level !== 2) {
return;
}
if (!config.link.length) {
return;
}
$.get(config.link.attr('href'))
.done(function(context) {
var $textarea = $('#text_editor_textarea', context);
var isHide = $('#only_admin-' + config.message.match(/[0-9]+/));
if (!$textarea.length) return;
$('<img>', {
'src': (isHide.length ? 'https://i.servimg.com/u/f26/19/95/73/76/scre2611.png' : 'https://i.servimg.com/u/f26/19/95/73/76/scre2610.png'),
'role': 'button',
'class': 'p-hide',
'loading': 'lazy',
'title': (isHide.length ? 'Weergeef dit bericht' : 'Verberg dit bericht'),
'alt': (isHide.length ? 'Niet meer verbergen' : 'Verberg bericht')
})
.insertAfter($post.next().find('a[href^="/post"][href$="mode=delete"]'))
.on('click', function(event) {
event.preventDefault();
var topicname = '> only_admin';
if (isHide.length) {
var renametopic = prompt('Maak onderstaand veld helemaal leeg om bericht terug te zetten voor leden!', topicname);
if (renametopic != null) {
topicname = renametopic;
}
}
$.post("/post", {
p: config.link.attr('href').replace(/^\/post\?p=(\d+)&.+/gi, '$1'),
mode: 'editpost',
subject: topicname,
message: $textarea.val(),
edit_reason: '',
attach_sig: 0,
notify: 0,
post: 1
}).done(function() {
location.reload(true);
}).fail(function() {
alert('[Erro]: Something went wrong when editing the post');
});
});
});
});
var btns = $(".i_icon_ip ").length;
var splitBtn = $(".btn-flat")[4].getAttribute("href");
for (i = 0; i < btns; i++) {
var hideBtn = $(".i_icon_ip ").parent()[i];
$(`<a href=${splitBtn}><img src="https://i.servimg.com/u/f26/19/95/73/76/th/17571410.png" class="p-move"></a>`).insertBefore(hideBtn);
}
}
});
}(jQuery));
You can translate the dutch language to your lanquage.
skouliki, TonnyKamper and zest_n like this post
Re: Hidden messages visible for Administrators only
Joost wrote:Hello @zest_n ,
You can use this Javascript. You can add members who can use the hide button.
- Code:
(function($) {
'use strict';
$(function() {
var username = _userdata["username"];
var usersWithAccess = ["Admin", "Moderator"];
if (usersWithAccess.includes(username)) {
if (!/^\/t(\d+)(p\d+-|-).*$/i.test(location.pathname)) {
return;
}
$('.post').each(function() {
var $post = $(this);
var config = {
link: $post.next().find('a[href^="/post?p="][href$="&mode=editpost"]'),
message: $post.attr('class').split('--')[1],
title: $post.find('.postdetails:not(.poster-profile)'),
content: $post.find('.postbody div').html()
};
if (/> only_admin/.test(config.title.text())) {
config.title
.html('[VERBORGEN BERICHT] alleen zichtbaar voor leden met moderatierechten!</u>.');
$post
.attr('id', 'only_admin-' + config.message.match(/[0-9]+/))
.css('opacity', '.6')
.find('.postbody .content')
.html((_userdata.user_level ? config.content : '<span style="font-weight: 700; color: #ccff00 !important; text-shadow: 1px 1px 4px rgb(0 0 0 / 20%); user-select: none;">[ Dit bericht is verborgen en alleen voor moderatoren te bekijken! ]</span>'));
}
if (_userdata.user_level !== 1 && _userdata.user_level !== 2) {
return;
}
if (!config.link.length) {
return;
}
$.get(config.link.attr('href'))
.done(function(context) {
var $textarea = $('#text_editor_textarea', context);
var isHide = $('#only_admin-' + config.message.match(/[0-9]+/));
if (!$textarea.length) return;
$('<img>', {
'src': (isHide.length ? 'https://i.servimg.com/u/f26/19/95/73/76/scre2611.png' : 'https://i.servimg.com/u/f26/19/95/73/76/scre2610.png'),
'role': 'button',
'class': 'p-hide',
'loading': 'lazy',
'title': (isHide.length ? 'Weergeef dit bericht' : 'Verberg dit bericht'),
'alt': (isHide.length ? 'Niet meer verbergen' : 'Verberg bericht')
})
.insertAfter($post.next().find('a[href^="/post"][href$="mode=delete"]'))
.on('click', function(event) {
event.preventDefault();
var topicname = '> only_admin';
if (isHide.length) {
var renametopic = prompt('Maak onderstaand veld helemaal leeg om bericht terug te zetten voor leden!', topicname);
if (renametopic != null) {
topicname = renametopic;
}
}
$.post("/post", {
p: config.link.attr('href').replace(/^\/post\?p=(\d+)&.+/gi, '$1'),
mode: 'editpost',
subject: topicname,
message: $textarea.val(),
edit_reason: '',
attach_sig: 0,
notify: 0,
post: 1
}).done(function() {
location.reload(true);
}).fail(function() {
alert('[Erro]: Something went wrong when editing the post');
});
});
});
});
var btns = $(".i_icon_ip ").length;
var splitBtn = $(".btn-flat")[4].getAttribute("href");
for (i = 0; i < btns; i++) {
var hideBtn = $(".i_icon_ip ").parent()[i];
$(`<a href=${splitBtn}><img src="https://i.servimg.com/u/f26/19/95/73/76/th/17571410.png" class="p-move"></a>`).insertBefore(hideBtn);
}
}
});
}(jQuery));
You can translate the dutch language to your lanquage.
Hello @joost
Thanks for your help
But I want the "Unhide" button to be similar to the "Hide" button
e.g. when I click on the "Hide" button, the post's subject will be modified to "> only_admin" to hide. Then I click on the "Unhide" button, the post's subject will be modified to "topicname" to unhide.
zest_n- New Member
- Posts : 17
Reputation : 7
Language : English
Similar topics
» Hidden messages visible for Administrators only
» Notifications visible when FM Toolbar is hidden
» divide forum into visible and hidden section
» Threads are visible only for registered users (not visible for guest)
» How do I create different hidden forums for different hidden groups?
» Notifications visible when FM Toolbar is hidden
» divide forum into visible and hidden section
» Threads are visible only for registered users (not visible for guest)
» How do I create different hidden forums for different hidden groups?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum