[Userscript] YouTube Chemotherapy [Updated 8/14/2016]

DataMine
by DataMine · 6 posts
7 years ago in Javascript
Posted 7 years ago · Author
About
This is a Greasemonkey script I'm working on to hide all content on YouTube that I deem to be cancerous or otherwise uninteresting. Hopefully making it much faster to find what you're interested in.

Prerequisites
For FireFox users install Greasemonkey: https://addons.mozilla.org/en-US/firefo ... asemonkey/

Downloads
This is a WIP script and is also subjective. Therefore there is no install link, you must install it manually and edit it as you see fit.


Here's the working part of the script:
Code
// ==UserScript==
// @name        YouTube Chemotherapy
// @namespace   TIMDM
// @description Hides cancerous content from YouTube
// @include     *.youtube.com/*
// @version     1
// @require     http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant       GM_addStyle
// ==/UserScript==




/*
Blacklisted Strings
*/
var cancerousTerms = [
  'prank',
  'drama',
  'minecraft',
  'troll',
  'pokemon',
]


/*
Regular Expressions to match
*/
var topListRegex = /top\s+\d+/i;
var listRegex = /^[\d]+\s/i;


$(document).ready(function () {
  //Video Titles
   testVideos(".yt-lockup-title");
   
   //Video Authors
   testVideos("a.g-hovercard");
});

function testVideos(el) {
   if(el) {
      $(el).each(function() {
         if (contentIsCancerous($(this).text())) {
            //Remove the video shelf item from the channel shelf
            $(this).closest(".yt-lockup-video").remove();
         }
      });
   }
}

function contentIsCancerous(content) {
   if(topListRegex.test(content)) {
      console.log("Regex Match. Removing Top List:" + content);
      return true;
   }
   
   if(listRegex.test(content)) {
      console.log("Regex Match. Removing List:" + content);
      return true;
   }

   for (var i = 0; i < cancerousTerms.length; ++i) {
      if (content.toLowerCase().indexOf(cancerousTerms[i].toLowerCase()) !== -1) {
         console.log("Blacklisted String Match: " + cancerousTerms[i]);
         return true;
      }
   }
   
   return false;
}



And here's the full broken script:
Spoiler: Broken Script

Code
// ==UserScript==
// @name        YouTube Chemotherapy
// @namespace   TIMDM
// @description Hides cancerous content from YouTube
// @include     *.youtube.com/*
// @version     1
// @require     http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant       GM_addStyle
// ==/UserScript==




//Add your cancerous and/or unwanted keywords here
var cancer = [
  'Prank',
  'Drama',
  'Minecraft',
  'Troll',
  'top 10',
  'pokemon',
]





$(document).ready(function () {
  checkChannels('.feed-item-container');
  checkVideos('.yt-lockup-title');
  checkVideos('a.g-hovercard');
  cleanUp();
});


//This is for automatically cleaning new video shelfs as they appear when you scroll
var lastScroll = 0;

$(window).scroll(function(){
  var st = $(this).scrollTop();
 
  //If scrolling down
  if (st > lastScroll){
    checkChannels('.feed-item-container');
    checkVideos('.yt-lockup-title');
    checkVideos('a.g-hovercard');
    //cleanUp();
  }
 
  //Updates scroll position
  lastScroll = st;
})


//Checks video information for cancer
function checkVideos(el) {
  if (el) {
    $(el).each(function () {
      console.log("Text: " + $(this).text());
      if (contentIsCancerous($(this).text())) {
        console.log("Found Cancer");
        Remove the video shelf item from the channel shelf
        $(this).closest('.yt-lockup-video').remove();
        $(this).closest('li').remove();
      }
    });
  }
}




//Checks channel information for cancer
function checkChannels(el) {
  if (el) {
    $(el).each(function () {
      //Grab the channel name
      var channelTitle = $(this).find('span.branded-page-module-title-text');
      //If the channel name exists
      if (channelTitle.length > 0) {
        if (contentIsCancerous(channelTitle.text())) {
          //Remove the channel shelf from the homepage
          $(this).remove();
        }
      }
    });
  }
}



//Removes shelves that have no videos after cancer removal
function cleanUp() {
   $(".feed-item-container").each(function() {
      var videoList = $(this).find("ul.yt-uix-shelfslider-list");
      
      if(videoList.length > 0) {
      console.log("videolist found");
      if (videoList.children().length == 0) {
        console.log("no children);
        $(this).parents(".feed-item-container").remove();
      }         
      } else {
      //console.log("videolist not found");
    }
   });
}







//Compares content to cancer array
function contentIsCancerous(a) {
  for (var i = 0; i < cancer.length; ++i) {
    if (a.toLowerCase().indexOf(cancer[i].toLowerCase()) !== - 1) {
      console.log('Found Cancer: ' + a);
      return true;
    }
  }
  return false;
}



The goal is to have a script that first scans each channel shelf (if you're on the homepage) and removes all cancerous videos from them. Then it removes all channel shelves that have 0 videos left. After that it scans each remaining video title and author name and removes them if they are cancerous. This whole process than repeats as you scroll down and new channel shelves are added.

Right now scrolling doesn't work properly and neither does cancer detection for the channel shelves. Adding in the shelf code also breaks the script.

If you're on a results page it will simply hide any videos on the page that are cancerous as you load the page.
Posted 7 years ago
Awesome work! I'm gonna test this out right now :).
Posted 7 years ago · Author
I updated the script and added regex matching to filter out top number lists as well as numerical list videos.
Posted 7 years ago
Thanks DM, ur the best lol i'll give it a try, great job DM as usual :dancingapple:
Posted 6 years ago
I confirm. So happens. Let's discuss this question. Here or in PM.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT
Select a forum Protection     Help & Support     Introductions     Mafia News     IMVU News General Discussion     IMVU Lounge        IMVU Series / Roleplaying        Social Games     Mafia Market     Mafia Tools        Premium IMVU Tools        Off Topic Tools     Off Topic     Contests Creator Corner     Graphics Design        Photoshop        GIMP     Basic Creator Help     Catalog And Product Showcase     3D Meshing        3Ds Max        Sketchup        Blender Gangsters with Connections     White Hat Activities        Google Hacking        Trackers Programming Corner     Coding        Python        .Net (C#, VB, etc)        Flash        JAVA        Autoit        Batch        HTML & CSS        Javascript        PHP        Other        IMVU Homepage Codes           General           About me Panel           Messages Panel           Special Someone Panel           Visitors Panel           New Products Panel           Rankings Panel           Wishlist Panel           My Badges Panel           Outfits Panel           Url Panel           Groups Panel           Slideshow Panel           My Room Panel           Sandbox panel           Layouts     Help & Requests Free Credits     Approved Methods     Submit Methods Free Money     Approved Methods     Submit Methods Adult Corner     Get Mafia AP Here     AP Lounge        AP Social Games        Casual Dating Tips     IMVU Slave Market & Escorts