// ==UserScript== // @name Block youtube users / channels // @author Schegge // @namespace https://greasyfork.org/en/users/12632-schegge // @description Prevent from seeing videos by certain users (from recommended, search, related channels... no in playlists) // @version 2.1.5 // @match *://www.youtube.com/* // @exclude *://www.youtube.com/embed/* // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js // @grant GM_getValue // @grant GM_setValue // @downloadURL none // ==/UserScript== /**************************************** → the program is case-insensitive → split the usernames with a comma → put a * in front of a word for wildcard (only in the blacklist!), it will find the word no matter its position in the username (example: *vevo) → on line 139 the channels' hovercards are disabled, comment it if you want them (they seem to cause a problem on the MutationObserver, but it does NOT broke this script anyway, so whatever) → on line 142 you can change the pages in which the search is excluded → VERSION 2: # blacklist editor changed # whitelist added # no need to refresh the page after changes in the blacklist/whitelist # added ☆ button to force a new search (in case of problems?) please report any bugs ****************************************/ (function($) { var sBL, sWL, ytblacklist, ytwhitelist; function getValues() { sBL = GM_getValue("savedblocks", "the program is case-insensitive, split the usernames with a comma, put a * in front of a word for wildcard, it will find the word no matter its position in the username, example, *vevo, delete all of this"); sWL = GM_getValue("savedwhites", "put here whitelisted usernames, if for example you blacklist *vevo, but you want to see IndilaVEVO, write here:, indilavevo, delete all of this"); ytblacklist = sBL.split(","); ytwhitelist = sWL.split(","); } getValues(); // add blacklist button to the menu $buttonB = $("", { id: "yt-blacklist", html: "B", css: {"cursor": "pointer", "margin-right": "2px", "font-size": "20px", "vertical-align": "middle"} } ); $buttonS = $("", { id: "yt-blacklist-research", html: "☆", css: {"cursor": "pointer", "margin-right": "5px", "font-size": "12px", "vertical-align": "top"} } ); $("#upload-btn") .after($buttonS) .after($buttonB); var marginright = ( $(window).width() - $buttonB.offset().left - $buttonB.outerWidth() - $buttonS.outerWidth() - 20 ); var margintop = $("#yt-masthead-container").height() + parseInt($("#yt-masthead-container").css("padding-top")) + parseInt($("#yt-masthead-container").css("padding-bottom")); // elements for user input $divInput = $("
", { id: "yt-blacklist-options", css: {"display": "none", "position": "fixed", "right": marginright+"px", "top": margintop+"px", "padding": "0 20px 20px 20px", "text-align": "center", "background-color": "#fff", "box-shadow": "0 2px 2px 1px rgba(0,0,0,.1)", "z-index": "99999999999"} }); $textareaBL = $("
Blacklist
"); $textareaWL = $("
Whitelist
"); $saveDiv = $("
", { id: "saveblacklistDiv", css: {"clear": "both", "padding-bottom": "10px", "margin": "1px 0 0 0", "text-align": "right"} } ); $save = $("", { id: "saveblacklist", css: {"cursor": "pointer", "color": "#cc181e", "text-shadow": "1px 1px 1px rgba(0,0,0,0.25)", "border-radius": "2px"}, html: "save" }); $saved = $("", { css: {"margin-right": "7px", "font-size": "80%"}, html: "saved and searched again" }); $saveDiv.append($save); $divInput .append($saveDiv) .append($textareaWL) .append($textareaBL); $("body").append($divInput); $researched = $("
", { html: "done!", css: {"position": "fixed", "right": marginright+20+"px", "top": margintop-12+"px", "font-size": "80%", "z-index": "999999999999"} }); // open and close textareas $("#yt-blacklist").click(function() { $("#yt-blacklist-options").slideToggle(); }); // check if a username is whitelisted function ifWhite(u) { var whitelisted = false; for(var z = 0; z < ytwhitelist.length; z++) { var w = ytwhitelist[z].trim().toLowerCase(); if (w.length && u === w) { whitelisted = true; } } return whitelisted; } // check if a username is blacklisted function ifMatch(u) { var match = false; if ( !ifWhite(u) ) { // if the username isn't whitelisted for (var j = 0; j < ytblacklist.length; j++) { var b = ytblacklist[j].trim().toLowerCase(); if ( b.charAt(0) == "*" ) { // wildcards var part = b.split("*"), item = part[1]; if ( item.length && u.indexOf(item) !== -1 ) { match = true; } } else { // exact match if ( b.length && u == b ) { match = true; } } } } return match; } // do the thing function findMatch(s) { $(s).each(function() { var username = $(this).text().trim().toLowerCase(); if ( ifMatch(username) ) { // if the username is blacklisted if ( $(this).parents("#watch-header").length ) { // on the watch page if ( !$(this).siblings(".span-is-black").length ) { // check if it wasn't already blacklisted $(".yt-user-info").append("BLACKLISTED!"); } } else { if ( !$(this).parents(".li-is-black").length ) { // check if it wasn't already blacklisted $(this).closest("li").addClass("li-is-black").hide(); } } } else { // if a previous black/whitelist word is deleted/added if ( $(this).siblings(".span-is-black").length ) { $(this).siblings(".span-is-black").remove(); } if ( $(this).parents(".li-is-black").length ) { $(this).parents(".li-is-black").removeClass("li-is-black").show(); } } }); } // where the usernames are var uClasses = [".g-hovercard", ".branded-page-related-channels-list"]; // the final search function function search() { if ( yt.config_.UNIVERSAL_HOVERCARDS ) { yt.config_.UNIVERSAL_HOVERCARDS = false; } var url = window.location.pathname; if ( url != ( "/feed/history" || "/playlist?list=WL" || "/feed/subscriptions" ) ) { for (var i = 0; i < uClasses.length; i++) { findMatch(uClasses[i]); } } } // search when youtube is first opened search(); // save blacklist changes and research $("#saveblacklist").click(function() { GM_setValue("savedblocks", $('#blacklist-words').val()); GM_setValue("savedwhites", $('#whitelist-words').val()); getValues(); search(); $save.before($saved); setTimeout(function() { $saved.remove(); }, 3000); }); // research when the $buttonS is clicked $("#yt-blacklist-research").click(function() { search(); $("#yt-masthead-user").append($researched); setTimeout(function() { $researched.remove(); }, 2000); }); // research after every change in #content var target = document.querySelector('#content'); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { search(); }); }); var config = { attributes: true, childList: true, characterData: true }; observer.observe(target, config); })(window.jQuery);