Skip to content

Commit

Permalink
Merge pull request #138 from festoney8/dev
Browse files Browse the repository at this point in the history
merge dev to main, v3.11.3
  • Loading branch information
festoney8 authored Sep 24, 2024
2 parents 7af0320 + c9277c3 commit a80558a
Show file tree
Hide file tree
Showing 14 changed files with 995 additions and 708 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## 3.11.3

- 更新:播放页、番剧页、动态页新版评论区过滤触发策略
- 修复:番剧页 网页全屏/全屏滚动 视频位置bug

## 3.11.2

- 更新:播放页 评论区过滤
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@

</details>
<details>
<summary><b>备份 TamperMonkey 数据到云端</b></summary>
<summary><b>备份数据到云端</b></summary>
<br>

- 这一操作将备份 TamperMonkey 内所有脚本代码及其本地数据到云端
Expand All @@ -241,6 +241,18 @@

![](images/how-to-backup-to-cloud-drive.png)

</details>
<details>
<summary><b>复制 JSON 数据</b></summary>
<br>

- 可通过开启插件管理器的高级模式,复制脚本 JSON 数据,可用于保存或快速在另一设备导入
- 请勿在未知后果的情况下编辑 JSON 数据

![](images/how-to-edit-1.png)
![](images/how-to-edit-2.png)
![](images/how-to-edit-3.png)

</details>

## Ref
Expand Down
Binary file added images/how-to-edit-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/how-to-edit-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/how-to-edit-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
545 changes: 316 additions & 229 deletions src/filters/comment/dyn.ts

Large diffs are not rendered by default.

225 changes: 124 additions & 101 deletions src/filters/comment/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Group } from '../../components/group'
import { ButtonItem, CheckboxItem, NumberItem } from '../../components/item'
import { WordList } from '../../components/wordlist'
import settings from '../../settings'
import fetchHook from '../../utils/fetch'
import { debugCommentFilter as debug, error } from '../../utils/logger'
import { isPageSpace } from '../../utils/pageType'
import { showEle, waitForEle } from '../../utils/tool'
Expand Down Expand Up @@ -41,6 +42,9 @@ const GM_KEYS = {
callUser: {
statusKey: 'dynamic-comment-call-user-filter-status',
},
isAD: {
statusKey: 'video-comment-ad-filter-status',
},
},
white: {
root: {
Expand All @@ -64,6 +68,85 @@ const GM_KEYS = {
},
}

// 一二级评论信息提取
const selectorFns = {
// 测试视频:
// https://b23.tv/av810872
// https://b23.tv/av1855797296
// https://b23.tv/av1706101190
// https://b23.tv/av1705573085
// https://b23.tv/av1350214762
root: {
username: (comment: HTMLElement): SelectorResult => {
return comment.querySelector('.root-reply-container .user-name')?.textContent?.trim()
},
content: (comment: HTMLElement): SelectorResult => {
return comment
.querySelector('.root-reply-container .reply-content')
?.textContent?.trim()
.replace(/@[^@ ]+?( |$)/g, '')
.trim()
},
callUser: (comment: HTMLElement): SelectorResult => {
return comment
.querySelector('.root-reply-container .reply-content .jump-link.user')
?.textContent?.replace('@', '')
.trim()
},
level: (comment: HTMLElement): SelectorResult => {
const c = comment.querySelector('.root-reply-container .user-level')?.className
const lv = c?.match(/level-([1-6])/)?.[1] // 忽略level-hardcore
return lv ? parseInt(lv) : undefined
},
isUp: (comment: HTMLElement): SelectorResult => {
return !!comment.querySelector('.root-reply-container .up-icon')
},
isPin: (comment: HTMLElement): SelectorResult => {
return !!comment.querySelector('.root-reply-container .top-icon')
},
isNote: (comment: HTMLElement): SelectorResult => {
return !!comment.querySelector('.root-reply-container .note-prefix')
},
isLink: (comment: HTMLElement): SelectorResult => {
return !!comment.querySelector('.root-reply-container .jump-link:is(.normal, .video)')
},
},
sub: {
username: (comment: HTMLElement): SelectorResult => {
return comment.querySelector('.sub-user-name')?.textContent?.trim()
},
content: (comment: HTMLElement): SelectorResult => {
return comment
.querySelector('.reply-content')
?.textContent?.trim()
?.replace(/@[^@ ]+?( |$)/g, '')
.replace(/^回复 *:?/, '')
.trim()
},
callUser: (comment: HTMLElement): SelectorResult => {
return comment
.querySelector('.reply-content')
?.textContent?.trim()
.replace(/^回复 ?@[^@ ]+? ?:/, '')
.trim()
?.match(/@[^@ ]+( |$)/)?.[0]
.replace('@', '')
.trim()
},
level: (comment: HTMLElement): SelectorResult => {
const c = comment.querySelector('.sub-user-level')?.className
const lv = c?.match(/level-([1-6])/)?.[1] // 忽略level-hardcore
return lv ? parseInt(lv) : undefined
},
isUp: (comment: HTMLElement): SelectorResult => {
return !!comment.querySelector('.sub-up-icon')
},
isLink: (comment: HTMLElement): SelectorResult => {
return !!comment.querySelector('.sub-reply-content .jump-link:is(.normal, .video)')
},
},
}

const spacePageCommentFilterGroupList: Group[] = []

// 右键菜单功能
Expand Down Expand Up @@ -142,85 +225,6 @@ if (isPageSpace()) {
const commentIsNoteFilter = new CommentIsNoteFilter()
const commentIsLinkFilter = new CommentIsLinkFilter()

// 一二级评论信息提取
const selectorFns = {
// 测试视频:
// https://b23.tv/av810872
// https://b23.tv/av1855797296
// https://b23.tv/av1706101190
// https://b23.tv/av1705573085
// https://b23.tv/av1350214762
root: {
username: (comment: HTMLElement): SelectorResult => {
return comment.querySelector('.root-reply-container .user-name')?.textContent?.trim()
},
content: (comment: HTMLElement): SelectorResult => {
return comment
.querySelector('.root-reply-container .reply-content')
?.textContent?.trim()
.replace(/@[^@ ]+?( |$)/g, '')
.trim()
},
callUser: (comment: HTMLElement): SelectorResult => {
return comment
.querySelector('.root-reply-container .reply-content .jump-link.user')
?.textContent?.replace('@', '')
.trim()
},
level: (comment: HTMLElement): SelectorResult => {
const c = comment.querySelector('.root-reply-container .user-level')?.className
const lv = c?.match(/level-([1-6])/)?.[1] // 忽略level-hardcore
return lv ? parseInt(lv) : undefined
},
isUp: (comment: HTMLElement): SelectorResult => {
return !!comment.querySelector('.root-reply-container .up-icon')
},
isPin: (comment: HTMLElement): SelectorResult => {
return !!comment.querySelector('.root-reply-container .top-icon')
},
isNote: (comment: HTMLElement): SelectorResult => {
return !!comment.querySelector('.root-reply-container .note-prefix')
},
isLink: (comment: HTMLElement): SelectorResult => {
return !!comment.querySelector('.root-reply-container .jump-link:is(.normal, .video)')
},
},
sub: {
username: (comment: HTMLElement): SelectorResult => {
return comment.querySelector('.sub-user-name')?.textContent?.trim()
},
content: (comment: HTMLElement): SelectorResult => {
return comment
.querySelector('.reply-content')
?.textContent?.trim()
?.replace(/@[^@ ]+?( |$)/g, '')
.replace(/^回复 *:?/, '')
.trim()
},
callUser: (comment: HTMLElement): SelectorResult => {
return comment
.querySelector('.reply-content')
?.textContent?.trim()
.replace(/^回复 ?@[^@ ]+? ?:/, '')
.trim()
?.match(/@[^@ ]+( |$)/)?.[0]
.replace('@', '')
.trim()
},
level: (comment: HTMLElement): SelectorResult => {
const c = comment.querySelector('.sub-user-level')?.className
const lv = c?.match(/level-([1-6])/)?.[1] // 忽略level-hardcore
return lv ? parseInt(lv) : undefined
},
isUp: (comment: HTMLElement): SelectorResult => {
return !!comment.querySelector('.sub-up-icon')
},
isLink: (comment: HTMLElement): SelectorResult => {
return !!comment.querySelector('.sub-reply-content .jump-link:is(.normal, .video)')
},
},
}

// 检测评论列表
const checkCommentList = async (fullSite: boolean) => {
if (location.host === 'space.bilibili.com' && !location.pathname.includes('/dynamic')) {
Expand Down Expand Up @@ -329,28 +333,6 @@ if (isPageSpace()) {
}
}

// // 评论区过滤,新旧通用,在获取评论相关API后触发检测
// fetchHook.addPostFn((input: RequestInfo | URL, init: RequestInit | undefined, _resp?: Response) => {
// if (typeof input === 'string' && init?.method?.toUpperCase() === 'GET' && input.includes('api.bilibili.com')) {
// // 主评论载入
// if (input.includes('/v2/reply/wbi/main')) {
// let cnt = 0
// const id = setInterval(() => {
// check(false)
// ++cnt > 30 && clearInterval(id)
// }, 100)
// }
// // 二级评论翻页
// if (input.includes('/v2/reply/reply')) {
// let cnt = 0
// const id = setInterval(() => {
// check(false)
// ++cnt > 15 && clearInterval(id)
// }, 200)
// }
// }
// })

// 右键监听函数, 屏蔽评论用户
const contextMenuFunc = () => {
if (isContextMenuFuncRunning) {
Expand Down Expand Up @@ -555,6 +537,47 @@ if (isPageSpace()) {
check(true)
},
}),
// 过滤 带货评论
new CheckboxItem({
itemID: GM_KEYS.black.isAD.statusKey,
description: '过滤 带货评论 (实验功能 需刷新)',
enableFunc: () => {
fetchHook.addPostFn(
async (
input: RequestInfo | URL,
init: RequestInit | undefined,
resp?: Response,
): Promise<Response | void> => {
if (!resp) {
return
}
if (
typeof input === 'string' &&
init?.method?.toUpperCase() === 'GET' &&
input.includes('api.bilibili.com/x/v2/reply/wbi/main')
) {
try {
const respData = await resp.clone().json()
const msg = respData?.data?.top?.upper?.content?.message
if (msg && /b23\.tv\/mall-|领券|gaoneng\.bilibili\.com/.test(msg)) {
respData.data.top = null
respData.data.top_replies = null
const newResp = new Response(JSON.stringify(respData), {
status: resp.status,
statusText: resp.statusText,
headers: resp.headers,
})
return newResp
}
} catch {
return resp
}
return resp
}
},
)
},
}),
]
spacePageCommentFilterGroupList.push(new Group('comment-type-filter-group', '评论区 按类型过滤', typeItems))

Expand Down
Loading

0 comments on commit a80558a

Please sign in to comment.