# 페이지 렌더링 후 코드 실행하는 방법

**URL:** https://meta.discourse.org/t/how-to-run-code-after-page-has-rendered/358393
**Category:** Development
**Created:** [3월 21, 2025, 9:49오후 UTC](https://meta.discourse.org/t/how-to-run-code-after-page-has-rendered/358393 "2025-03-21T21:49:38Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [3월 21, 2025, 9:49오후 UTC](https://meta.discourse.org/t/how-to-run-code-after-page-has-rendered/358393/1 "2025-03-21T21:49:38Z")

</div>

`span.category-topics--posts-count`에서 괄호를 제거하고 싶습니다 ([https://github.com/discourse/discourse-right-sidebar-blocks에서](https://github.com/discourse/discourse-right-sidebar-blocks%EC%97%90%EC%84%9C) 렌더링됨). 이 `api.onPageChange()` 호출을 시도하고 있지만, countSpans을 전혀 가져오지 못하고 있습니다. 다른 테마 구성 요소가 페이지에 요소를 추가하기 전에 실행되고 있기 때문이라고 생각합니다.

어떻게 해야 할까요? 😿

```plaintext

  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";
      }
    });
  });
});

```

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [3월 21, 2025, 10:21오후 UTC](https://meta.discourse.org/t/how-to-run-code-after-page-has-rendered/358393/2 "2025-03-21T22:21:52Z")

</div>

그렇게 될 것 같지 않습니다.

이 작업은 CSS를 통해 또는 Ember 실행 루프 내에서 수행해야 합니다.

그 컴포넌트를 포크해서 다른 이름으로 원하는 대로 커스터마이징한 후, 별도의 테마 컴포넌트를 로드하고 RSB에서 이름으로 추가하는 것을 막는 것이 무엇인가요?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [3월 21, 2025, 10:46오후 UTC](https://meta.discourse.org/t/how-to-run-code-after-page-has-rendered/358393/3 "2025-03-21T22:46:04Z")

</div>

> [@merefield](#):
>
> 그 컴포넌트를 포크해서 다른 이름으로 취향에 맞게 커스터마이즈하는 걸 막는 게 뭐야

대부분 게으름 때문이야. 처음 시작했을 땐 아마 정적일 가능성이 높은 작은 css일 뿐이라 포크를 유지보수할 필요가 없을 거라고 생각했거든. 하지만 지금은 포크하지 않는 게 명백히 멍청한 일이야.

감사해

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [4월 20, 2025, 10:46오후 UTC](https://meta.discourse.org/t/how-to-run-code-after-page-has-rendered/358393/4 "2025-04-20T22:46:26Z")

</div>

이 주제는 마지막 답변 후 30일이 지나면 자동으로 닫힙니다. 더 이상 새 답변을 작성할 수 없습니다.
