amitbl / blocktube

YouTube™ content blocker
GNU General Public License v3.0
855 stars 57 forks source link

Adding ammount of time in "Runtime blocking" of X-90 seconds makes everything below video dissapear #389

Open SirGoldenTaco opened 3 months ago

SirGoldenTaco commented 3 months ago

Reproduce: "Runtime blocking" set to specific settings:

First part can be anything Second part can be anything from 0 to 89 seconds If you put anything higher than 90 everything under thed currently playing video dissapear

What I tried: Reinstalling the extension Disabling every other extensions Incognito mode Other browsers Safe mode

With "Runtime blocking" set to 89 seconds image image

With "Runtime blocking" set to anything higher than 89 seconds image image

misspent commented 1 month ago

Add this in advanced settings:

    // Video length - Use this over built in | Bug: https://github.com/amitbl/blocktube/issues/389
    if (video.vidLength<=120) { // Value to change
    return true;
    }

Got this from: Exceptions for subscribed channels

SirGoldenTaco commented 1 month ago

Just to make sure before testing

image

Like this right?

misspent commented 1 month ago

Yes, and it worked for me, but my CPU was "overloaded", so I got AI to write a TamperMonkey script instead; it's more consistent and faster. It needs additional testing and cleaning before I'll put it on greasyfrok (if I do).

Video Duration Script
```js // ==UserScript== // @name YouTube Video Duration Filter // @version 1.0 // @description Filters out YouTube videos below 2 minutes in duration, logs the title and duration of each removed video to the console with custom colors, and avoids displaying videos with a duration of 0 seconds. // @author Misspent & OpenAI // @namespace https://chat.openai.com // @icon https://i.imgur.com/1RYzIiT.png // @match https://www.youtube.com/* // @grant none // @license MIT // @run-at document-body // ==/UserScript== (function() { 'use strict'; // Function to check if a video duration is less than 2 minutes and not 0 seconds function isShortVideo(duration) { // Assuming duration is in seconds return duration < 120 && duration !== 0; // Change value here (the 120) } // Function to get the title of a video element function getVideoTitle(video) { var titleElement = video.querySelector('#video-title'); return titleElement ? titleElement.innerText.trim() : null; } // Function to filter out short videos function filterVideos() { // Get all video elements on the page var videos = document.querySelectorAll('ytd-rich-item-renderer, ytd-compact-video-renderer, ytd-video-renderer, ytd-playlist-panel-video-renderer'); videos.forEach(function(video) { // Get the title of each video var title = getVideoTitle(video); // Get the duration of each video var durationElement = video.querySelector('span.ytd-thumbnail-overlay-time-status-renderer'); var durationText = durationElement ? durationElement.innerText.trim() : ''; if (title && durationText) { // Extract duration in seconds from the element text var durationArray = durationText.split(':'); var durationInSeconds = 0; // Convert duration to seconds if (durationArray.length === 3) { durationInSeconds += parseInt(durationArray[0]) * 3600; durationInSeconds += parseInt(durationArray[1]) * 60; durationInSeconds += parseInt(durationArray[2]); } else if (durationArray.length === 2) { durationInSeconds += parseInt(durationArray[0]) * 60; durationInSeconds += parseInt(durationArray[1]); } else { durationInSeconds += parseInt(durationArray[0]); } // Check if the video is short and not 0 seconds if (isShortVideo(durationInSeconds)) { // Log the title and duration of the removed video with custom colors console.log("%cDuration Removal: %c" + title + " %c(" + durationText + ")", "color: red;", "color: orange;", "color: deepskyblue;"); // Remove the parent element of the video video.parentNode.removeChild(video); } } }); } // Run the filter when the page loads and when new content is added (AJAX) var observer = new MutationObserver(filterVideos); observer.observe(document.body, { childList: true, subtree: true }); filterVideos(); })(); /* 1. Write a perfect global YouTube TamperMonkey script that removes everything video below 2 mins and you can maybe use the variable: video.vidLength 2. Console log it accurately too so I know how many you've done + that it works 3. I want it to remove the videos results IE: ytd-rich-item-renderer, ytd-compact-video-renderer, ytd-video-renderer, ytd-playlist-panel-video-renderer 4. Make it give me the title of the video + length of video in the console log and make it NEVER show ones with 0 5. MAke it so it ALWAYS gives a video title then length of video... Some console logs are only giving the time for some reason 6. It's still showing some that just give me the length can you fix that or not show them? Either one, your choice 7. Make it so the time in the console like shows as blue text, the title as orange and the removed: as red 8. That fully stop the script from working or showing anything */ ```

I've had nothing but strange issues with Blocktube, which is a shame. I hope he fixes them at some point if he's still working on it, and I hope that little snippet works better for you than it did for me.


Everything I have in my Advanced Configuration so far, if you're curious:

Blocktube Advanced config filters
```js (video, objectType) => { // Remove videos older than x const isPublishedOverThreeYearsAgo = () => { const yearsMatch = video.publishTimeText.match(/\b(\d+)\s+years?\b/i); if (yearsMatch) { const years = parseInt(yearsMatch[1], 10); if (years > 3) { // Change this number return true; } } return false; }; // Block old videos by channel const blockOldVideosByChannel = () => { const channelsToBlock = [ { channelId: "UCuAXFkgsw1L7xaCfnd5JJOw", // Change this to your desired channel ID maxAge: 10 // Change this to the maximum age of videos to block }, // Add more channel configurations here as needed ]; for (const channelConfig of channelsToBlock) { if ( video.channelId === channelConfig.channelId && /year/.test(video.publishTimeText) && parseInt(video.publishTimeText.split(" ")[0]) >= channelConfig.maxAge ) { return true; } } return false; }; // Remove Premieres if (Number.isNaN(video.vidLength)) { return true; } // Remove Live streams if (video.badges?.includes('live')) { return true } // Removes videso that were streamed if (video.publishTimeText.match('Streamed')) { return true } // If video title contains "something" // and If the channel name contains "otherthing" if (video.vidLength < 1200 && video.viewCount > 2000) { return true; } // https://github.com/amitbl/blocktube/issues/317 //if (video.vidLength < 1200 && video.viewCount > 2000) if (isPublishedOverThreeYearsAgo()) { return true; // If the video was published over 3 years ago } if (blockOldVideosByChannel()) { return true; // Block videos by certain channel if they are older than specified } return false; // Allow all other videos } ```
SirGoldenTaco commented 1 month ago

Thanks for all that!

Will keep testing and report back in a bit