Skip to content

Commit 7f10aff

Browse files
committed
feat: 清理网页标题中多余的Youtube字符以及修复截图功能
1 parent aed5dc9 commit 7f10aff

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

youtube-helper/AUTHORS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--482387,521538,529134-->
1+
<!--482387,521538,529134,555384-->
22
<!--AUTHORS-->
33
## 💖 脚本参考或使用了以下脚本:
44
[🧑‍💻 **@bernzrdo**](https://greasyfork.org/users/1207477) ⇒ 📜 _[YouTube Screenshot](https://greasyfork.org/scripts/482387)_<br>

youtube-helper/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# **🛠️ youtube-helper 更新日志**
22

3+
### **📅 2026.3.20.1**
4+
5+
**新增**: 清理网页标题中多余的`Youtube`<br>
6+
**修复**: 修复截图功能<br>
7+
8+
---
9+
310
### **📅 2025.03.15.0436**
411
**新增**: •初始版本.
512

youtube-helper/youtube-helper.user.js

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
// @compatible qq
9898
// @compatible via
9999
// @compatible brave
100-
// @version 2025.03.15.0436
100+
// @version 2026.3.20.1
101101
// @grant GM_addStyle
102102
// @created 2025-03-14 20:36:01
103103
// @modified 2025-03-14 20:36:01
@@ -111,18 +111,14 @@
111111
* File Created: 2025/03/15,Saturday 04:36:02
112112
* Author: 人民的勤务员@ChinaGodMan (china.qinwuyuan@gmail.com)
113113
* -----
114-
* Last Modified: 2025/03/15,Saturday 05:57:23
114+
* Last Modified: 2026/03/20,Friday 02:00:54
115115
* Modified By: 人民的勤务员@ChinaGodMan (china.qinwuyuan@gmail.com)
116116
* -----
117117
* License: MIT License
118-
* Copyright © 2024 - 2025 ChinaGodMan,Inc
118+
* Copyright © 2024 - 2026 ChinaGodMan,Inc
119119
*/
120120
const directDownload = true
121-
const infiniteLool = true
122-
123-
124-
125-
121+
const infiniteLool = false
126122

127123
const loopVideo = () => {
128124
const video = document.querySelector('video')
@@ -139,8 +135,8 @@ let escapeHTMLPolicy = 'trustedTypes' in window
139135
? trustedTypes.createPolicy('forceInner', { createHTML: html => html })
140136
: { createHTML: html => html }
141137
function screenBtnUpdate() {
142-
let $miniplayerBtn = document.querySelector('button.ytp-miniplayer-button')
143-
if ($miniplayerBtn && !document.getElementById('ytp-screenshot-button')) {
138+
let $settingsButton = document.querySelector('button.ytp-settings-button')
139+
if ($settingsButton && !document.getElementById('ytp-screenshot-button')) {
144140
const $btn = document.createElement('button')
145141
$btn.id = 'ytp-screenshot-button'
146142
$btn.classList.add('ytp-screenshot-button', 'ytp-button')
@@ -149,15 +145,18 @@ function screenBtnUpdate() {
149145
$btn.dataset.titleNoTooltip = 'Screenshot'
150146
$btn.ariaLabel = 'Screenshot'
151147
$btn.title = 'Screenshot'
152-
$btn.innerHTML = escapeHTMLPolicy.createHTML(`<svg height="100%" version="1.1" viewBox="-300 -1260 1560 1560" width="100%">
153-
<use class="ytp-svg-shadow" xlink:href="#ytp-id-screenshot-svg"></use>
154-
<path
155-
d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm40-80h480L570-480 450-320l-90-120-120 160Zm-40 80v-560 560Z"
156-
fill="#fff" id="ytp-id-screenshot-svg"></path>
148+
$btn.innerHTML = escapeHTMLPolicy.createHTML(`<svg fill="none" height="24" viewBox="0 0 24 24" width="24">
149+
<path d="M4 5H20C21.1 5 22 5.9 22 7V18C22 19.1 21.1 20 20 20H4C2.9 20 2 19.1 2 18V7C2 5.9 2.9 5 4 5Z" stroke="white" stroke-width="1.5" fill="none"/>
150+
<circle cx="12" cy="12.5" r="4" stroke="white" stroke-width="1.5" fill="none"/>
151+
<circle cx="12" cy="12.5" r="2" fill="white" opacity="0.9"/>
152+
<circle cx="18" cy="9" r="1.2" fill="white"/>
153+
<path d="M12 9.5V15.5 M9 12.5H15" stroke="white" stroke-width="1" opacity="0.6"/>
154+
<circle cx="6.5" cy="9.5" r="0.8" stroke="white" stroke-width="1" fill="none"/>
155+
<circle cx="6.5" cy="9.5" r="0.3" fill="white"/>
157156
</svg>`)
158157
$btn.addEventListener('click', screenshot)
159158

160-
insertBefore($btn, $miniplayerBtn)
159+
insertBefore($btn, $settingsButton)
161160
}
162161

163162
requestAnimationFrame(screenBtnUpdate)
@@ -166,7 +165,6 @@ function insertBefore($element, $sibling) {
166165
$sibling.parentElement.insertBefore($element, $sibling)
167166
}
168167
function screenshot() {
169-
170168
const $video = document.querySelector('#player video')
171169
if (!$video) {
172170
console.error('No video found to screenshot!')
@@ -217,3 +215,21 @@ if (infiniteLool) {
217215

218216
requestAnimationFrame(screenBtnUpdate)
219217
ThemeProgressbar()
218+
219+
/**
220+
* 清理标题
221+
*/
222+
function cleanTitle() {
223+
setTimeout(() => {
224+
let title = document.title
225+
// Remove notification count e.g. "(7) Video name"
226+
title = title.replace(/^\(\d+\)\s*/g, '')
227+
// Remove " - YouTube" at the end of the title
228+
title = title.replace(/\s*-\s*YouTube\s*$/i, '')
229+
230+
document.title = title
231+
}, 300) // small delay to ensure YouTube updates title first
232+
}
233+
cleanTitle()
234+
const cleanTitleObserver = new MutationObserver(cleanTitle)
235+
cleanTitleObserver.observe(document.querySelector('title'), { childList: true })

0 commit comments

Comments
 (0)