I want to remove the parenthesis from span.category-topics--posts-count
(rendered by GitHub - discourse/discourse-right-sidebar-blocks). I’m trying this api.onPageChange()
call, but it’s not getting any countSpans, I think because it’s running before the other theme component has put them on the page.
What can I do?
api.onPageChange(() => {
console.log("page changed");
const countSpans = document.querySelectorAll(
"span.category-topics--posts-count"
);
console.log("spans", countSpans);
countSpans.forEach((span) => {
const currentText = span.textContent.trim();
const newText = currentText.replace(/[()]/g, "");
span.textContent = newText;
const number = parseInt(newText);
if (isNaN(number)) {
span.style.padding = "0px";
} else if (number < 10) {
span.style.padding = "0px";
} else {
span.style.padding = "0px 3px";
}
});
});
});