From ff4aee527d28e277dc7fb02a4e78257b55f2110d Mon Sep 17 00:00:00 2001 From: festoney8 Date: Wed, 1 May 2024 01:30:11 +0800 Subject: [PATCH 1/2] update: optimize code, fix typo --- CHANGELOG.md | 4 +++ src/filters/videoFilter/pages/channel.ts | 22 +++++-------- src/filters/videoFilter/pages/homepage.ts | 22 +++++-------- src/filters/videoFilter/pages/popular.ts | 38 ++++++----------------- src/filters/videoFilter/pages/search.ts | 18 ++++------- src/filters/videoFilter/pages/space.ts | 14 ++++----- src/filters/videoFilter/pages/video.ts | 21 +++++-------- vite.config.ts | 2 +- 8 files changed, 51 insertions(+), 90 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 962c3ef4..7c9a5277 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 3.5.1 + +- 修复:修复typo,优化代码 + ## 3.5.0 - 新增:热门/每周必看/排行榜页 时长过滤 diff --git a/src/filters/videoFilter/pages/channel.ts b/src/filters/videoFilter/pages/channel.ts index 7010eb81..d265c5f8 100644 --- a/src/filters/videoFilter/pages/channel.ts +++ b/src/filters/videoFilter/pages/channel.ts @@ -119,9 +119,7 @@ if (isPageChannel()) { // 监听视频列表内部变化, 有变化时检测视频列表 const watchVideoListContainer = () => { - if (videoListContainer) { - debug('watchVideoListContainer start') - // 初次全站检测 + const check = async (fillSite: boolean) => { if ( channelDurationAction.status || channelUploaderAction.status || @@ -129,19 +127,15 @@ if (isPageChannel()) { channelBvidAction.status || channelTitleKeywordAction.status ) { - checkVideoList(true) + checkVideoList(fillSite) } + } + if (videoListContainer) { + // 初次全站检测 + check(true) const videoObverser = new MutationObserver(() => { - if ( - channelDurationAction.status || - channelUploaderAction.status || - channelUploaderKeywordAction.status || - channelBvidAction.status || - channelTitleKeywordAction.status - ) { - // 增量检测 - checkVideoList(false) - } + // 增量检测 + check(false) }) videoObverser.observe(videoListContainer, { childList: true, subtree: true }) debug('watchVideoListContainer OK') diff --git a/src/filters/videoFilter/pages/homepage.ts b/src/filters/videoFilter/pages/homepage.ts index 0ea162e5..18e2b67d 100644 --- a/src/filters/videoFilter/pages/homepage.ts +++ b/src/filters/videoFilter/pages/homepage.ts @@ -152,8 +152,7 @@ if (isPageHomepage()) { // 监听视频列表内部变化, 有变化时检测视频列表 const watchVideoListContainer = () => { - if (videoListContainer) { - debug('watchVideoListContainer start') + const check = async (fullSite: boolean) => { if ( homepageDurationAction.status || homepageUploaderAction.status || @@ -161,20 +160,15 @@ if (isPageHomepage()) { homepageBvidAction.status || homepageTitleKeywordAction.status ) { - // 初次全站检测 - checkVideoList(true) + checkVideoList(fullSite) } + } + if (videoListContainer) { + // 初次全站检测 + check(true) const videoObverser = new MutationObserver(() => { - if ( - homepageDurationAction.status || - homepageUploaderAction.status || - homepageUploaderKeywordAction.status || - homepageBvidAction.status || - homepageTitleKeywordAction.status - ) { - // 增量检测 - checkVideoList(false) - } + // 增量检测 + check(false) }) videoObverser.observe(videoListContainer, { childList: true }) debug('watchVideoListContainer OK') diff --git a/src/filters/videoFilter/pages/popular.ts b/src/filters/videoFilter/pages/popular.ts index 5d67cb6c..23ecf554 100644 --- a/src/filters/videoFilter/pages/popular.ts +++ b/src/filters/videoFilter/pages/popular.ts @@ -229,8 +229,7 @@ if (isPagePopular()) { // 监听视频列表内部变化, 有变化时检测视频列表 const watchVideoListContainer = async () => { - if (videoListContainer) { - debug('watchVideoListContainer start') + const check = async (fullSite: boolean) => { if ( popularDurationAction.status || popularUploaderAction.status || @@ -240,36 +239,19 @@ if (isPagePopular()) { popularBvidAction.status || popularTitleKeywordAction.status ) { - // 初次全站检测 if (location.pathname.match(/\/v\/popular\/(?:all|rank|weekly)/)) { - if (popularDurationAction.status || popularQualityAction.status || popularDimensionAction) { - await parseResp() - } else { - parseResp() - } + popularDurationAction.status || popularQualityAction.status || popularDimensionAction.status + ? await parseResp() + : parseResp() } - checkVideoList(true) + checkVideoList(fullSite) } + } + + if (videoListContainer) { + check(true) const videoObverser = new MutationObserver(async () => { - if ( - popularDurationAction.status || - popularUploaderAction.status || - popularQualityAction.status || - popularDimensionAction.status || - popularUploaderKeywordAction.status || - popularBvidAction.status || - popularTitleKeywordAction.status - ) { - // 全量检测 - if (location.pathname.match(/\/v\/popular\/(?:all|rank|weekly)/)) { - if (popularDurationAction.status || popularQualityAction.status || popularDimensionAction) { - await parseResp() - } else { - parseResp() - } - } - checkVideoList(true) - } + check(true) }) videoObverser.observe(videoListContainer, { childList: true, subtree: true }) debug('watchVideoListContainer OK') diff --git a/src/filters/videoFilter/pages/search.ts b/src/filters/videoFilter/pages/search.ts index d3334d35..0d3b4471 100644 --- a/src/filters/videoFilter/pages/search.ts +++ b/src/filters/videoFilter/pages/search.ts @@ -123,8 +123,7 @@ if (isPageSearch()) { // 监听视频列表内部变化, 有变化时检测视频列表 const watchVideoListContainer = () => { - if (videoListContainer) { - debug('watchVideoListContainer start') + const check = async (fullSite: boolean) => { if ( searchDurationAction.status || searchUploaderAction.status || @@ -132,18 +131,13 @@ if (isPageSearch()) { searchBvidAction.status || searchTitleKeywordAction.status ) { - checkVideoList(true) + checkVideoList(fullSite) } + } + if (videoListContainer) { + check(true) const videoObverser = new MutationObserver(() => { - if ( - searchDurationAction.status || - searchUploaderAction.status || - searchUploaderKeywordAction.status || - searchBvidAction.status || - searchTitleKeywordAction.status - ) { - checkVideoList(true) - } + check(true) }) videoObverser.observe(videoListContainer, { childList: true, subtree: true }) debug('watchVideoListContainer OK') diff --git a/src/filters/videoFilter/pages/space.ts b/src/filters/videoFilter/pages/space.ts index 95092495..f4c81441 100644 --- a/src/filters/videoFilter/pages/space.ts +++ b/src/filters/videoFilter/pages/space.ts @@ -90,16 +90,16 @@ if (isPageSpace()) { // 监听视频列表内部变化, 有变化时检测视频列表 const watchVideoListContainer = () => { - if (videoListContainer) { - debug('watchVideoListContainer start') + const check = async (fullSite: boolean) => { if (spaceDurationAction.status || spaceBvidAction.status || spaceTitleKeywordAction.status) { - checkVideoList(true) + checkVideoList(fullSite) } + } + if (videoListContainer) { + check(true) const videoObverser = new MutationObserver(() => { - if (spaceDurationAction.status || spaceBvidAction.status || spaceTitleKeywordAction.status) { - // 全量检测 - checkVideoList(true) - } + // 全量检测 + check(true) }) videoObverser.observe(videoListContainer, { childList: true, subtree: true }) debug('watchVideoListContainer OK') diff --git a/src/filters/videoFilter/pages/video.ts b/src/filters/videoFilter/pages/video.ts index 463bc63a..eb9f1cd1 100644 --- a/src/filters/videoFilter/pages/video.ts +++ b/src/filters/videoFilter/pages/video.ts @@ -121,8 +121,7 @@ if (isPageVideo() || isPagePlaylist()) { // 监听视频列表内部变化, 有变化时检测视频列表 const watchVideoListContainer = () => { - if (videoListContainer) { - debug('watchVideoListContainer start') + const check = async (fullSite: boolean) => { if ( videoDurationAction.status || videoUploaderAction.status || @@ -130,21 +129,15 @@ if (isPageVideo() || isPagePlaylist()) { videoBvidAction.status || videoTitleKeywordAction.status ) { - // 播放页右栏载入慢, 始终做全站检测 - checkVideoList(true) + checkVideoList(fullSite) } + } + if (videoListContainer) { + check(true) const videoObverser = new MutationObserver(() => { - if ( - videoDurationAction.status || - videoUploaderAction.status || - videoUploaderKeywordAction.status || - videoBvidAction.status || - videoTitleKeywordAction.status - ) { - checkVideoList(true) - } + // 播放页右栏载入慢, 始终做全站检测 + check(true) }) - // 播放页需监听subtree videoObverser.observe(videoListContainer, { childList: true, subtree: true }) debug('watchVideoListContainer OK') } diff --git a/vite.config.ts b/vite.config.ts index eb452097..2f761323 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -8,7 +8,7 @@ export default defineConfig({ userscript: { name: 'bilibili 页面净化大师', namespace: 'http://tampermonkey.net/', - version: '3.5.0', + version: '3.5.1', description: '净化 B站/哔哩哔哩 页面,支持「精简功能、播放器净化、过滤视频、过滤评论、全站黑白名单」,提供 300+ 功能,定制自己的 B 站', author: 'festoney8', From b02fbf40d0c06ea20eaa146f15af7935650a48f7 Mon Sep 17 00:00:00 2001 From: festoney8 Date: Wed, 1 May 2024 03:57:52 +0800 Subject: [PATCH 2/2] update: quality calc params --- CHANGELOG.md | 1 + .../videoFilter/filters/subfilters/quality.ts | 18 +++++++++++++----- src/filters/videoFilter/pages/popular.ts | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c9a5277..426b871d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 3.5.1 +- 优化:视频质量计算参数 - 修复:修复typo,优化代码 ## 3.5.0 diff --git a/src/filters/videoFilter/filters/subfilters/quality.ts b/src/filters/videoFilter/filters/subfilters/quality.ts index 89bf150f..dbbbc26c 100644 --- a/src/filters/videoFilter/filters/subfilters/quality.ts +++ b/src/filters/videoFilter/filters/subfilters/quality.ts @@ -13,12 +13,20 @@ class QualityFilter implements IVideoSubFilter { this.threshold = threshold } - // 根据coinLikeRatio计算视频质量, 参数源于爬虫数据拟合 + /* + 根据coinLikeRatio计算视频质量 + 对爬虫数据中投币点赞比在热门视频中所在排名进行拟合(百分制,4PL Formula) + 保持Quality在5%~80%时的高拟合度 + + 热门(质量要求适中):f(x) = (-9.881-168.6)/(1+(x/0.3829)^0.6463)+168.6 + 排行榜(较低):h(x) = (-14.82-115.9)/(1+(x/0.05327)^0.6639)+115.9 + 每周必看(严格):p(x) = (1.534-173.4)/(1+(x/0.7463)^1.401)+173.4 + */ calcQuality = (ratio: number): number => { - const A = -1.201e1 - const B = 6.861e-1 - const C = 7.369e-2 - const D = 1.192e2 + const A = -9.881 + const B = 6.463e-1 + const C = 3.829e-1 + const D = 1.686e2 const ans = (A - D) / (1 + Math.pow(ratio / C, B)) + D return ans > 0 ? ans : 0 } diff --git a/src/filters/videoFilter/pages/popular.ts b/src/filters/videoFilter/pages/popular.ts index 23ecf554..4601b3bd 100644 --- a/src/filters/videoFilter/pages/popular.ts +++ b/src/filters/videoFilter/pages/popular.ts @@ -392,8 +392,8 @@ if (isPagePopular()) { }), new NumberItem({ itemID: popularQualityAction.valueKey, - description: '设定 劣质视频过滤百分比', - defaultValue: 20, + description: '劣质视频过滤百分比 (0~80%)', + defaultValue: 25, minValue: 0, maxValue: 80, disableValue: 0,