Filter YouTube subscriptions videos

Allows to hide matched videos from subscriptions page

< Feedback on Filter YouTube subscriptions videos

Question/comment

Qon
§
Posted: 2016-11-20

FTFY - Working version of the script here.

I wanted this script, but it didn't work for me. So I rewrote it from scratch basically. The old version was outdated (interface with youtube and using deprecated web technology), bloated (used 2 unecessary bs libraries), slow (deprecated slow technology and unecessary work done). I'd say that the new version is better structured and easier to read and understand too.

I might make it even better later. It's a WIP, I've barely tested it. But it works better than before so I'll thow it out in case someone wants to try it out. Edit the script and just replace all the code with the code I have below:

// ==UserScript==
// @name       Filter YouTube subscriptions videos
// @version    0.3
// @description Allows to hide matched videos from subscriptions page
// @match      http://www.youtube.com/feed/subscriptions*
// @match      http://youtube.com/feed/subscriptions*
// @match      https://www.youtube.com/feed/subscriptions*
// @match      https://youtube.com/feed/subscriptions*
// @license    GPLv3 - http://www.gnu.org/licenses/gpl-3.0.en.html
// @copyright  sergey.larionov@gmail.com
// @grant      none
// @namespace https://greasyfork.org/users/29165
// ==/UserScript==

var videoMatchHide = {
    'CrashCourse': ['Crash Course (Games|Physics)']
   ,'Skallagrim': ['Vlog:']
   ,'Fraser Cain': ['Weekly Space Hangout -', 'Hasdad Hsdasd Jsdaa']
   ,'*': [] // Applies to all channels
}
var keys = Object.keys(videoMatchHide)
for(var i = 0; i < keys.length; ++i) {
    videoMatchHide[keys[i]] = videoMatchHide[keys[i]].map(q=>new RegExp(q))
}

function funcFilter(mutations, mutObserver) {
    var checkVideos
    if(mutations == null) {
        checkVideos = [document.querySelectorAll('.yt-shelf-grid-item')]
    } else {
        checkVideos = mutations.map(c=>querySelectorAll('.yt-shelf-grid-item'))
    }
    for(var j = checkVideos.length - 1; j >= 0; --j) {
        var subset = checkVideos[j]
        for(var i = subset.length - 1; i >= 0; --i) {
            var vidCard = subset[i]
            var vidAuthor = vidCard.querySelector('div.yt-lockup-byline > a').textContent
            var vidTitle = vidCard.querySelector('.yt-lockup-title').textContent
            var filthRE = videoMatchHide[vidAuthor]
            if(
                filthRE != null && filthRE.some(c=>vidTitle.search(c) !== -1)
              ||       videoMatchHide['*'].some(c=>vidTitle.search(c) !== -1)
            ) {
                console.log(
                    'Video filtered. Author: ' + vidAuthor
                    + ', Title: ' + vidTitle)
                vidCard.remove()
            }
        }
    }
};
var observer = new MutationObserver(funcFilter)
observer.observe(
    document.querySelector('div#content')
   ,{childList: true, subtree: true}
)
funcFilter();

Post reply

Sign in to post a reply.