Skip to content

Commit

Permalink
Merge pull request #107 from festoney8/dev
Browse files Browse the repository at this point in the history
merge dev to main, v3.9.1
  • Loading branch information
festoney8 authored Jul 15, 2024
2 parents 1efabde + 17a3b9f commit c353792
Show file tree
Hide file tree
Showing 15 changed files with 581 additions and 50 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## 3.9.1

- 新增:空间页 动态列表净化
- 新增:空间页 动态列表评论区净化
- 新增:空间页 评论过滤
- 优化:统一处理fetch相关功能

## 3.9.0

- 新增:播放页新版评论区 净化优化 适配测试
Expand Down
8 changes: 4 additions & 4 deletions src/components/contextmenu.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
margin-block-start: 0;
-webkit-margin-after: 0;
margin-block-end: 0;
-webkit-margin-start: 0px;
margin-inline-start: 0px;
-webkit-margin-end: 0px;
margin-inline-end: 0px;
-webkit-margin-start: 0;
margin-inline-start: 0;
-webkit-margin-end: 0;
margin-inline-end: 0;
-webkit-padding-start: 0;
padding-inline-start: 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/contextmenu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
ul {
margin-block-start: 0;
margin-block-end: 0;
margin-inline-start: 0px;
margin-inline-end: 0px;
margin-inline-start: 0;
margin-inline-end: 0;
padding-inline-start: 0;
}
li {
Expand Down
2 changes: 1 addition & 1 deletion src/components/panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
width: 25px;
height: 25px;
position: absolute;
top: 0px;
top: 0;
left: 0;
border-radius: 50px;
background-color: #fff;
Expand Down
2 changes: 1 addition & 1 deletion src/components/panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ $theme-color: rgb(0, 174, 236);
width: 25px;
height: 25px;
position: absolute;
top: 0px;
top: 0;
left: 0;
border-radius: 50px;
background-color: white;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Group } from '../../../components/group'
import { CheckboxItem, ButtonItem } from '../../../components/item'
import { debugCommentFilter as debug, error } from '../../../utils/logger'
import { isPageDynamic } from '../../../utils/pageType'
import { isPageDynamic, isPageSpace } from '../../../utils/pageType'
import { showEle, waitForEle } from '../../../utils/tool'
import { ContentAction, UsernameAction } from './actions/action'
import coreCommentFilterInstance, { CommentSelectorFunc } from '../filters/core'
Expand All @@ -22,7 +22,7 @@ let isPinnedCommentWhitelistEnable = false
let isNoteCommentWhitelistEnable = false
let isLinkCommentWhitelistEnable = false

if (isPageDynamic()) {
if (isPageDynamic() || isPageSpace()) {
let commentListContainer: HTMLElement
// 一级评论
const rootCommentSelectorFunc: CommentSelectorFunc = {
Expand Down
Empty file.
16 changes: 6 additions & 10 deletions src/filters/commentFilter/pages/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import coreCommentFilterInstance, { CommentSelectorFunc } from '../filters/core'
import settings from '../../../settings'
import { ContextMenu } from '../../../components/contextmenu'
import { unsafeWindow } from '$'
import fetchHook from '../../../utils/fetch'

const videoPageCommentFilterGroupList: Group[] = []

Expand Down Expand Up @@ -271,14 +272,13 @@ if (isPageVideo() || isPageBangumi() || isPagePlaylist()) {
}
}
/**
* hook fetch, 获取评论相关API时触发检测
* 新版评论区过滤
* 在获取评论相关API时触发检测
* 多层 Shadow DOM 套娃对MutationObserver不友好
* 切换视频会导致observe对象被替换
* 使用监听一级二级评论载入方法触发评论区检测
*/
// Todo: 统一全站fetch hook
const origFetch = unsafeWindow.fetch
unsafeWindow.fetch = async (input, init?) => {
fetchHook.addPostFn((input: RequestInfo | URL, init: RequestInit | undefined, _resp?: Response) => {
if (isCommentV2()) {
if (
typeof input === 'string' &&
Expand All @@ -287,29 +287,24 @@ if (isPageVideo() || isPageBangumi() || isPagePlaylist()) {
) {
// 主评论载入
if (input.includes('/v2/reply/wbi/main')) {
const resp = await origFetch(input, init)
setTimeout(() => checkV2(false), 100)
setTimeout(() => checkV2(false), 200)
setTimeout(() => checkV2(false), 500)
setTimeout(() => checkV2(false), 1000)
setTimeout(() => checkV2(false), 2000)
setTimeout(() => checkV2(false), 3000)
return resp
}
// 二级评论翻页
if (input.includes('/v2/reply/reply')) {
const resp = await origFetch(input, init)
setTimeout(() => checkV2(true), 100)
setTimeout(() => checkV2(true), 200)
setTimeout(() => checkV2(true), 500)
setTimeout(() => checkV2(true), 1000)
setTimeout(() => checkV2(true), 2000)
return resp
}
}
}
return origFetch(input, init)
}
})

// 配置 行为实例
const usernameAction = new UsernameAction(
Expand Down Expand Up @@ -339,6 +334,7 @@ if (isPageVideo() || isPageBangumi() || isPagePlaylist()) {
}

try {
// 旧版评论区过滤
waitForEle(document, '#comment, #comment-body, .playlist-comment', (node: HTMLElement): boolean => {
return ['comment', 'comment-body'].includes(node.id) || node.className === 'playlist-comment'
}).then((ele) => {
Expand Down
24 changes: 12 additions & 12 deletions src/filters/videoFilter/pages/popular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
UploaderKeywordAction,
UploaderWhitelistAction,
} from './actions/action'
import { unsafeWindow } from '$'
import fetchHook from '../../../utils/fetch'

const popularPageVideoFilterGroupList: Group[] = []

Expand All @@ -36,19 +36,19 @@ if (isPagePopular()) {
// 存储API中的视频数据, key为bvid
const videoInfoMap = new Map<string, VInfo>()

// hook fetch
// 获取api resp
let apiResp: Response | undefined = undefined
const origFetch = unsafeWindow.fetch
unsafeWindow.fetch = async (input, init?) => {
if (typeof input === 'string' && input.includes('api.bilibili.com') && init?.method?.toUpperCase() === 'GET') {
if (input.match(/web-interface\/(ranking|popular\/series\/one|popular\?ps)/)) {
const resp = await origFetch(input, init)
apiResp = resp.clone()
return resp
}
fetchHook.addPostFn((input: RequestInfo | URL, init: RequestInit | undefined, resp?: Response) => {
if (
typeof input === 'string' &&
input.includes('api.bilibili.com') &&
input.match(/web-interface\/(ranking|popular\/series\/one|popular\?ps)/) &&
init?.method?.toUpperCase() === 'GET' &&
resp
) {
apiResp = resp.clone()
}
return origFetch(input, init)
}
})

// 解析API数据,存入map
const parseResp = async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { searchPageVideoFilterGroupList } from './filters/videoFilter/pages/sear
import { channelPageVideoFilterGroupList } from './filters/videoFilter/pages/channel'
import { videoPageCommentFilterGroupList } from './filters/commentFilter/pages/video'
import { spacePageVideoFilterGroupList } from './filters/videoFilter/pages/space'
import { dynamicPageCommentFilterGroupList } from './filters/commentFilter/pages/dynamic'
import { dynamicPageCommentFilterGroupList } from './filters/commentFilter/pages/dynamicAndSpace'
import { watchlaterGroupList } from './rules/watchlater'
import { spaceGroupList } from './rules/space'
import { dynamicPageDynFilterGroupList } from './filters/dynFilter/pages/dynamic'
Expand Down Expand Up @@ -148,7 +148,7 @@ const main = async () => {
)
}

if (isPageVideo() || isPageBangumi() || isPagePlaylist() || isPageDynamic()) {
if (isPageVideo() || isPageBangumi() || isPagePlaylist() || isPageDynamic() || isPageSpace()) {
regIDs.push(
GM_registerMenuCommand('✅评论过滤设置', () =>
createPanelWithMode('commentFilter', COMMENT_FILTER_GROUPS),
Expand Down Expand Up @@ -188,7 +188,7 @@ const main = async () => {
)
}
}
if (isPageVideo() || isPageBangumi() || isPagePlaylist() || isPageDynamic()) {
if (isPageVideo() || isPageBangumi() || isPagePlaylist() || isPageDynamic() || isPageSpace()) {
const commentFilterSideBtnID = 'comment-filter-side-btn'
const sideBtn = new SideBtn(commentFilterSideBtnID, '评论过滤', () => {
panel.isShowing ? panel.hide() : createPanelWithMode('commentFilter', COMMENT_FILTER_GROUPS)
Expand Down
12 changes: 5 additions & 7 deletions src/rules/homepage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { unsafeWindow } from '$'
import { Group } from '../components/group'
import { CheckboxItem, NumberItem, RadioItem } from '../components/item'
import fetchHook from '../utils/fetch'
import { isPageHomepage } from '../utils/pageType'
import { debounce, waitForEle } from '../utils/tool'

Expand Down Expand Up @@ -492,10 +492,8 @@ if (isPageHomepage()) {
.container.is-version8 > .floor-single-card:has(.skeleton, .skeleton-item, .floor-skeleton) {
display: none;
}`,
enableFunc: async () => {
// hook fetch
const origFetch = unsafeWindow.fetch
unsafeWindow.fetch = async (input, init?) => {
enableFunc: () => {
fetchHook.addPreFn((input: RequestInfo | URL, init: RequestInit | undefined): RequestInfo | URL => {
if (
typeof input === 'string' &&
input.includes('api.bilibili.com') &&
Expand All @@ -504,8 +502,8 @@ if (isPageHomepage()) {
) {
input = input.replace('&ps=12&', '&ps=24&')
}
return origFetch(input, init)
}
return input
})
},
}),
// 启用 预加载下一屏
Expand Down
Loading

0 comments on commit c353792

Please sign in to comment.