I got sick of seeing 40 minute long videos on the dumbest things. Even if it is a topic I'm interested in the pacing of such a video makes it so not even 5 minutes of it are worth watching. All good youtube videos are under 20 minutes. Some of the code is mislabeled because I decided having the script tell youtube I'm not interested is a stretch goal and for the sake of the end user, simply hiding those videos is good enough.
// ==UserScript==
// @name Youtube long video remove
// @namespace Violentmonkey Scripts
// @match [https://www.youtube.com/](https://www.youtube.com/)*
// @grant none
// @version 1.0
// @author -
// @artwork [https://img.gvid.tv/i/3Bvv1H36.jpg](https://img.gvid.tv/i/3Bvv1H36.jpg)
// @description 11/29/2023, 6:23:59 PM
// ==/UserScript==
(function() {
'use strict';
function convertDurationToSeconds(text) {
return text.split(':')
.reverse()
.map((i, idx) => parseFloat(i) * Math.pow(60, idx))
.reduce((a, b) => a + b, 0);
}
function findAndHideLongVideos() {
var selectors = [
'ytd-compact-video-renderer.style-scope.ytd-item-section-renderer',
'div#content.style-scope.ytd-rich-item-renderer'
];
for(let selector of selectors) {
console.log("hello from long youtube")
const suggestions = document.querySelectorAll(selector);
console.log({selector,suggestions});
for (let suggestion of suggestions) {
let durationElement = suggestion.querySelector('div#time-status span#text');
if (durationElement) {
let durationSeconds = convertDurationToSeconds(durationElement.textContent.trim());
if (durationSeconds > 1200) { // 20 minutes
//Hide it
suggestion.style.display='none';
//[Todo] Tell youtube not interested
//Find and click the menu button
//let menuButton = suggestion.querySelector(/* selector for the menu button */);
//if (menuButton) menuButton.click();
//Wait for the menu to open and then click 'Not Interested'
//setTimeout(() => {
// let notInterestedButton = document.querySelector(/* selector for 'Not Interested' */);
// if (notInterestedButton) notInterestedButton.click();
//}, 500); // Adjust timeout as needed
}
}
}
}
}
// Run the function periodically
setInterval(findAndHideLongVideos, 1000); // Adjust interval as needed
})();
Also I made some artwork because that is absurdly easy now:
https://img.gvid.tv/i/3Bvv1H36.jpg