This is an update that works perfectly for my use case.
If you want to hide a particular topic via CSS, on page load and henceforth, this will do it. Just add your topic IDs to the list of topic IDs:
<script>
document.addEventListener("DOMContentLoaded", function() {
var topicIdsToHide = ["10", "20", "30"]; // Add your topic IDs here
function hideElementsByDataTopicIds() {
topicIdsToHide.forEach(function(id) {
var element = document.querySelector('[data-topic-id="' + id + '"]');
if (element) {
element.style.display = 'none';
}
});
}
// Run the function initially
hideElementsByDataTopicIds();
// Create a mutation observer to monitor DOM changes
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
hideElementsByDataTopicIds();
});
});
// Observe the entire document
observer.observe(document.body, { childList: true, subtree: true });
});
</script>