×
Login Register an account
Top Submissions Explore Upgoat Search Random Subverse Random Post Colorize! Site Rules
5

I made a userscript to block youtube suggestions over 20 minutes long

submitted by soupnazi to alttech 5 monthsNov 29, 2023 18:53:22 ago (+5/-0)     (alttech)

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/
// @grant none
// @version 1.0
// @author -
// @description 11/29/2023, 6:23:59 PM
// /UserScript

// UserScript
// @name YouTube Auto 'Not Interested' for Long Videos
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Automatically mark long videos as 'Not Interested' on YouTube
// @author YourName
// @match ://youtube.com/
// @grant none
// /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';
//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

})();
```


4 comments block


[ - ] soupnazi [op] 2 points 5 monthsNov 29, 2023 18:54:30 ago (+2/-0)*

Sorry about the formatting. That about as good as formatting is going to look on voat.

It's better formatted here: https://matrix.gvid.tv/c/userscripts/54MdRDve8X

[ - ] OftenWrong 1 point 5 monthsNov 29, 2023 19:38:11 ago (+1/-0)

I generally agree. Unless it is a high effort lecture most things are dragged out. Even most 20 minute videos could just be 5 minutes long

[ - ] Niggly_Puff 0 points 5 monthsNov 29, 2023 21:15:58 ago (+0/-0)

Can you make a script to block mr beast videos so I can stop seeing that stupid fucking soy face everytime I visit the site?

[ - ] soupnazi [op] 0 points 5 monthsNov 29, 2023 22:18:24 ago (+0/-0)

Yes. But actually while I was looking to see if someone already made this I saw someone else already made that.

https://raw.githubusercontent.com/Schegge/Userscripts/master/Block%20Youtube%20Users.js

But I also think that's a youtube feature already and I have no idea how old that script is. I think there is a "Don't recommend this channel" option on thumbnails.