Skip to content

Commit

Permalink
- 修复细节问题
Browse files Browse the repository at this point in the history
  • Loading branch information
czy0729 committed Aug 23, 2024
1 parent dcfdda7 commit 4e90265
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 47 deletions.
2 changes: 2 additions & 0 deletions src/components/render-html/renderer/span.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import MaskText from '../mask-text'
import { fixedBaseFontStyle } from '../utils'

export function span({ key, style, defaultBaseFontStyle, baseFontStyle, rawChildren, children }) {
if (typeof style === 'string' && style.includes('font-size:0px')) return null

try {
// 暂时没有对样式混合情况作出正确判断, 以重要程度优先(剧透 > 删除 > 隐藏 > 其他)
// 防剧透字
Expand Down
6 changes: 3 additions & 3 deletions src/screens/home/mono/store/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2023-04-21 18:32:13
* @Last Modified by: czy0729
* @Last Modified time: 2024-01-10 04:42:28
* @Last Modified time: 2024-08-23 18:07:43
*/
import { subjectStore, systemStore, tinygrailStore } from '@stores'
import { getTimestamp, omit } from '@utils'
Expand Down Expand Up @@ -83,12 +83,12 @@ export default class Fetch extends Computed {
comments: {
list: this.monoComments.list
.filter(item => !!item.userId)
.filter((item, index) => index < 8)
.filter((_item, index) => index < 8)
.map(item => ({
...omit(item, ['replySub']),
sub: item.sub
.filter(i => !!i.userId)
.filter((i, idx) => idx < 8)
.filter((_i, idx) => idx < 8)
.map(i => omit(i, ['replySub']))
})),
pagination: this.monoComments.pagination
Expand Down
4 changes: 3 additions & 1 deletion src/screens/home/subject/store/computed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2022-05-11 19:26:49
* @Last Modified by: czy0729
* @Last Modified time: 2024-08-23 17:16:07
* @Last Modified time: 2024-08-23 17:29:45
*/
import React from 'react'
import { View } from 'react-native'
Expand Down Expand Up @@ -1030,6 +1030,8 @@ export default class Computed extends State {

/** 书籍 */
@computed get subjectBook() {
if (!WEB) return null

return this.subjectRelations.find(item => item.type === '书籍')
}

Expand Down
50 changes: 25 additions & 25 deletions src/stores/subject/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2019-07-15 09:33:32
* @Last Modified by: czy0729
* @Last Modified time: 2024-04-18 17:01:29
* @Last Modified time: 2024-08-23 18:08:31
*/
import {
cheerio,
Expand Down Expand Up @@ -146,7 +146,7 @@ export async function fetchMono({ monoId }: { monoId: MonoId }) {
)
if (matchHTML) {
const $ = cheerio(matchHTML[1])
$('li.item').each((index: number, element: any) => {
$('li.item').each((_index: number, element: any) => {
const $row = cheerio(element)
const $a = $row.find('a.l')
mono.works.push({
Expand All @@ -155,7 +155,7 @@ export async function fetchMono({ monoId }: { monoId: MonoId }) {
cover: $row.find('img.cover').attr('src'),
staff: $row
.find('span.badge_job')
.map((index: number, element: any) => {
.map((_index: number, element: any) => {
const $row = cheerio(element)
return $row.text().trim()
})
Expand Down Expand Up @@ -240,7 +240,7 @@ export async function fetchMono({ monoId }: { monoId: MonoId }) {
matchHTML = HTML.match(/<\/h2><ul class="groupsLine">(.+?)<\/ul>/)
if (matchHTML) {
const $ = cheerio(matchHTML[1])
$('li.clearit').each((index: number, element: any) => {
$('li.clearit').each((_index: number, element: any) => {
const $row = cheerio(element)
const $a = $row.find('.innerWithAvatar .avatar')
mono.collected.push({
Expand All @@ -257,7 +257,7 @@ export async function fetchMono({ monoId }: { monoId: MonoId }) {
matchHTML = HTML.match(/<ul class="coversSmall">(.+?)<\/ul>/)
if (matchHTML) {
const $ = cheerio(matchHTML[1])
$('li.clearit').each((index: number, element: any) => {
$('li.clearit').each((_index: number, element: any) => {
const $row = cheerio(element)
const $a = $row.find('a.l')
mono.collabs.push({
Expand Down Expand Up @@ -285,7 +285,7 @@ export function cheerioSubjectFromHTML(html: string): SubjectFromHTML {
let relationsType: SubjectTypeValue

const disc = []
$('div.line_detail ul.line_list_music li').each((index: number, element: any) => {
$('div.line_detail ul.line_list_music li').each((_index: number, element: any) => {
const $row = cheerio(element)
if ($row.attr('class') === 'cat') {
disc.push(
Expand All @@ -306,7 +306,7 @@ export function cheerioSubjectFromHTML(html: string): SubjectFromHTML {
})

let type = ''
$('.nameSingle small.grey').each((index: number, element: any) => {
$('.nameSingle small.grey').each((_index: number, element: any) => {
type += cheerio(element).text().trim()
})

Expand All @@ -323,7 +323,7 @@ export function cheerioSubjectFromHTML(html: string): SubjectFromHTML {
}

const crtCounts = {}
$('#browserItemList li').each((index: number, element: any) => {
$('#browserItemList li').each((_index: number, element: any) => {
const $row = cheerio(element)
const id = String($row.find('a.avatar').attr('href')).replace('/character/', '')
const num =
Expand All @@ -342,7 +342,7 @@ export function cheerioSubjectFromHTML(html: string): SubjectFromHTML {
info,
tags:
$('div.subject_tag_section div.inner a.l')
.map((index: number, element: any) => {
.map((_index: number, element: any) => {
const $row = cheerio(element)
return safeObject({
name: $row.find('span').text().trim(),
Expand All @@ -352,7 +352,7 @@ export function cheerioSubjectFromHTML(html: string): SubjectFromHTML {
.get() || [],
relations:
$('div.content_inner ul.browserCoverMedium li')
.map((index: number, element: any) => {
.map((_index: number, element: any) => {
const $row = cheerio(element)
const $title = $row.find('a.title')
const id = matchSubjectId($title.attr('href'))
Expand Down Expand Up @@ -380,7 +380,7 @@ export function cheerioSubjectFromHTML(html: string): SubjectFromHTML {
},
comic:
$('div.subject_section ul.browserCoverSmall li')
.map((index: number, element: any) => {
.map((_index: number, element: any) => {
const $row = cheerio(element)
const $a = $row.find('a')
return safeObject({
Expand All @@ -392,7 +392,7 @@ export function cheerioSubjectFromHTML(html: string): SubjectFromHTML {
.get() || [],
like:
$('div.content_inner ul.coversSmall li')
.map((index: number, element: any) => {
.map((_index: number, element: any) => {
const $row = cheerio(element)
const $a = $row.find('a')
return safeObject({
Expand All @@ -404,7 +404,7 @@ export function cheerioSubjectFromHTML(html: string): SubjectFromHTML {
.get() || [],
who:
$('#subjectPanelCollect li')
.map((index: number, element: any) => {
.map((_index: number, element: any) => {
const $row = cheerio(element)
const $a = $row.find('a.avatar')
return safeObject({
Expand All @@ -423,7 +423,7 @@ export function cheerioSubjectFromHTML(html: string): SubjectFromHTML {
.get() || [],
catalog:
$('#subjectPanelIndex li')
.map((index: number, element: any) => {
.map((_index: number, element: any) => {
const $row = cheerio(element)
const $user = $row.find('small.grey a.avatar')
const $catalog = $row.find('.innerWithAvatar > a.avatar')
Expand Down Expand Up @@ -513,14 +513,14 @@ export function cheerioMonoWorks(html: string): MonoWorks {
return {
filters:
$('div.subjectFilter > ul.grouped')
.map((index: number, element: any) => {
.map((_index: number, element: any) => {
const $li = cheerio(element)
return safeObject({
title: $li.find('li.title').text().trim(),
data:
$li
.find('a.l')
.map((idx: number, el: any) => {
.map((_idx: number, el: any) => {
const $a = cheerio(el)
return safeObject({
title: $a.text().trim(),
Expand All @@ -533,7 +533,7 @@ export function cheerioMonoWorks(html: string): MonoWorks {
.get() || [],
list:
$('ul#browserItemList > li.item')
.map((index: number, element: any) => {
.map((_index: number, element: any) => {
const $li = cheerio(element)
return safeObject({
id: $li.find('a.cover').attr('href'),
Expand All @@ -544,7 +544,7 @@ export function cheerioMonoWorks(html: string): MonoWorks {
position:
$li
.find('span.badge_job')
.map((idx: number, el: any) => cheerio(el).text().trim())
.map((_idx: number, el: any) => cheerio(el).text().trim())
.get() || [],
score: $li.find('small.fade').text().trim(),
total: $li.find('span.tip_j').text().trim(),
Expand All @@ -568,14 +568,14 @@ export function cheerioMonoVoices(html: string): MonoVoices {
return {
filters:
$('div.subjectFilter > ul.grouped')
.map((index: number, element: any) => {
.map((_index: number, element: any) => {
const $li = cheerio(element)
return safeObject({
title: $li.find('li.title').text().trim(),
data:
$li
.find('a.l')
.map((idx: number, el: any) => {
.map((_idx: number, el: any) => {
const $a = cheerio(el)
return safeObject({
title: $a.text().trim(),
Expand All @@ -588,7 +588,7 @@ export function cheerioMonoVoices(html: string): MonoVoices {
.get() || [],
list:
$('ul.browserList > li.item')
.map((index: number, element: any) => {
.map((_index: number, element: any) => {
const $li = cheerio(element)
const $leftItem = $li.find('div.innerLeftItem')
return safeObject({
Expand All @@ -599,7 +599,7 @@ export function cheerioMonoVoices(html: string): MonoVoices {
subject:
$li
.find('ul.innerRightList > li')
.map((idx: number, el: any) => {
.map((_idx: number, el: any) => {
const $l = cheerio(el)
const $a = $l.find('h3 > a.l')
return safeObject({
Expand Down Expand Up @@ -628,7 +628,7 @@ export function cheerioRating(html: string): Rating {
dropped: 0
}
$('ul.secTab li')
.map((index: number, element: any) => {
.map((_index: number, element: any) => {
const text = cheerio(element).text()
const count = parseInt((text.match(/\d+/g) || [])[0]) || 0
if (text.includes('想')) {
Expand All @@ -648,7 +648,7 @@ export function cheerioRating(html: string): Rating {

const list =
$('#memberUserList li')
.map((index: number, element: any) => {
.map((_index: number, element: any) => {
const $li = cheerio(element)
const $user = $li.find('a.avatar')
const avatar = matchAvatar($li.find('.avatarNeue').attr('style'))
Expand Down Expand Up @@ -680,7 +680,7 @@ export function cheerioSubjectCatalogs(html: string): SubjectCatalogs {
return {
list:
$('li.tml_item')
.map((index: number, element: any) => {
.map((_index: number, element: any) => {
const $li = cheerio(element)
const $title = $li.find('h3 a.l')
const $user = $li.find('span.tip_j a.l')
Expand Down
11 changes: 8 additions & 3 deletions src/utils/html/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,21 @@ export function cheerio(
return cheerioRN(target)
}

/** cheerio.text().trim() */
/** HTMLDecode(cheerio.text().trim()) */
export function cText($el: any): string {
return $el.text().trim() || ''
return HTMLDecode($el.text().trim() || '')
}

/** cheerio.attr(key) */
export function cData($el: any, key: string): string {
export function cData($el: any, key: 'id' | 'style' | 'href' | 'onclick'): string {
return $el.attr(key) || ''
}

/** HTMLTrim(cheerio.html(key)) */
export function cHtml($el: any) {
return HTMLTrim($el.html() || '')
}

/** 去除字符串中所有链接 */
export function removeURLs(str: string = '') {
const urlRegex = /(https?:\/\/[^\s]+)/g
Expand Down
25 changes: 10 additions & 15 deletions src/utils/match/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ function match(

/** 匹配头像地址 */
export function matchAvatar(str: string = ''): Avatar {
return match(
str,
str =>
str.match(/background-image:url\('(.+?)'\)/)?.[1] ||
'//lain.bgm.tv/pic/user/s/icon.jpg',
'matchAvatar'
return (
match(
str,
str =>
str.match(/background-image:url\('(.+?)'\)/)?.[1] || '//lain.bgm.tv/pic/user/s/icon.jpg',
'matchAvatar'
) || ''
)
}

Expand All @@ -48,7 +49,7 @@ export function matchAvatar(str: string = ''): Avatar {
* @eg /user/123
*/
export function matchUserId(str: string = ''): string {
return match(str, str => str.substring(str.lastIndexOf('/') + 1), 'matchUserId')
return match(str, str => str.substring(str.lastIndexOf('/') + 1), 'matchUserId') || ''
}

/**
Expand Down Expand Up @@ -88,8 +89,7 @@ export function matchBgmUrl(str: string = '', returnAll: boolean = false) {
str,
str => {
const matchs =
str.match(/https?:\/\/(bangumi\.tv|bgm\.tv|chii\.in)((\w|=|\?|\.|\/|&|-)+)/g) ||
[]
str.match(/https?:\/\/(bangumi\.tv|bgm\.tv|chii\.in)((\w|=|\?|\.|\/|&|-)+)/g) || []
return returnAll ? matchs : matchs[0] || ''
},
`${matchBgmUrl}${returnAll ? 'returnAll' : ''}`,
Expand All @@ -99,12 +99,7 @@ export function matchBgmUrl(str: string = '', returnAll: boolean = false) {

/** 从头像地址匹配用户 Id */
export function matchUserIdFromAvatar(str: string = ''): UserId {
return match(
str,
str => str.match(/\/(\d+).jpg/)?.[1] || 0,
'matchUserIdFromAvatar',
0
)
return match(str, str => str.match(/\/(\d+).jpg/)?.[1] || 0, 'matchUserIdFromAvatar', 0)
}

/** 匹配年份 */
Expand Down

0 comments on commit 4e90265

Please sign in to comment.