Hello,
I tried making a script to grab the background-image attribute from the profile header, then save it as a root variable. However, my code does not work. I tried many solutions, some of them included AI, which just reverted the plugin version and did not help.
This is the code:
<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; //when run, this always comes up no matter what and displays the same error
}
};
const shouldRun = () => {
return window.location.pathname.startsWith('/u/');
};
const init = () => {
if (shouldRun()) {
setRootBgImage();
}
};
document.addEventListener('DOMContentLoaded', init);
api.onPageChange(() => {
init();
});
</script>
Thank you.