안녕하세요,
프로필 헤더에서 background-image 속성을 가져와 루트 변수로 저장하는 스크립트를 작성해 보았습니다. 하지만 제 코드가 작동하지 않습니다. 다양한 해결책을 시도해 보았는데, 그중 일부는 AI를 사용했는데, 결과적으로 플러그인 버전만 되돌려졌을 뿐 도움이 되지 않았습니다.
아래는 제 코드입니다:
<script type="text/discourse-plugin" version="0.9">
const setRootBgImage = () => {
try {
const el = document.getElementByClassName('.user-profile-image');
if (el) {
const bgImage = window.getComputedStyle(el).getPropertyValue('background-image');
document.documentElement.style.setProperty('--profile-bg-img', bgImage);
}
} catch (error) {
console.error(error);
debugger; //실행할 때 항상 이 에러가 발생하며 동일한 오류가 표시됩니다
}
};
const shouldRun = () => {
return window.location.pathname.startsWith('/u/');
};
const init = () => {
if (shouldRun()) {
setRootBgImage();
}
};
document.addEventListener('DOMContentLoaded', init);
api.onPageChange(() => {
init();
});
</script>
감사합니다.