This code is a **userscript** designed to remove auto-translations of...
September 3, 2025 at 10:34 AM
This code is a userscript designed to remove auto-translations of YouTube video titles and restore them to their original titles. Here is a breakdown of its functionality:
Primary Purpose
The userscript ensures that:
- YouTube video titles, which may have been localized or automatically translated based on the user's language settings, are reverted to their original, untranslated titles.
- Additionally, if viewing a specific video, its description is also restored to its original state.
Key Functionalities
-
Prompt for YouTube Data API Key:
- The script prompts the user to enter a YouTube Data API key, which it uses to fetch the original titles and descriptions through the YouTube API.
- If no valid API key is provided, certain features requiring the API will not work.
-
Monitoring Page Changes:
- The script tracks whether the webpage's URL or video changes (e.g., navigating from one video to another or scrolling to see recommended videos). When a change is detected, it resets state and processes new content.
-
Restoration of Titles for Videos on the Page:
- For all video links (like recommended videos, search results, etc.), the script:
- Extracts video IDs from their URLs.
- Fetches their original titles using the YouTube API (unless they are cached).
- Replaces the auto-translated or localized titles with their original titles.
- For all video links (like recommended videos, search results, etc.), the script:
-
Restoration of the Main Video Description:
- If viewing a specific video, it uses the YouTube API to fetch the original video description and updates the page to display the unaltered description, replacing any localized/auto-translated text.
-
Caching Titles:
- The script retains a cache (
cachedTitles
) of original titles from prior API calls, minimizing API requests and improving performance.
- The script retains a cache (
-
Error Handling:
- It retries operations if content changes dynamically (e.g., lazy-loaded content or re-rendering by YouTube).
- If the API key is invalid, it prompts the user to re-enter it.
-
Linkify Functionality:
- The script adds clickable links to URLs, email addresses, or timecodes found in video descriptions. For example:
- Timecodes (e.g.,
2:15
) are converted into clickable timestamps, allowing users to jump to those times in the current video.
- Timecodes (e.g.,
- The script adds clickable links to URLs, email addresses, or timecodes found in video descriptions. For example:
How it Works
-
Initialization:
- The script is injected into YouTube (
@match https://www.youtube.com/*
). - It ensures strict mode (
'use strict';
) for better performance and error detection. - It checks if a YouTube Data API key is stored. If not, it prompts the user to enter one.
- The script is injected into YouTube (
-
API Requests:
- A base API URL template (
url_template
) is prepared, which is used to fetch video details in bulk (up to 50 video IDs at a time) using the provided API key.
- A base API URL template (
-
Dynamic Handling of Page Content:
- The script continuously checks the page title, URL, and video elements.
- Based on the detected content, it updates the titles and description via DOM manipulation.
-
Rechecking:
- It sets timers to periodically recheck and update titles/descriptions if new content is dynamically loaded.
Specific Code Components
-
getVideoID:
- This function extracts the
video ID
(11-character unique identifier) from a given video link.
- This function extracts the
-
resetChanged:
- Resets the script's state when a page or video change is detected.
-
changeTitles:
- Core function that:
- Fetches original titles/descriptions.
- Replaces translated titles/descriptions with their authentic versions.
- Core function that:
-
linkify:
- Converts URLs, email addresses, and timecodes in video descriptions into clickable links.
Dependencies
GM_getValue
andGM_setValue
are used to store the API key locally (features of Greasemonkey/Tampermonkey browser extensions).XMLHttpRequest
for making API requests to the YouTube Data API.
Limitations
- Requires a valid YouTube Data API key to fetch original data.
- Restricted to 50 videos per API call.
- May not account for edge cases (e.g., private or deleted videos).
Outcome
The script dynamically monitors YouTube and reverts video titles and descriptions to their original, untranslated state for improved accuracy.
Generate your own explanations
Download our vscode extension
Read other generated explanations
Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node