@@ -3,21 +3,25 @@ import { createPopup } from '../../components/popup'
33import { createToast } from '../../components/toast'
44import { StorageKey } from '../../constants'
55import { iconHeart , iconHide , iconReply } from '../../icons'
6- import type { Member } from '../../types'
6+ import { fetchTopicPage } from '../../services'
7+ import type { CommentData , Member } from '../../types'
78import { escapeHTML , getStorageSync } from '../../utils'
89import {
910 $commentBox ,
1011 $commentCells ,
1112 $commentTableRows ,
1213 $replyTextArea ,
13- commentDataList ,
1414 loginName ,
1515 topicOwnerName ,
16+ updateCommentCells ,
1617} from '../globals'
1718import { insertTextToReplyInput } from '../helpers'
1819import { processAvatar } from './avatar'
1920import { openTagsSetter , processReplyContent , updateMemberTag } from './content'
2021
22+ /** 每一页的回复列表数据 */
23+ let commentDataList : readonly CommentData [ ] = [ ]
24+
2125/**
2226 * 设置热门回复。
2327 */
@@ -199,7 +203,89 @@ function handlingControls() {
199203 } )
200204}
201205
202- export function handlingComments ( ) {
206+ export async function handlingComments ( ) {
207+ if ( false ) {
208+ const $paging = $ ( '.v2p-paging' )
209+ const $pagingTop = $paging . eq ( 0 )
210+ const $pagingBottom = $paging . eq ( 1 )
211+
212+ const $pageCurrent = $pagingTop . find ( '.page_current' )
213+ const currentPage = $pageCurrent . text ( )
214+
215+ if ( currentPage === '1' ) {
216+ const $pageNormal = $pagingTop . find ( '.page_normal' )
217+ const pages : string [ ] = [ ]
218+ $pageNormal . each ( ( _ , ele ) => {
219+ if ( ele . textContent ) {
220+ ele . classList . add ( 'page_current' )
221+ pages . push ( ele . textContent )
222+ }
223+ } )
224+
225+ if ( pages . length > 0 ) {
226+ const pagesText = await Promise . all (
227+ pages . map ( ( p ) => fetchTopicPage ( window . location . pathname , p ) )
228+ )
229+
230+ pagesText . map ( ( pageText ) => {
231+ $pagingBottom . before ( $ ( pageText ) . find ( '.cell[id^="r_"]' ) )
232+ } )
233+ }
234+
235+ updateCommentCells ( )
236+ }
237+ }
238+
239+ commentDataList = $commentTableRows
240+ . map < CommentData > ( ( idx , tr ) => {
241+ const id = $commentCells [ idx ] . id
242+
243+ const $tr = $ ( tr )
244+ const $td = $tr . find ( '> td:nth-child(3)' )
245+
246+ const thanked = $tr . find ( '> td:last-of-type > .fr' ) . find ( '> .thank_area' ) . hasClass ( 'thanked' )
247+
248+ const $member = $td . find ( '> strong > a' )
249+ const memberName = $member . text ( )
250+ const memberLink = $member . prop ( 'href' )
251+ const memberAvatar = $tr . find ( '.avatar' ) . prop ( 'src' )
252+
253+ const content = $td . find ( '> .reply_content' ) . text ( )
254+ const likes = Number ( $td . find ( 'span.small' ) . text ( ) )
255+ const floor = $td . find ( 'span.no' ) . text ( )
256+
257+ const memberNameMatches = Array . from ( content . matchAll ( / @ ( [ a - z A - Z 0 - 9 ] + ) / g) )
258+ const refMemberNames =
259+ memberNameMatches . length > 0
260+ ? memberNameMatches . map ( ( [ , name ] ) => {
261+ return name
262+ } )
263+ : undefined
264+
265+ const floorNumberMatches = Array . from ( content . matchAll ( / # ( \d + ) / g) )
266+ const refFloors =
267+ floorNumberMatches . length > 0
268+ ? floorNumberMatches . map ( ( [ , floor ] ) => {
269+ return floor
270+ } )
271+ : undefined
272+
273+ return {
274+ id,
275+ memberName,
276+ memberLink,
277+ memberAvatar,
278+ content,
279+ likes,
280+ floor,
281+ index : idx ,
282+ refMemberNames,
283+ refFloors,
284+ thanked,
285+ }
286+ } )
287+ . get ( )
288+
203289 const storage = getStorageSync ( )
204290
205291 const tagData = storage [ StorageKey . MemberTag ]
0 commit comments