Skip to content

Commit ea7e632

Browse files
authored
Update unity-forum-fixer.js
fix post view username display (fixes #3 )
1 parent 2bd442f commit ea7e632

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

unity-forum-fixer.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name UnityForumFixer
33
// @namespace https://unitycoder.com/
4-
// @version 0.87 (26.05.2025)
4+
// @version 0.88 (27.07.2025)
55
// @description Fixes For Unity Forums - https://github.com/unitycoder/UnityForumFixer
66
// @author unitycoder.com
77
// @match https://discussions.unity.com/latest
@@ -465,36 +465,36 @@ function stripHtmlTags(html) {
465465

466466
// POST VIEW
467467

468-
function PostViewShowOriginalPosterInfo()
469-
{
470-
// Select all elements that contain the avatar with a data-user-card attribute
471-
document.querySelectorAll('.trigger-user-card.main-avatar').forEach(function(avatar) {
472-
// Check if the user link has already been added
473-
if (avatar.parentNode.querySelector('.custom-post-username')) {
474-
return; // Skip to the next avatar if the user link already exists
475-
}
468+
function PostViewShowOriginalPosterInfo() {
469+
// Loop through all avatar anchors that represent a user
470+
document.querySelectorAll('.post-avatar').forEach(postAvatar => {
471+
const avatarLink = postAvatar.querySelector('a.main-avatar[data-user-card]');
472+
if (!avatarLink) return;
476473

477-
// Get the user name from the data-user-card attribute
478-
var userName = avatar.getAttribute('data-user-card');
474+
// Check if we've already added the username
475+
if (postAvatar.querySelector('.custom-post-username')) return;
479476

480-
// Create a new anchor element to wrap the user name and link to the profile
481-
var userLink = document.createElement('a');
477+
const username = avatarLink.getAttribute('data-user-card');
478+
if (!username) return;
479+
480+
const userLink = document.createElement('a');
482481
userLink.className = 'custom-post-username';
483-
userLink.href = 'https://discussions.unity.com/u/' + userName;
484-
userLink.textContent = userName;
482+
userLink.href = `/u/${username}`;
483+
userLink.textContent = username;
485484

486-
// Insert the user name link before the avatar image
487-
avatar.parentNode.insertBefore(userLink, avatar);
485+
// Insert username under the avatar
486+
postAvatar.appendChild(userLink);
488487
});
489-
490488
}
491489

490+
492491
let prevPageURL = '';
493492
function PostViewFetchOPDetails()
494493
{
495494
// Get the current page URL
496495
const currentPageURL = window.location.href;
497496

497+
498498
// Check if the current page URL has already been processed
499499
if (currentPageURL === prevPageURL) {
500500
//console.log(`Skipping fetch for already processed page URL: ${currentPageURL}`);
@@ -507,14 +507,16 @@ function PostViewFetchOPDetails()
507507
// Select all elements with the specified classes to get usernames
508508
const usernames = new Set(); // Using a Set to avoid duplicates
509509

510-
// Find usernames from elements with class 'trigger-user-card main-avatar'
511-
document.querySelectorAll('.trigger-user-card.main-avatar').forEach(function(avatar) {
510+
// Find usernames from main avatar links
511+
document.querySelectorAll('a.main-avatar[data-user-card]').forEach(function(avatar) {
512512
const userName = avatar.getAttribute('data-user-card');
513513
if (userName) {
514-
usernames.add(userName); // Add to the Set
514+
usernames.add(userName);
515515
}
516516
});
517517

518+
519+
518520
// Convert the Set to an Array and limit to the first 3 users
519521
const userArray = Array.from(usernames).slice(0, 3);
520522

@@ -557,7 +559,7 @@ function PostViewFetchOPDetails()
557559
creationDateElement.textContent = `Joined: ${formattedDate}`;
558560

559561
// Find all post-avatar divs associated with this user
560-
document.querySelectorAll('.trigger-user-card.main-avatar').forEach(function(avatarElement) {
562+
document.querySelectorAll('a.main-avatar[data-user-card]').forEach(function(avatarElement) {
561563
if (avatarElement.getAttribute('data-user-card') === userName) {
562564
const postAvatarDiv = avatarElement.closest('.post-avatar');
563565
if (postAvatarDiv && !postAvatarDiv.querySelector('.custom-user-creation-date')) {

0 commit comments

Comments
 (0)