hallzy / remove-youtube-shorts Goto Github PK
View Code? Open in Web Editor NEWTamperMonkey Script to remove YouTube Shorts from the page.
TamperMonkey Script to remove YouTube Shorts from the page.
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,
}
);
}
)();
I think YouTube changed something, and now they don't get blocked anymore
With turned on this extension youtube trending list is empty.
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/*
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/";
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.