这是一个非常适合我的用例的更新。
如果你想通过 CSS 隐藏某个特定主题,在页面加载时以及之后,这个脚本可以做到。只需将你的主题 ID 添加到主题 ID 列表中:
<script>
document.addEventListener("DOMContentLoaded", function() {
var topicIdsToHide = ["10", "20", "30"]; // 在此处添加你的主题 ID
function hideElementsByDataTopicIds() {
topicIdsToHide.forEach(function(id) {
var element = document.querySelector('[data-topic-id="' + id + '"]');
if (element) {
element.style.display = 'none';
}
});
}
// 初始运行时
hideElementsByDataTopicIds();
// 创建一个突变观察者来监视 DOM 更改
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
hideElementsByDataTopicIds();
});
});
// 观察整个文档
observer.observe(document.body, { childList: true, subtree: true });
});
</script>