amitbl / blocktube

YouTube™ content blocker
GNU General Public License v3.0
882 stars 62 forks source link

[Request] Give an option to hide watched videos while ignoring Channel videos #260

Open jaylay99 opened 1 year ago

jaylay99 commented 1 year ago

The feature: "Hide videos watched more than" is great but it hides videos when I go on someone's Channel. I wish to have an extra option that would let me hide watched videos but only on the Homepage.

Thanks!

llamatar commented 1 year ago

I wrote a custom blocking function that blocks watched videos only for the homepage, subscriptions, and related videos sidebar here: https://github.com/amitbl/blocktube/issues/151#issuecomment-1221647020

Adapting this function to only the homepage results in something like this:

// Block watched videos in certain pages
(video, objectType) => {
  const hideVideosWatchedMoreThanPercentage = 90; 

  // Do not block videos in pages other than blockedPathnames
  const blockedPathnames = [
    /^\/$/                      // homepage
  ];
  if (!blockedPathnames.some(blockedPathname => blockedPathname.test(window.location.pathname)))
    return false;

  // Do not block unwatched videos
  if (video.percentWatched === undefined || parseInt(video.percentWatched) < hideVideosWatchedMoreThanPercentage)
    return false;

  // Do not block videos in playlists
  if (objectType === "playlistPanelVideoRenderer")
    return false;

  console.log(`BlockTube custom blocking function: "${video.title}" (${video.percentWatched}% watched)`);
  return true;
}