Skip to content

Commit

Permalink
Swap persona name and secondary name in mini profiles for consistency…
Browse files Browse the repository at this point in the history
… with friends list
  • Loading branch information
tfedor committed Aug 20, 2024
1 parent 467c286 commit e871da5
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class FFriendsAppendNickname extends Feature<CFriendsAndGroups> {
apply(): void | Promise<void> {
document.addEventListener("as_subpageNav", () => this.callback());
this.callback();
this.handleMiniProfile();
}

private async callback(): Promise<void> {
Expand Down Expand Up @@ -63,4 +64,50 @@ export default class FFriendsAppendNickname extends Feature<CFriendsAndGroups> {
}
}
}

private handleMiniProfile(): void {
const miniProfileNode = document.querySelector(".miniprofile_hover");
if (!miniProfileNode) {
return;
}

const observer = new MutationObserver(() => {
const parent = miniProfileNode.querySelector(".player_content");
if (!parent) {
return;
}

const personaNode = parent.querySelector<HTMLElement>(".persona")!;

/*
* It seems like Steam is caching entire built profile somwehow, so we only need to swap
*/
if (personaNode.dataset.swapped) {
return;
}

const secondaryNode = parent.querySelector<HTMLElement>(".secondaryname");
if (!secondaryNode) {
return;
}

const personaName = personaNode.textContent ?? "";
const secondaryName = secondaryNode.textContent ?? "";

observer.disconnect();

secondaryNode.textContent = personaName;
personaNode.textContent = secondaryName.substring(1, secondaryName.length-1);
personaNode.dataset.swapped = "1";

observer.observe(miniProfileNode, {
childList: true,
subtree: true
})
});
observer.observe(miniProfileNode, {
childList: true,
subtree: true
});
}
}

0 comments on commit e871da5

Please sign in to comment.