YouTube Add filename formatted title

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

Author
S M
Daily installs
0
Total installs
12
Ratings
0 0 0
Version
0.1
Created
2023-06-30
Updated
2023-06-30
License
MIT
Applies to

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.