مرحباً،
لقد حاولت إنشاء نص برمجي للحصول على السمة background-image من رأس الملف الشخصي، ثم حفظها كمتغير جذر. ومع ذلك، فإن الكود الخاص بي لا يعمل. لقد جربت العديد من الحلول، بعضها تضمن الذكاء الاصطناعي، والذي أعاد فقط إصدار المكون الإضافي ولم يساعد.
هذا هو الكود:
<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>
شكراً لك.