Skip to content

Commit

Permalink
feat: add filter for bangumi
Browse files Browse the repository at this point in the history
  • Loading branch information
magicdawn committed May 13, 2024
1 parent 80532da commit dffb62c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
21 changes: 19 additions & 2 deletions src/components/ModalSettings/tab-panes/pane-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ export function TabPaneFilter() {
<CheckboxSettingItem
className={styles.row}
configKey='filterOutGotoTypePicture'
label='启用图文(动态 & 专栏)过滤'
tooltip={<>过滤掉图文推荐</>}
label='过滤图文类型推荐'
tooltip={
<>
过滤 <kbd>goto = picture</kbd> 的内容: 包括 (动态 & 专栏) 等
</>
}
disabled={!filterEnabled}
/>
<CheckboxSettingItem
Expand All @@ -105,6 +109,19 @@ export function TabPaneFilter() {
label='对「已关注」的图文启用过滤'
tooltip={<>默认不过滤「已关注」</>}
/>

<div className={styles.settingsGroupSubTitle}>影视</div>
<CheckboxSettingItem
className={styles.row}
configKey='filterOutGotoTypeBangumi'
label='过滤影视类型推荐'
tooltip={
<>
过滤 <kbd>goto = bangumi</kbd> 的内容: 包括 (番剧 / 电影 / 国创 / 纪录片) 等
</>
}
disabled={!filterEnabled}
/>
</div>

<div className='col'>
Expand Down
12 changes: 11 additions & 1 deletion src/components/VideoCard/process/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function filterRecItems(items: RecItemExtraType[], tab: ETabType) {
// just keep it
if (item.api === EApiType.Separator) return true

const { play, duration, recommendReason, goto, authorName, authorMid, title, bvid } =
const { play, duration, recommendReason, goto, authorName, authorMid, title, bvid, href } =
normalizeCardData(item)
const isFollowed = recommendReason === '已关注' || !!recommendReason?.endsWith('关注')

Expand All @@ -45,6 +45,7 @@ export function filterRecItems(items: RecItemExtraType[], tab: ETabType) {

const isVideo = goto === 'av'
const isPicture = goto === 'picture'
const isBangumi = goto === 'bangumi'
// console.log('filter: goto = %s', goto)

if (authorMid && blacklistIds.size) {
Expand Down Expand Up @@ -98,6 +99,7 @@ export function filterRecItems(items: RecItemExtraType[], tab: ETabType) {

if (isVideo) return filterVideo()
if (isPicture) return filterPicture()
if (isBangumi) return filterBangumi()

return true // just keep it

Expand Down Expand Up @@ -161,5 +163,13 @@ export function filterRecItems(items: RecItemExtraType[], tab: ETabType) {
return true
}
}

function filterBangumi() {
if (settings.filterOutGotoTypeBangumi) {
debug('filter out by goto-type-bangumi-rule: %s %o', goto, { title, href })
return false
}
return true
}
})
}
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import '$components/ModalSettings/index.module.scss'
import '$components/VideoCard/index.module.scss'
import '$components/video-grid.module.scss'

// load config first
import './modules/settings'

// dayjs setup
import dayjs from 'dayjs'
import duration from 'dayjs/plugin/duration'
dayjs.extend(duration)

// load config first
import './modules/settings'

import { IN_BILIBILI_HOMEPAGE, IN_BILIBILI_VIDEO_PLAY_PAGE } from '$common'
import { initHomepage } from '$main/homepage'
import { initVideoPlayPage } from '$main/video-play-page'
Expand Down
3 changes: 3 additions & 0 deletions src/modules/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ export const initialSettings = {
// 图文也是有 rcmd_reason = '已关注' 的
enableFilterForFollowedPicture: false,

// filter out whose goto = 'bangumi'
filterOutGotoTypeBangumi: false,

// authorName
filterByAuthorNameEnabled: false,
filterByAuthorNameKeywords: [] as string[],
Expand Down

0 comments on commit dffb62c

Please sign in to comment.