// ==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 recommendation, search... //no in playlists) // @version 1.1 // @history 1.1 minor fixes // @match *://www.youtube.com/* // @exclude *://www.youtube.com/embed/* // @exclude *//www.youtube.com/playlist?list=WL // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js // @grant GM_getValue // @grant GM_setValue // @downloadURL none // ==/UserScript== //* INSTRUCTIONS *//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*// // → 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) // // → after saving refresh the page // //*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*// (function($) { var gmSaved = 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, *vevos, after saving refresh the page, delete all of this"); var ytblacklist = gmSaved.split(","); // add blacklist button to the menu $liButton = $("
  • ", {class: "guide-channel guide-notification-item overflowable-list-item", id: "yt-blacklist"} ); $aButton = $("", {class: "guide-item yt-uix-sessionlink yt-valign spf-link"} ); $spanButton = $("Blacklist"); $aButton.append($spanButton); $liButton.append($aButton); $("#guide-container li.guide-section:nth-child(1) ul.guide-user-links").append($liButton); // element for user input $divInput = $("
    ", {id: "yt-blacklist-options", /*class: "yt-card",*/ css: {"display": "none", "width": "100%", "padding": "20px", "margin": "10px 0", "text-align": "center", "box-sizing": "border-box"} }); $textarea = $(""); $saveDiv = $("
    ", {id: "saveblacklistDiv", css: {"padding-top": "10px", "width": "600px", "margin": "0 auto", "text-align": "right"} } ); $save = $("", {id: "saveblacklist", css: {"cursor": "pointer", "padding": "5px", "color": "#fff", "background": "#cc181e", "font-weight": "bold", "text-shadow": "-1px -1px 0 rgba(0,0,0,0.25)"}, html: "save"} ); $saved = $("", {id: "saved", css: {"padding": "5px", "margin-right": "10px", "font-size": "80%"}, html: "SAVED"} ); $saveDiv.append($save); $divInput .append($textarea) .append($saveDiv); $("#page-container #page").prepend($divInput); // open and close textarea $("#yt-blacklist").click(function() { $(document).scrollTop(0); $("#yt-blacklist-options").slideToggle("200"); if($saved.length) { $saved.remove(); } }); // save $("#saveblacklist").click(function() { GM_setValue("savedblocks", $('#blacklist-words').val()); $save.before($saved); }); //*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*// var Program = { blacklist: ytblacklist, sClass: [".g-hovercard", ".yt-uix-tile-link", ".branded-page-module-title-text"], // the classes where usernames are findMatch: function(s, b) { $(s).each(function() { if( $(this).length ) { // if the element exist var username = $(this).text().trim().toLowerCase(); var match = false; b = b.trim().toLowerCase(); if ( b.charAt(0) == "*" ) { // wildcards var part = b.split("*"), item = part[1]; if ( username.indexOf(item) !== -1 ) { match = true; } } else { // exact match if ( username == b ) { match = true; } } if( match ) { if( $(this).parents("#watch-header").length ) { $("#watch-header").before("
    " + b + " is in your blacklist
    "); $(".yt-user-info").append("BLACKLISTED!"); } else { $(this).closest("li").remove(); } } } }); }, search: function() { for (var i = 0; i < this.sClass.length; i++) { for (var j = 0; j < this.blacklist.length; j++) { this.findMatch(this.sClass[i], this.blacklist[j]); } } } }; Program.search(); //* // code below taken from: // https://hacks.mozilla.org/2012/05/dom-mutationobserver-reacting-to-dom-changes-without-killing-browser-performance/ //* var target = document.querySelector('#content'); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { Program.search(); }); }); var config = { attributes: true, childList: true, characterData: true }; observer.observe(target, config); })(window.jQuery);