I’m trying to change the tag links using the below and it seems to work on refreshing the page or going to a new page, but it does not work when you scroll down the page where endless scroll loads in new items:
<script type="text/discourse-plugin" version="0.8">
api.onPageChange(() =>{
var tags = document.getElementsByClassName("discourse-tag");
for (i = 0; i < tags.length; i++) {
var tag = tags[i];
var url = tag.href;
var newUrl = "https://site.com" + url;
tag.href = newUrl;
}
});
</script>
Do I need to use something other than or in addition to api.onPageChange?
Yeah that won’t work. It’s only going to fire on a route change. You need to consider overriding the code that actually renders those tags directly rather than using Dom selection.
Any ideas what I’m doing wrong? Has something changed since I read the guides perhaps? (For some reason I thought it was as simple as overriding files to change small things like this).
Thanks! Funnily enough I started customising the Tag icons component last night and managed to get it to work!
Out of curiosity tho, should the plugin file-override method as I described above should have worked as well? (If so any ideas what I was doing wrong?)