Skip to content

Commit 8411296

Browse files
committed
Fix display of user remark
1 parent 2af15dd commit 8411296

1 file changed

Lines changed: 67 additions & 22 deletions

File tree

src/mods/user_remark.ts

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { registerModule } from '@/module';
22
import { onMounted } from '@/hooks';
3-
import { $, append, create, html } from '@/utils/dom';
3+
import { $, $H, append, create, html } from '@/utils/dom';
44

55
interface IFeedUser {
66
remark: string;
77
screen_name: string;
88
follow_me: boolean;
99
following: boolean;
10+
verified: boolean;
1011
}
1112

1213
interface IFeedData {
@@ -21,39 +22,83 @@ registerModule({
2122
name: '优化用户备注显示',
2223
defaultEnabled: true,
2324
setup() {
25+
// 信息流一级作者
2426
onMounted('Feed', (instance) => {
2527
const el = instance.vnode.el as HTMLElement | null;
2628
if (!el) return;
2729

2830
const data = (instance.props as { data: IFeedData }).data;
2931
if (!data?.user) return;
3032

31-
const nick = $<HTMLElement>(el, '[class*="_nick_"]');
32-
if (!nick || nick.querySelector('.awsl-remark')) return;
33+
const ctx = $H<{
34+
nick: HTMLElement;
35+
name: HTMLElement;
36+
}>(el, {
37+
nick: '[class*="_nick_"]',
38+
name: '[class*="_nick_"] > [class*="_name_"] > span',
39+
});
40+
if (!ctx || $(ctx.nick, '.awsl-remark')) return;
3341

34-
const nameLink = $<HTMLElement>(nick, 'a[class*="_name_"]');
35-
const nameSpan = nameLink?.querySelector('span');
36-
37-
const info: string[] = [];
38-
if (data.user.remark && nameSpan) {
39-
html(nameSpan, data.user.screen_name);
40-
info.push(`备注:${data.user.remark}`);
42+
if (data.user.remark) {
43+
html(ctx.name, data.user.screen_name);
4144
}
42-
if (data.user.follow_me) {
43-
info.push(data.user.following ? '互相关注' : '关注了我');
45+
46+
buildRemark(ctx.nick, data.user);
47+
});
48+
49+
// 转发内容的原作者
50+
onMounted('FeedContent', (instance) => {
51+
const el = instance.vnode.el as HTMLElement | null;
52+
if (!el || !el.classList.contains('retweet')) return;
53+
54+
const data = (instance.props as { data: IFeedData }).data;
55+
if (!data?.user) return;
56+
57+
const ctx = $H<{
58+
link: HTMLElement;
59+
name: HTMLElement;
60+
}>(el, {
61+
link: '.wbpro-feed-reText [usercard]',
62+
name: '.wbpro-feed-reText [usercard] > [class*="_nick_"]',
63+
});
64+
if (!ctx) return;
65+
66+
const container = ctx.link.parentElement!;
67+
const verify = $(container, '[class*="_verify_"]');
68+
69+
if ($(container, '.awsl-remark')) return;
70+
71+
if (!data.user.verified && verify) {
72+
verify.remove();
4473
}
4574

46-
if (info.length > 0) {
47-
append(nick, () => create('div', ['awsl-remark'], {
48-
style: {
49-
'color': 'var(--w-sub)',
50-
'font-size': '80%',
51-
'font-weight': 'normal',
52-
'margin-left': '0.5em',
53-
},
54-
html: info.join(SPLITTER),
55-
}));
75+
if (data.user.remark) {
76+
html(ctx.name, data.user.screen_name);
5677
}
78+
79+
buildRemark(container, data.user);
5780
});
5881
},
5982
});
83+
84+
function buildRemark(container: HTMLElement, user: IFeedUser): void {
85+
const info: string[] = [];
86+
if (user.remark) {
87+
info.push(`备注:${user.remark}`);
88+
}
89+
if (user.follow_me) {
90+
info.push(user.following ? '互相关注' : '关注了我');
91+
}
92+
93+
if (info.length > 0) {
94+
append(container, () => create('div', ['awsl-remark'], {
95+
style: {
96+
'color': 'var(--w-sub)',
97+
'font-size': '80%',
98+
'font-weight': 'normal',
99+
'margin-left': '0.5em',
100+
},
101+
html: info.join(SPLITTER),
102+
}));
103+
}
104+
}

0 commit comments

Comments
 (0)