GithubHelp home page GithubHelp logo

hallzy / remove-youtube-shorts Goto Github PK

View Code? Open in Web Editor NEW
27.0 2.0 3.0 2 KB

TamperMonkey Script to remove YouTube Shorts from the page.

JavaScript 100.00%
remove shorts tampermonkey youtube youtube-shorts remove-youtube-shorts

remove-youtube-shorts's Issues

Does not work on the mobile version of YouTube

Thanks for the code, it's the only script I found that will remove the shorts completely, but apparently it doesn't work with the mobile versions, is there any change in these versions?
I changed these lines in header to test and it still doesn't work. Thank you very much!

// @match ://.youtube.com/*
// @exclude ://music.youtube.com/
// @exclude ://.music.youtube.com/*

Shorts still show

I think YouTube changed something, and now they don't get blocked anymore

Toggle Option

I added a toggle feature to your script, maybe you like it. (I'm not the best coder yet, so excuse bad habits )

(
    () =>
    {

        const sleep = (milliseconds) => {
            return new Promise(resolve => setTimeout(resolve, milliseconds));
        }

        const createToggleButton = () => {
            const buttonDiv = document.querySelector('div#end')
            const checkBox = document.createElement('input')
            checkBox.type = 'checkbox'
            checkBox.id = 'shortsToggle'
            checkBox.style.height = checkBox.style.width = '20px'
            checkBox.addEventListener('change', handleToggle)
            checkBox.checked = localStorage.getItem('hidden') != 'true'
            buttonDiv.insertBefore(checkBox, buttonDiv.firstChild)
        }


        const handleToggle = () => {
            const isToggled = document.getElementById('shortsToggle').checked
            isToggled ? localStorage.removeItem('hidden') : localStorage.setItem('hidden', 'true')
            toggleShorts(isToggled)
        }

        const toggleShorts = (isToggled) =>
        {
            Array
                .from(document.querySelectorAll(`a[href^="/shorts"]`))
                .forEach
            (
                a =>
                {
                    let parent = a.parentElement;

                    while (parent && (!parent.tagName.startsWith('YTD-') || parent.tagName === 'YTD-THUMBNAIL'))
                    {
                        parent = parent.parentElement;
                    }

                    if (parent)
                    {
                        parent.style.visibility = isToggled ? 'visible' : 'hidden'
                    }
                }
            )
            ;
        }
        createToggleButton()
        const loadLastChoice = async () => {
            const hidden = localStorage.getItem('hidden') != 'true'
            await sleep(1000)
            toggleShorts(hidden)
        }
        loadLastChoice()

        const observer = new MutationObserver(localStorage.getItem('hidden') != 'true');
        observer.observe
        (
            document,
            {
                childList:  true,
                subtree:    true,
            }
        );
    }
)();

Block shorts completely

HI, here is the code to block main page of shorts, pls add it if you think it is useful

const regex = /^https:\/\/www\.youtube\.com\/shorts.*/;
if (regex.test(window.location.href)) {
    window.location.href = "https://www.youtube.com/";
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.