如何限制对按钮钉住/解除钉住的访问

我在页眉中尝试了此代码

document.addEventListener("DOMContentLoaded", function() {
    setTimeout(() => {
        let userTrustLevel = parseInt(Discourse.User.current().trust_level);

        if (userTrustLevel < 4) {
            document.querySelectorAll(".pin-topic, .unpin-topic").forEach(button => {
                button.style.pointerEvents = "none";
                button.style.opacity = "0.5";
                button.title = "您无权置顶主题";
            });
        }
    }, 1000);  complet
});

并在 CSS 中添加了以下代码

.d-header-icons .pin-topic,
.d-header-icons .unpin-topic,
.controls .pin-topic,
.controls .unpin-topic {
    display: none !important;
}

但是,信任等级为 1 或 0 的普通用户仍然可以点击并看到置顶按钮。

默认情况下,当用户滚动到底部时自动取消置顶主题。 此选项已关闭
当用户滚动到底部时自动取消置顶主题。 此选项已关闭

嘿,欢迎!:wave:

您是在说这些按钮吗?

您可以使用纯 CSS 来隐藏这些按钮。

首先安装此组件:https://meta.discourse.org/t/css-classes-for-current-users-groups/226068。它会将当前用户组名称(例如 group-<name>)添加到 <body> 元素中。

然后您可以定位任何元素:

:not(.group-trust_level_4) #topic-footer-buttons .pinned-button {
  display: none;
}
5 个赞

另外,主题可以被固定/取消固定在几个地方:

4 个赞

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