This code is a UserScript designed to customize the behavior...
June 30, 2025 at 11:11 PM
This code is a UserScript designed to customize the behavior of YouTube's homepage feed on desktop and mobile web browsers. It uses hardcoded logic to force the YouTube homepage feed into a fixed, reproducible order based on a seeded shuffle of video items, while categorizing them into predefined groups using specific keywords. Here's what the code does in detail:
1. General Overview
- This script uses the Tampermonkey or similar browser extension to run custom JavaScript code on YouTube pages. It modifies the layout of the homepage feed in a non-dynamic, static manner.
- By overriding the default YouTube behavior, the script eliminates YouTube's dynamic ordering (suggestions, algorithm-driven changes, etc.) and applies a predictable and user-defined order to the feed.
2. Key Features
- Keyword Categorization:
Videos on the homepage are categorized into predefined groups based on keywords that occur in video titles or channel names. For example:- The
CATEGORY_KEYWORDS
defines a group calledaudio_commentary
, matching keywords like "audio", "commentary", or "review". - Other videos unrelated to these keywords are placed into an "unmatched" group.
- The
- Seeded Shuffle for Order Control:
A seeded random number generator is utilized to shuffle the categorized video groups into a specific ordering. The seed ensures the shuffle is deterministic, yielding the same order every time. - Content Classification:
Videos are sorted into three groups:- "Prev Video Related Items" - Videos related to predefined hardcoded words.
- "Audio Commentary Items" - Videos matching
audio_commentary
keywords. - Unmatched Items - Videos that do not match any keywords.
- Custom Feed Distribution:
The code enforces a strict59/39/2
percent distribution for the groups:- 59% of videos are from the first category.
- 39% are from the second category.
- Remaining videos are randomly distributed.
- Caching:
Once an order is generated, it is cached (cachedItems
) and reapplied when revisiting the page to ensure the feed remains locked.
3. Functional Details
- Detecting YouTube Context:
Functions likeisWatchPage
andisMobile
detect whether the script is running on a video or mobile version of YouTube. However, these seem to have limited use since they are not heavily utilized in the script. - Feed Manipulation:
- After a 1-second delay, the homepage feed is located on the DOM using
getFeedContainer
. If not found, the script retries periodically. - The function
randomizeHomepageFeed
organizes and reshuffles the feed:- Extracts all video items (DOM nodes) from the feed.
- Filters and classifies videos based on keywords in their titles and channel names.
- Shuffles each group using the seeded shuffle algorithm.
- Enforces a fixed distribution and rebuilds the feed order using DOM manipulation, updating the page content.
- The final order is cached for subsequent use.
- After a 1-second delay, the homepage feed is located on the DOM using
4. Seeded Shuffle Implementation
- A simple seeded random function (
seededRandom
) ensures that the shuffle is repeatable given the same seed. This is used inshuffleArray
to rearrange video items deterministically.
5. Hardcoded Approach
- The script strongly relies on hardcoded logic:
- The keywords for categorization are explicitly defined (
audio
,commentary
, etc.). - A fixed seed value (
5958
) drives the shuffle. - There is no dynamic adaptation to new or unexpected content.
- The keywords for categorization are explicitly defined (
6. User Interaction
- The user does not need to interact directly; the script automatically triggers when the YouTube homepage loads.
- Logs in the developer console provide feedback such as the number of videos processed, categorized, and shuffled.
7. Limitations
- The script is narrowly tailored to YouTube's current HTML structure. If YouTube changes its DOM layout, the script will likely break.
- Keywords and logic are static, requiring manual updates to accommodate new content types or preferences.
- It does not account for infinite scrolling or dynamically loaded content — it only manipulates the initial set of videos on page load.
In Summary:
This script modifies YouTube's homepage feed by:
- Categorizing videos based on hardcoded keywords.
- Shuffling and displaying them in a predetermined order using a seeded random algorithm.
- Caching the results to "lock" the feed order.
It essentially overrides YouTube's algorithm to create a static, predictable, and user-controlled feed layout.
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