Greasy Fork is available in English.

Hide videos seen on Youtube

Hide videos seen on Youtube channel's videos tab and channel search results

Verzia zo dňa 10.10.2014. Pozri najnovšiu verziu.

// ==UserScript==
// @name         Hide videos seen on Youtube
// @namespace    http://herbalcell.com
// @version      0.1
// @description  Hide videos seen on Youtube channel's videos tab and channel search results
// @match        https://www.youtube.com/user/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js
// @require      https://greasyfork.org/scripts/2199-waitforkeyelements/code/waitForKeyElements.js?version=6349
// ==/UserScript==

var currentUrl = window.location.toString().replace(/(.*\/user\/.*?)\/.*/,'\$1');
var storedHiddenVideos = JSON.parse(localStorage.getItem(currentUrl) || '{}');

function getListElements() { return $('div.branded-page-v2-col-container a.yt-uix-tile-link'); }

$('head').append(
    '<style>' +
        '.channels-browse-content-grid .channels-content-item {' +
            'position: relative;' +
        '}' +
        '.hide-link, .hide-link:hover {' +
            'display: none;' +
            'background: #fff;' +
            'font-size: 20px;' +
            'color: #000;' +
            'line-height: 30px;' +
            'text-align: center;' +
            'z-index: 555;' +
            'position: absolute;' +
            'right: 0;' +
            'width: 30px;' +
            'height: 30px;' +
            'text-decoration: none;' +
        '}' +
        '#show-all-hidden-videos {' +
            'margin-left: 20px;' +
        '}' +
    '</style>'
);

$('div#content').on('mouseover', 'li.channels-content-item, li.feed-item-container', function(){
    $(this).find('a.hide-link').show();
});

$('div#content').on('mouseout', 'li.channels-content-item, li.feed-item-container', function(){
    $(this).find('a.hide-link').hide();
});

$('div#content').on('click', 'a.hide-link', function(){
    currentLink = $(this).parent().find('a.yt-uix-sessionlink');
    storedHiddenVideos[currentLink.attr('href').replace(/(.*?)&.*/,'\$1')] = true;
    localStorage.setItem(currentUrl, JSON.stringify(storedHiddenVideos));
    currentLink.closest('li').hide();
});

function assessLinks() {
    currentLink = $(this);
    currentLink.closest('li').find('img').closest('div').prepend('<a class="hide-link">X</a><div style="clear:both;"></div>');
    if (storedHiddenVideos[currentLink.attr('href').replace(/(.*?)&.*/,'\$1')] !== undefined)
        currentLink.closest('li').hide();
}

waitForKeyElements ('div.branded-page-v2-col-container ul#browse-items-primary', function() {
    $('div.branded-page-v2-col-container a.yt-uix-tile-link').each(assessLinks);
});

function loadMoreVideos() {
    var startingListLength = getListElements().length;
    var intervalID = setInterval(function() {
        var currentListLength = getListElements().length;
        if (startingListLength != currentListLength) {
            getListElements().slice(startingListLength, currentListLength).each(assessLinks);
            clearInterval(intervalID);
        }
    }, 500);
}

var showButton = '<button id="show-all-hidden-videos" class="yt-uix-button yt-uix-button-default"><span>Show hidden</span></button>';
$('button.yt-google-help-link').after(showButton);
$('button#show-all-hidden-videos').click(function(){
    getListElements().each(function() {$(this).closest('li').show()});
});

waitForKeyElements ('button.yt-uix-load-more', function() {
    $('#content').on('click', 'button.yt-uix-load-more', loadMoreVideos);
    // // Uncomment this section to automatically click "Load more" until all videos are showing
    // var intervalID = setInterval(function() {
        // var loadMoreButton = $('button.yt-uix-load-more')[0];
        // if (!loadMoreButton)
            // clearInterval(intervalID);
        // else
            // loadMoreButton.click();
    // }, 5000);
});