Hidden messages visible for Administrators only 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.
3 posters

    Hidden messages visible for Administrators only

    zest_n
    zest_n
    New Member


    Posts : 11
    Reputation : 3
    Language : English

    Solved Hidden messages visible for Administrators only

    Post by zest_n January 24th 2023, 6:31 pm

    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)
    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));
    Source https://help.forumotion.com/t160906-hidden-messages-visible-for-administrators-only#1124954

    Can you help me ?

    Thanks for reading!


    Last edited by zest_n on January 30th 2023, 3:30 pm; edited 1 time in total

    Joost likes this post

    skouliki
    skouliki
    Manager
    Manager


    Female Posts : 15274
    Reputation : 1701
    Language : English,Greek
    Location : Greece

    Solved Re: Hidden messages visible for Administrators only

    Post by skouliki January 24th 2023, 6:52 pm

    hello

    please post our forum url and verison

    zest_n
    zest_n
    New Member


    Posts : 11
    Reputation : 3
    Language : English

    Solved Re: Hidden messages visible for Administrators only

    Post by zest_n January 24th 2023, 7:19 pm

    skouliki wrote:hello
    please post our forum url and verison
    hello
    my forum: https://fmt111.forumotion.com/
    version: punbb
    Joost
    Joost
    Active Poster


    Male Posts : 1370
    Reputation : 193
    Language : Dutch, English
    Location : The Netherlands

    Solved Re: Hidden messages visible for Administrators only

    Post by Joost January 24th 2023, 7:32 pm

    Hello @zest_n ,

    You can use this Javascript. You can add members who can use the hide button. Smile

    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. Smile

    skouliki, TonnyKamper and zest_n like this post

    zest_n
    zest_n
    New Member


    Posts : 11
    Reputation : 3
    Language : English

    Solved Re: Hidden messages visible for Administrators only

    Post by zest_n January 25th 2023, 3:02 pm

    Joost wrote:Hello @zest_n ,

    You can use this Javascript. You can add members who can use the hide button. Smile

    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. Smile

    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.
    skouliki
    skouliki
    Manager
    Manager


    Female Posts : 15274
    Reputation : 1701
    Language : English,Greek
    Location : Greece

    Solved Re: Hidden messages visible for Administrators only

    Post by skouliki February 2nd 2023, 7:56 am

    marked as solved

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