Skip to content

Instantly share code, notes, and snippets.

@unascribed
Last active February 26, 2016 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unascribed/83517634fca279361b16 to your computer and use it in GitHub Desktop.
Save unascribed/83517634fca279361b16 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name YouTube Subscriptions Filter
// @namespace https://unascribed.com/
// @version 0.1
// @description allows you to filter your YouTube subscription feed
// @author Aesen "unascribed" Vismea
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @match https://www.youtube.com/feed/subscriptions
// @match http://www.youtube.com/feed/subscriptions
// ==/UserScript==
var filters = [
{
name: "Example Filter", // for informational purposes, can be omitted
channel: "MrExample", // can also be a regex or a function
title: /Minecraft$/, // ends with "Minecraft"
action: "remove" // remove the video from the feed outright
},
{
name: "Example Filter #2",
title: /^Street Fighter/, // starts with "Street Fighter"
action: "obscure" // replace the thumbnail with gray stripes
}
];
function matches(filter, str) {
if (!filter) {
return true;
} else if (filter instanceof RegExp) {
return !!filter.exec(str);
} else if (typeof filter === "string" || filter instanceof String) {
return filter === str;
} else if (typeof filter === "function") {
return !!filter(str);
} else {
throw new Error("unknown filter type");
}
}
function forEachInterruptible(arr, fun) {
for (var i = 0; i < arr.length; i++) {
if (!fun(arr[i])) return;
}
}
$("div.yt-lockup-video > div.yt-lockup-dismissable").each(function(i, e) {
e = $(e);
var title = e.find("h3.yt-lockup-title > a").text();
var channel = e.find("div.yt-lockup-byline > a").text();
forEachInterruptible(filters, function(filter) {
if (matches(filter.channel, channel) && matches(filter.title, title)) {
switch (filter.action) {
case "remove":
console.log("Removing video "+title+" by "+channel+(filter.name ? " (matches filter '"+filter.name+"')" : ""));
e.parent().parent().remove();
return false;
case "obscure":
console.log("Obscuring thumbnail for video "+title+" by "+channel+(filter.name ? " (matches filter '"+filter.name+"')" : ""));
var thumb = e.find(".yt-thumb");
var img = thumb.find("img").remove();
thumb.css("width", img.attr("width")+"px");
thumb.css("height", img.attr("height")+"px");
img.remove();
thumb.css("background", "repeating-linear-gradient(45deg, #222, #222 10px, #444 10px, #444 20px)");
return false;
default:
console.warn("Unknown filter action "+filter.action+(filter.name ? " (filter '"+filter.name+"')" : ""));
break;
}
}
return true;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment