YouTube Add filename formatted title

Adds and modifies an filename formatted title on Youtube above the normal one

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

作者
S M
日安装量
0
总安装量
12
评分
0 0 0
版本
0.1
创建于
2023-06-30
更新于
2023-06-30
大小
3.3 KB
许可证
MIT
适用于

YouTube Add Filename Formatted Title

This userscript aims to enhance the user experience on YouTube by adding an additional title to each video. It creates a new H2 element above the standard H1 element that YouTube uses for video titles.

The script automatically formats the new title to be suitable for use as a filename, replacing any characters that are invalid in filenames with dashes. This can be especially useful for users who download videos for offline use and want to retain the original title as a filename.

The script works on all pages of youtube.com, applying the changes whenever it detects a change in the H1 title of the video.

Code Breakdown

The script follows a simple structure and works as follows:

It initializes variables to keep track of the last H1 text, check counter, change counter, and interval ID.

It defines a function modifyElement that modifies the new H2 element to match the H1 element text but formatted for filename compatibility. The function also appends the username of the video uploader to the H2 element.

The function checkElements is defined to continuously check for changes in the H1 element. If it finds a change, it modifies the H2 element with the new title. The function also manages the checking frequency based on how often the title is changing.

The script sets up an interval to run the checkElements function every 2 seconds. Then reduces calls frequency after some time.