amitbl / blocktube

YouTube™ content blocker
GNU General Public License v3.0
860 stars 60 forks source link

Help with advanced blocking? #311

Open anatidaeta opened 1 year ago

anatidaeta commented 1 year ago

Hi, I have no js knowledge, just looking for help with an advanced blocking rule that will block videos with very old upload dates (ie. >3 years old)

In addition, is there a way to stop blocktube from affecting videos shown on channel themselves?

Thanks

ewonais commented 1 year ago

sadly the video age is only awalibel as text. depends on lanuge settings. this might block anything older than 2 yaers:

(video, objectType) => { if (video.publishTimeText.match("years")) {return true; } return false; }

block if "publishTimeText" contains the word "years"

ercarp commented 1 year ago

sadly the video age is only awalibel as text. depends on lanuge settings. this might block anything older than 2 yaers:

(video, objectType) => { if (video.publishTimeText.match("years")) {return true; } return false; }

block if "publishTimeText" contains the word "years"

I'm not @anatidaeta but I was looking for something similar and this worked out perfectly. Thank you! I was getting video recommendations as old as 13-15 years and I had seen all of them already, it was getting very annoying.

llamatar commented 1 year ago

Here is an Advanced Blocking function to block all videos older than the chosen number of years:

  const blockVideosPublishedYearsAgo = 4; // <-- change this number as desired 
  if (video.hasOwnProperty("publishTimeText") && /year/.test(video.publishTimeText) && video.publishTimeText.split(" ")[0] >= blockVideosPublishedYearsAgo)
    return true;
llamatar commented 1 year ago

There are several ways to stop BlockTube from affecting videos shown on channel pages.

One way is to allow all videos on channel pages:

  // Allow all videos in unblockablePages
  const unblockablePages = [
    /\/channel\//   // channel page (contains "/channel/")
    , /\/@/         // channel page (contains "/@")
  ];
  if (unblockablePages.some(page => page.test(window.location.pathname)))
    return false;

Another way is to allow videos everywhere except for the homepage, the subscriptions page, and the related videos sidebar. This is just my personal preference, and you may not want this:

  // Allow videos in pages other than blockablePages
  const blockablePages = [
    /^\/$/                      // homepage (exactly "/")
    , /\/feed\/subscriptions/   // subscriptions (contains "/feed/subscriptions")
    , /\/watch/                 // related videos sidebar (contains "/watch")
  ];
  if (!blockablePages.some(page => page.test(window.location.pathname)))
    return false;