Skip to content

Commit 3c92768

Browse files
committed
feat: ✨ 百合会增加「移动端显示帖子权限」功能
https://sleazyfork.org/scripts/374903/discussions/209399#comment-608222
1 parent 84448d7 commit 3c92768

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

src/site/yamibo.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type History = {
3333
修正点击页数时的跳转判定: true,
3434
固定导航条: true,
3535
自动签到: true,
36+
移动端显示帖子权限: true,
3637
});
3738

3839
useStyle(
@@ -430,5 +431,37 @@ type History = {
430431
// 点击下一页后更新提示
431432
querySelector('#autopbn')?.addEventListener('click', updateHistoryTag);
432433
}
434+
435+
if (options.移动端显示帖子权限 && /mod=forumdisplay/.test(document.URL)) {
436+
const apiUrl = new URL(location.href);
437+
apiUrl.pathname = '/api/mobile/index.php';
438+
apiUrl.searchParams.set('module', apiUrl.searchParams.get('mod')!);
439+
apiUrl.searchParams.delete('mod');
440+
441+
const res = await request<{
442+
Variables: {
443+
forum_threadlist: { tid: string; readperm: string }[];
444+
};
445+
}>(`${apiUrl}`, {
446+
responseType: 'json',
447+
errorText: '获取帖子权限时出错',
448+
});
449+
450+
const readpermMap = new Map<number, number>();
451+
for (const { tid, readperm } of res.response.Variables.forum_threadlist)
452+
if (readperm !== '0') readpermMap.set(Number(tid), Number(readperm));
453+
454+
for (const item of querySelectorAll('.threadlist li.list')) {
455+
const a = item.querySelector<HTMLAnchorElement>('a[href*="&tid="]')!;
456+
const tid = Number(new URLSearchParams(a.href).get('tid')!);
457+
if (!readpermMap.has(tid)) continue;
458+
item
459+
.querySelector('.threadlist_foot li.mr')!
460+
.insertAdjacentHTML(
461+
'beforeend',
462+
`<span style="margin-right: .5em; color: #EE1B2E">#权限${readpermMap.get(tid)}</span>`,
463+
);
464+
}
465+
}
433466
}
434467
})().catch((error) => log.error(error));

0 commit comments

Comments
 (0)