Last active
October 8, 2024 15:28
-
-
Save Anthonyg5005/858b7bebe588dc7012bded18405cd7d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name YouTube Shorts Blocker: My Attention Span's Last Hope | |
| // @namespace http://tampermonkey.net/ | |
| // @version 0.5 | |
| // @description Outsmart the algorithm. Restores your ability to watch single videos without falling into the Shorts abyss. | |
| // @author Gemini 1.5 Pro + Claude 3.5 Sonnet + GPT o4 | |
| // @match https://www.youtube.com/* | |
| // @grant none | |
| // ==/UserScript== | |
| // Make sure to have tampermonkey installed, if this was downloaded as a file then it's not installed/enabled | |
| (function() { | |
| 'use strict'; | |
| function getVideoIdFromShortsUrl(url) { | |
| try { | |
| const urlObj = new URL(url); | |
| if (urlObj.pathname.startsWith('/shorts/')) { | |
| return urlObj.pathname.split('/shorts/')[1].split('?')[0]; | |
| } else if (urlObj.searchParams.has('feature') && urlObj.searchParams.get('feature') === 'shorts') { | |
| return urlObj.searchParams.get('v'); | |
| } | |
| } catch (e) { | |
| console.error("Error parsing URL:", e); | |
| } | |
| return null; | |
| } | |
| function redirectShorts() { | |
| const videoId = getVideoIdFromShortsUrl(window.location.href); | |
| if (videoId && window.location.pathname.startsWith('/shorts/')) { | |
| history.replaceState(null, '', `https://www.youtube.com/watch?v=${videoId}`); | |
| window.dispatchEvent(new PopStateEvent('popstate')); | |
| } | |
| } | |
| function convertShortLinks(links) { | |
| links.forEach(link => { | |
| const videoId = getVideoIdFromShortsUrl(link.href); | |
| if (videoId && link.href !== `https://www.youtube.com/watch?v=${videoId}`) { | |
| link.href = `https://www.youtube.com/watch?v=${videoId}`; | |
| } | |
| }); | |
| } | |
| function handlePageUpdates() { | |
| redirectShorts(); | |
| convertShortLinks(document.querySelectorAll('a[href*="/shorts/"], a[href*="&feature=shorts"]')); | |
| } | |
| // Initial check | |
| handlePageUpdates(); | |
| // Observe changes in the DOM with throttling | |
| let timeout; | |
| const observer = new MutationObserver(() => { | |
| clearTimeout(timeout); | |
| timeout = setTimeout(handlePageUpdates, 100); | |
| }); | |
| observer.observe(document, { childList: true, subtree: true }); | |
| // Handle YouTube's history API usage | |
| const originalPushState = history.pushState; | |
| history.pushState = function() { | |
| originalPushState.apply(this, arguments); | |
| handlePageUpdates(); | |
| }; | |
| window.addEventListener('popstate', handlePageUpdates); | |
| window.addEventListener('yt-navigate-finish', handlePageUpdates); | |
| })(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
click on
Rawif you have tampermoney installedI just let gemini, claude, and gpt work together to create this, with gemini creating the name and description