איך להריץ קוד לאחר שהדף נטען

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? :crying_cat:


  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";
      }
    });
  });
});
2 לייקים

אני לא מאמין שזה יעבוד.

אתה חייב לבצע את הדברים האלה באמצעות CSS או בתוך לולאת הריצה של Ember.

מה שמנע ממך להעתיק את אותו רכיב ולשנות אותו לטעמך תחת שם שונה, לטעון רכיב נושא אחר ואז להוסיף אותו בשם ב-RSB?

2 לייקים

Laziness, mostly. And when I started it was just going to be a little css that would likely be static and they’d not need to maintain the fork, but yeah, it’s now obviously silly not to fork it.

Thanks

4 לייקים

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