From dd3955103eac8efd31add21b4a439ea4a9a9b383 Mon Sep 17 00:00:00 2001 From: festoney8 Date: Wed, 3 Jan 2024 03:52:51 +0800 Subject: [PATCH] feat: simple share fit watchlater and favlist --- CHANGELOG.md | 2 +- src/pages/common.ts | 6 +++--- src/pages/video.ts | 26 ++++++++++++++++++-------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f284057..e573af6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 2.2.2 - 新增:顶栏 稍后再看相关选项 -- 新增:评论区规则适配稍后再看页面、收藏夹页面 +- 新增:评论区规则、净化分享适配稍后再看页面、收藏夹页面 - 优化:首页 隐藏下载桌面端弹窗 改为默认开启 - 优化:全屏下隐藏弹幕输入框,完整展示章节名 - 优化:用户开启开关时执行功能函数 diff --git a/src/pages/common.ts b/src/pages/common.ts index e296a0a8..47ff7e8b 100644 --- a/src/pages/common.ts +++ b/src/pages/common.ts @@ -707,7 +707,7 @@ if (location.host != 'live.bilibili.com') { headerRightItems.push( new NormalItem( 'common-hide-nav-favorite', - '隐藏 收藏, 隐藏 稍后再看', + '隐藏 收藏,隐藏 稍后再看', false, undefined, false, @@ -724,7 +724,7 @@ if (location.host != 'live.bilibili.com') { headerRightItems.push( new NormalItem( 'common-hide-nav-favorite-keep-watchlater', - '隐藏 收藏, 保留 稍后再看(实验性)', + '隐藏 收藏,显示 稍后再看(实验性)', false, undefined, false, @@ -750,7 +750,7 @@ if (location.host != 'live.bilibili.com') { headerRightItems.push( new NormalItem( 'common-nav-keep-watchlater', - '显示 收藏, 显示 稍后再看(实验性)', + '显示 收藏,显示 稍后再看(实验性)', false, undefined, false, diff --git a/src/pages/video.ts b/src/pages/video.ts index 6073d8c7..102dacc5 100644 --- a/src/pages/video.ts +++ b/src/pages/video.ts @@ -62,20 +62,26 @@ function simpleShare() { // 新增click事件 // 若replace element, 会在切换视频后无法更新视频分享数量, 故直接新增click事件覆盖剪贴板 shareBtn.addEventListener('click', () => { - let title = document.querySelector('#viewbox_report > h1')?.textContent as string + let title = document.querySelector('#viewbox_report > h1')?.textContent + if (!title) { + // 尝试稍后再看or收藏夹列表 + title = document.querySelector('.video-title-href')?.textContent + if (!title) { + return + } + } if ( !'(({【[[《「<{〔〖<〈『'.includes(title[0]) && !'))}】]]》」>}〕〗>〉』'.includes(title.slice(-1)) ) { title = `【${title}】` } - let urlPath = location.pathname - if (urlPath.endsWith('/')) { - urlPath = urlPath.slice(0, -1) - } + // 匹配av号, BV号, 分P号 + const pattern = /av\d+|BV[1-9A-HJ-NP-Za-km-z]+/g + const avbv = pattern.exec(location.href) + let shareText = `${title} \nhttps://www.bilibili.com/video/${avbv}` const urlObj = new URL(location.href) const params = new URLSearchParams(urlObj.search) - let shareText = `${title} \nhttps://www.bilibili.com${urlPath}` if (params.has('p')) { shareText += `?p=${params.get('p')}` } @@ -759,7 +765,9 @@ if ( false, undefined, false, - `#v_desc {display: none !important;}`, + `#v_desc {display: none !important;} + /* 收藏夹和稍后再看 */ + .video-desc-container {display: none !important;}`, ), ) // 隐藏 tag列表 @@ -770,7 +778,9 @@ if ( false, undefined, false, - `#v_tag {display: none !important;}`, + `#v_tag {display: none !important;} + /* 收藏夹和稍后再看 */ + .video-tag-container {display: none !important;}`, ), ) // 隐藏 活动宣传, 默认开启