إخفاء نتائج التصويت من المجهولين

Hi, is there a way to hide poll result from anonymous? I’m creating a forum about exam question solving which allow user to choose an answer for question. I don’t need my members to give false answer just to see others’ answers, but I want to prevent anonymous from seeing it too.

إعجاب واحد (1)

One more thing, I try to find a way to hide reply from anonymous too but found nothing. Does such function exist?

Hi, I just figured it out. If anyone want to try, you can create a theme component and add this to head

<script type="text/discourse-plugin" version="0.8">api.onPageChange(() => {
        if (!Discourse.User.current()) {
            const pollContainers = document.querySelectorAll('.poll');

            pollContainers.forEach(poll => {
                const observer = new MutationObserver((mutations) => {
                    mutations.forEach((mutation) => {
                        if (mutation.type === 'childList') {
                            const resultsButton = poll.querySelector('.toggle-results');
                            if (resultsButton) {
                                resultsButton.remove();
                            }
                        }
                    });
                });

                observer.observe(poll, { attributes: false, childList: true, subtree: true });

                // Remove existing buttons if present
                const existingButton = poll.querySelector('.toggle-results');
                if (existingButton) {
                    existingButton.remove();
                }
            });
        }
    });
</script>

This will even prevent the “Results” button to show up when someone votes.

إعجاب واحد (1)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.