This repository has been archived on 2026-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
polyplus/js/op-comments.js
Index 4bf9139a60 small improvements
- removed tabs permission apparently it was unnecessary

- fixed store main page "owned" tags when the user's inventory is private/friends-only

- fixed "creator" tags in comment sections around the site

- deleted currently-unused currencies.json resource
2024-05-29 17:03:53 -05:00

61 lines
2 KiB
JavaScript
Executable file

/*
this script will need to be updated when the new profile URLs are fully rolled out
*/
!(() => {
let Comments = document.getElementById('comments');
const Type = window.location.pathname.split('/')[1];
let CreatorID;
if (Type === 'store') {
if (document.querySelector('h5 .text-reset[href^="/users/"]')) {
CreatorID = document.querySelector('h5 .text-reset[href^="/users/"]').getAttribute('href').split('/')[2];
} else {
CreatorID = 1;
}
} else if (Type === 'places') {
CreatorID = document.querySelector('.mcard .col .text-muted [href^="/users/"]').getAttribute('href').split('/')[2];
} else if (Type === 'feed') {
CreatorID = document.querySelector('p a[href^="/users/"].text-reset').getAttribute('href').split('/')[2];
} else if (Type === 'guilds') {
CreatorID = document.querySelector('[class^="userlink-"][href^="/users/"]').getAttribute('href').split('/')[2];
Comments = document.getElementById('wall-posts');
}
const Observer = new MutationObserver(function (list) {
for (let record of list) {
for (let element of record.addedNodes) {
if (element.classList.contains('card')) {
LoadCreatorTag(element);
}
}
}
});
Observer.observe(Comments, {attributes: false, childList: true, subtree: false});
const LoadCreatorTag = function (element) {
let NameElement = element.querySelector('.text-reset[href^="/users/"]');
if (Type === 'guilds') {
NameElement = element.querySelector('[class^="userlink-"][href^="/users/"]');
}
let UserID = NameElement.getAttribute('href').split('/')[2];
if (UserID === CreatorID) {
let Tag = document.createElement('span');
Tag.classList = 'badge bg-primary';
Tag.style.marginLeft = '5px';
Tag.style.verticalAlign = 'text-top';
Tag.innerText = 'CREATOR';
if (Type === 'guilds') {
Tag.innerText = 'LEADER';
}
NameElement.appendChild(Tag);
//new window.bootstrap.Tooltip(Tag, {toggle:"tooltip",title:"This user is the creator of this asset!"})
}
};
Array.from(Comments.children).forEach((element) => {
LoadCreatorTag(element);
});
})();