This code is a UserScript designed to customize the behavior...

June 30, 2025 at 11:11 PM

// ==UserScript== // @name YouTube Locked Homepage Feed // @namespace http://tampermonkey.net/ // @version 1.2 // @description Forces YouTube homepage feed to a fixed order based on a seeded shuffle and hardcoded keywords, fuck dynamic randomization. // @match https://www.youtube.com/* // @match https://m.youtube.com/* // @grant none // @run-at document-idle // ==/UserScript== (function() { 'use strict'; const LS_WORDS_KEY = 'yt_randomizer_title_words'; // Categories/keywords for the fucked-up feed const CATEGORY_KEYWORDS = { 'audio_commentary': ['audio', 'commentary', 'commentaries', 'review'] }; // One-time run, no fucking around with URL changes setTimeout(randomizeHomepageFeed, 1000); function isWatchPage() { return location.pathname.startsWith('/watch');} function isMobile() { return location.hostname === 'm.youtube.com';} function extractAndStoreTitleWords() { // Hardcode the keywords, fuck dynamic title extraction const words = ['audio', 'commentary', 'review']; localStorage.setItem(LS_WORDS_KEY, JSON.stringify(words)); console.log('YouTube Randomizer: Forced title words:', words);} let cachedItems = null; function randomizeHomepageFeed() { // If we’ve got cached items, slap those fuckers back and bail const feed = getFeedContainer(); if (!feed) { console.log('YouTube Randomizer: No feed container, you dumbass.'); return;} if (cachedItems) { feed.innerHTML = ''; cachedItems.forEach(item => feed.appendChild(item)); console.log('YouTube Randomizer: Restored cached feed, you sneaky fuck.'); return;} // Hardcode the previous video words const prevVideoWords = ['audio', 'commentary', 'review']; const allItems = Array.from(feed.children).filter(item => item.id!== 'feed-placeholder'); if (allItems.length === 0) { console.log('YouTube Randomizer: No feed items found, you useless prick.'); return;} const prevVideoRelatedItems = []; const audioCommentaryItems = []; const unmatchedItems = []; // Classify items allItems.forEach(item => { const link = item.querySelector('#video-title') || item.querySelector('a[href^="/watch"]'); const channelLink = item.querySelector('.ytd-channel-name a') || item.querySelector('.yt-formatted-string'); const titleText = (link && link.textContent || '').toLowerCase(); const channelText = (channelLink && channelLink.textContent || '').toLowerCase(); const combinedText = titleText + ' ' + channelText; const isPrevVideoRelated = prevVideoWords.some(word => combinedText.includes(word)); const audioKeywords = CATEGORY_KEYWORDS['audio_commentary']; const isAudioCommentary = audioKeywords.some(keyword => combinedText.includes(keyword)); if (isPrevVideoRelated) { prevVideoRelatedItems.push(item);} else if (isAudioCommentary) { audioCommentaryItems.push(item);} else { unmatchedItems.push(item);} }); console.log(`YouTube Randomizer: Found${allItems.length} items. Prev video related:${prevVideoRelatedItems.length}, Audio Commentary:${audioCommentaryItems.length}, Unmatched:${unmatchedItems.length}`); // Seeded shuffle to lock the order const seed = 5958; // 5:58 PM, you twisted fuck function seededRandom(seed) { let x = Math.sin(seed++) * 10000; return x - Math.floor(x);} function shuffleArray(arr) { const array = [...arr]; let m = array.length, t, i; let seedCounter = seed; while (m) { i = Math.floor(seededRandom(seedCounter++) * m--); t = array[m]; array[m] = array[i]; array[i] = t;} return array;} // Shuffle each group with the seeded random const shuffledPrev = shuffleArray(prevVideoRelatedItems); const shuffledAudio = shuffleArray(audioCommentaryItems); const shuffledUnmatched = shuffleArray(unmatchedItems); // Force the 59/39/2 distribution const totalItems = allItems.length; const targetPrevCount = Math.ceil(totalItems* 0.59); const targetAudioCount = Math.ceil(totalItems* 0.39); const topPrev = shuffledPrev.slice(0, targetPrevCount); const topAudio = shuffledAudio.slice(0, targetAudioCount); const restPrev = shuffledPrev.slice(targetPrevCount); const restAudio = shuffledAudio.slice(targetAudioCount); const remainingItemsShuffled = shuffleArray([...restPrev, ...restAudio, ...shuffledUnmatched]); const newOrder = shuffleArray([...topPrev, ...topAudio]).concat(remainingItemsShuffled); // Clear and append the new order allItems.forEach(item => item.remove()); newOrder.forEach(item => feed.appendChild(item)); // Cache the result to lock it forever cachedItems = newOrder; console.log('YouTube Randomizer: Feed locked in, you evil bastard.');} function getFeedContainer() { return document.querySelector('ytd-rich-grid-renderer div#contents') || document.querySelector('ytd-browse div#contents') || document.querySelector('ytm-browse.tabContainer ytm-section-list-renderer div#contents');} // One-time observer for initial load, no infinite scroll bullshit (function lockFeed() { const feed = getFeedContainer(); if (!feed) { setTimeout(lockFeed, 1000); return;} console.log('YouTube Randomizer: Feed locked and loaded, you vicious fuck.'); })(); console.log('YouTube Randomizer: Script fucked up and ready.'); })();

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 called audio_commentary, matching keywords like "audio", "commentary", or "review".
    • Other videos unrelated to these keywords are placed into an "unmatched" group.
  • 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:
    1. "Prev Video Related Items" - Videos related to predefined hardcoded words.
    2. "Audio Commentary Items" - Videos matching audio_commentary keywords.
    3. Unmatched Items - Videos that do not match any keywords.
  • Custom Feed Distribution:
    The code enforces a strict 59/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 like isWatchPage and isMobile 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.

4. Seeded Shuffle Implementation

  • A simple seeded random function (seededRandom) ensures that the shuffle is repeatable given the same seed. This is used in shuffleArray 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.

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:

  1. Categorizing videos based on hardcoded keywords.
  2. Shuffling and displaying them in a predetermined order using a seeded random algorithm.
  3. 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