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