Hi everyone!
I will show you with image.
These codes pull the Tags to the left of the topics.
But every time I click on the logo I get an error.
<script>
function moveTagsToTitle() {
const mainLinks = document.querySelectorAll('.main-link');
mainLinks.forEach(mainLink => {
const discourseTags = mainLink.querySelector('.discourse-tags');
const titleElement = mainLink.querySelector('.title');
if (discourseTags && titleElement) {
const tags = discourseTags.querySelectorAll('.discourse-tag');
tags.forEach(tag => {
const tagSpan = document.createElement('span');
tagSpan.className = 'discourse-tag box';
tagSpan.textContent = tag.textContent;
tagSpan.style.fontSize = 'var(--font-down-2)';
tagSpan.style.borderRadius = '10px';
tagSpan.style.border = '1px solid #444460';
tagSpan.style.backgroundColor = '#1f1f33';
tagSpan.style.margin = '2px';
tagSpan.style.display = 'inline-block';
tagSpan.style.overflow = 'hidden';
tagSpan.style.whiteSpace = 'nowrap';
tagSpan.style.textOverflow = 'ellipsis';
tagSpan.style.verticalAlign = 'middle';
tagSpan.style.marginRight = '5px';
tagSpan.style.marginLeft = '-6px';
titleElement.insertBefore(tagSpan, titleElement.firstChild);
});
if (discourseTags.parentNode) {
discourseTags.parentNode.removeChild(discourseTags);
}
}
});
const topicHeaderExtras = document.querySelectorAll('.topic-header-extra');
topicHeaderExtras.forEach(topicHeaderExtra => {
const discourseTags = topicHeaderExtra.querySelector('.discourse-tags');
const tags = discourseTags.querySelectorAll('.discourse-tag');
tags.forEach(tag => {
tag.className = 'discourse-tag box';
tag.style.borderRadius = '10px';
tag.style.border = '1px solid #444460';
tag.style.backgroundColor = '#1f1f33';
tag.style.margin = '1px';
tag.style.padding = '2px 8px';
tag.style.display = 'inline-block';
tag.style.overflow = 'hidden';
tag.style.whiteSpace = 'nowrap';
tag.style.textOverflow = 'ellipsis';
tag.style.verticalAlign = 'middle';
tag.style.marginRight = '5px';
tag.style.marginBottom = '5px';
});
});
}
window.addEventListener('load', moveTagsToTitle);
const observer = new MutationObserver(moveTagsToTitle);
const targetNode = document.body;
const observerOptions = {
childList: true,
subtree: true
};
observer.observe(targetNode, observerOptions);
</script>
Now I changed the codes to these codes but it does not work as I wanted.
<script>
function moveTagsToTitle() {
const mainLinks = document.querySelectorAll('.main-link');
mainLinks.forEach(mainLink => {
const discourseTags = mainLink.querySelector('.discourse-tags');
const titleElement = mainLink.querySelector('.title');
if (discourseTags && titleElement) {
const tags = discourseTags.querySelectorAll('.discourse-tag');
tags.forEach(tag => {
const tagSpan = document.createElement('span');
tagSpan.className = 'discourse-tag box';
tagSpan.textContent = tag.textContent;
tagSpan.style.fontSize = 'var(--font-down-2)';
tagSpan.style.borderRadius = '10px';
tagSpan.style.border = '1px solid #444460';
tagSpan.style.backgroundColor = '#1f1f33';
tagSpan.style.margin = '2px';
tagSpan.style.display = 'inline-block';
tagSpan.style.overflow = 'hidden';
tagSpan.style.whiteSpace = 'nowrap';
tagSpan.style.textOverflow = 'ellipsis';
tagSpan.style.verticalAlign = 'middle';
tagSpan.style.marginRight = '5px';
tagSpan.style.marginLeft = '-6px';
titleElement.insertBefore(tagSpan, titleElement.firstChild);
});
if (discourseTags.parentNode) {
discourseTags.parentNode.removeChild(discourseTags);
}
var pElement = document.getElementById('site-logo').parentNode;
//var pElement = document.createElement('a');
//pElement.innerHTML = aElement.innerHTML;
//aElement.replaceWith(pElement);
pElement.href = 'https://pvpfarm.com/';
pElement.style.cursor = 'pointer';
pElement.onclick = function() {
window.location.href = '/';
};
//document.getElementById('site-logo').parentNode.href = '/';
}
});
const topicHeaderExtras = document.querySelectorAll('.topic-header-extra');
topicHeaderExtras.forEach(topicHeaderExtra => {
const discourseTags = topicHeaderExtra.querySelector('.discourse-tags');
const tags = discourseTags.querySelectorAll('.discourse-tag');
tags.forEach(tag => {
tag.className = 'discourse-tag box';
tag.style.borderRadius = '10px';
tag.style.border = '1px solid #444460';
tag.style.backgroundColor = '#1f1f33';
tag.style.margin = '1px';
tag.style.padding = '2px 8px';
tag.style.display = 'inline-block';
tag.style.overflow = 'hidden';
tag.style.whiteSpace = 'nowrap';
tag.style.textOverflow = 'ellipsis';
tag.style.verticalAlign = 'middle';
tag.style.marginRight = '5px';
tag.style.marginBottom = '5px';
});
});
}
window.addEventListener('load', moveTagsToTitle);
const observer = new MutationObserver(moveTagsToTitle);
const targetNode = document.body;
const observerOptions = {
childList: true,
subtree: true
};
observer.observe(targetNode, observerOptions);
</script>
Can a hero help me please ?
I don’t want to get this error when I click on the logo.