이 업데이트는 제 사용 사례에 완벽하게 작동합니다.
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>