amitbl / blocktube

YouTube™ content blocker
GNU General Public License v3.0
945 stars 67 forks source link

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

Open SirGoldenTaco opened 7 months ago

SirGoldenTaco commented 7 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 5 months 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 5 months ago

Just to make sure before testing

image

Like this right?

misspent commented 5 months 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 - Ignore this
```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 (not all work, but you get the idea)
```js (video, objectType) => { // Helper function to parse view count const parseViewCount = (viewCount) => { if (typeof viewCount === 'string') { return parseInt(viewCount.replace(/[^0-9]/g, ''), 10); } return viewCount; }; // Check if video is older than specified years const isOlderThan = (years) => { const match = video.publishTimeText.match(/\b(\d+)\s+years?\b/i); return match && parseInt(match[1], 10) > years; }; // Check if video duration is within a specific range (in seconds) const isDurationBetween = (min, max) => video.vidLength >= min && video.vidLength <= max; // Parse view count const viewCount = parseViewCount(video.viewCount); if ( // Video type filters Number.isNaN(video.vidLength) || // Remove Premieres video.badges?.includes('live') || // Remove Live streams video.publishTimeText.includes('Streamed') || // Remove streamed videos (typeof video.viewCount === 'string' && video.viewCount.includes('No Views')) || // Remove videos with no view count // Duration filters // isDurationBetween(0, 120) || // Remove videos shorter than 2 minutes // isDurationBetween(3600, Infinity) || // Remove videos longer than 1 hour // Age and engagement filters isOlderThan(3) || // Remove videos older than 3 years viewCount < 500 // Remove low view count videos | 10000 ) { return true; // Remove the video if any of the conditions are met } return false; // Keep the video if none of the conditions are met } ```
SirGoldenTaco commented 5 months ago

Thanks for all that!

Will keep testing and report back in a bit