Add hide button

Add hide button to video blocks in subscriptions feed

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Add hide button
// @author       Rolandas Valantinas
// @description  Add hide button to video blocks in subscriptions feed
// @match        https://www.youtube.com/feed/subscriptions
// @namespace    https://greasyfork.org/users/157178
// @supportURL   https://github.com/rolandas-valantinas/gists/issues
// @version      1.2
// ==/UserScript==

// Helper functions
function getTarget(e) {
	e = e || window.event;
	return e.target || e.srcElement;
}

// Hide videos when clicked
function autoHideClicked (e) {
	var target = getTarget(e).parentNode.parentNode;

    var hideMenuButton = target.getElementsByTagName('button')[0];
    hideMenuButton.click();

    setTimeout(function() {
        // Hide the video via the youtube menus, because 1) lazy, 2) easier to update in future
        var hideMenu = document.getElementsByTagName('ytd-popup-container')[0];
        var hideButton = hideMenu.getElementsByTagName('yt-formatted-string');
        hideButton[hideButton.length-1].click();
    }, 4);
}

(function () {
    setTimeout(() => {
        var i;
        var videos = document.getElementsByTagName("ytd-grid-video-renderer");

        for (i = 0; i < videos.length; i++) {
            var link = document.createElement('div');
            link.innerHTML = '<a class="hide-button" href="javascript:;">hide</a>';

            videos[i].appendChild(link);
        }

        var hideButtons = document.getElementsByClassName('hide-button');

        for (i = 0; i < hideButtons.length; i++) {
            hideButtons[i].addEventListener('click', autoHideClicked, false);
        }
    }, 3000);

})();