إضافة اسم مستخدم OP إلى فئات CSS في الجسم

Hi,
Can anybody help me to add OP username as <body> CSS class?
I need to write some styles and need different attributes for some usernames.

Some users asked us to delete the topic from their profile but did not insist on deleting it completely. That’s why we created an anonymous user to change the ownership of the requested topics.

Now we need to make changes to the page elements if the OP is anonymous. Including hiding quotes and mentions and etc.

<script type="text/discourse-plugin" version="0.8">
    api.onPageChange((url, title) => {
        if (/^\/\t\/.*$/.test(url)) {
            const opUser = API.????? <--------------------------- How to Get OP user object
            if (opUser && opUser.id === 1234) {
                document.querySelector("body").classList.add("anon");
            }
        } else {
            document.querySelector("body").classList.remove("anon");
        }
    });
</script>

Is there a way we can get topic info via JavaScript API?

api.getCurrentUser()

Calling api.getCurrentUser() method returns the logged-in user. I’m looking for a method to get topic information (including topic owner).

Oh sorry I misread. :confused:

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

You’re welcome, I think this is more complicated than asking a simple question :+1: :sweat_smile:

To solve my problem, I found the following solution by reading this page:

https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/app/lib/plugin-api.js#L1138-L1140

<script type="text/discourse-plugin" version="0.8">
    const specialTopicUserId = 1000;
    api.decorateTopicTitle((topicModel, node, topicTitleType) => {
        if (topicModel && topicModel.user_id === specialTopicUserId) {
            $("#topic").addClass("anon");
        }
    });
</script>