Skip to content

Commit 70dbfd0

Browse files
fix: adjust message display position for accounts with empty bio (#1853)
1 parent 34964df commit 70dbfd0

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/css/style.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ sbs-message {
3434
margin-top: 1em;
3535
}
3636

37+
/*
38+
* If the bio is empty, the bio element does not exist, and sbs-message is inserted directly after the username,
39+
* so apply a different style
40+
*/
41+
[data-testid="UserName"] + sbs-message {
42+
margin-top: 0;
43+
margin-bottom: 1rem;
44+
}
45+
3746
[data-sb-compact-mode] {
3847
/*
3948
* `!important` is required to work with Kiwi Browser.

src/ts/core/core.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { TweetParser } from "./parser/tweetParser";
1313
class Core {
1414
private readonly settings: Settings;
1515
private readonly onMessageCallback: () => void;
16+
private previousMessageWrapper: SbsMessageWrapper | null = null;
1617

1718
/**
1819
* Run the core process.
@@ -41,6 +42,7 @@ class Core {
4142
document.body.setAttribute("data-color-scheme", colorScheme === "light" ? "light" : "dark");
4243
}
4344

45+
// eslint-disable-next-line max-statements
4446
private checkProfile(profile: Profile): void {
4547
const isCurrentUsersProfile = Boolean(document.querySelector("[data-testid='editProfileButton']"));
4648
if (!isCurrentUsersProfile && !this.settings.enableForOtherUsersProfiles) return;
@@ -56,6 +58,13 @@ class Core {
5658
document.querySelector("[data-testid='UserName']");
5759
if (!bioOrUserName) throw new Error("Failed to get user description of profile");
5860

61+
/*
62+
* When navigating directly from one profile page to another,
63+
* especially if the bio of the previous profile is empty, the inserted message may remain.
64+
* Therefore, ensure it is removed.
65+
*/
66+
this.previousMessageWrapper?.remove();
67+
this.previousMessageWrapper = sbsMessageWrapper;
5968
sbsMessageWrapper.insertAdjacentElement(bioOrUserName, "afterend");
6069
}
6170

src/ts/core/sbsMessageWrapper.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ class SbsMessageWrapper {
114114
public insertAdjacentElement(target: Element, position: InsertPosition): void {
115115
target.insertAdjacentElement(position, this.sbsMessage);
116116
}
117+
118+
public remove(): void {
119+
this.sbsMessage.remove();
120+
}
117121
}
118122

119123
export { type SbsMessageWrapperOptionsForTweets, type SbsMessageWrapperOptionsForProfiles, SbsMessageWrapper };

0 commit comments

Comments
 (0)