YouTube Add filename formatted title

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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.