YouTube Subscriptions Page: Hide Viewed Videos

Once a video is clicked, it will be hidden from the subscription page

当前为 2017-08-30 提交的版本,查看 最新版本

// ==UserScript==
// @name         YouTube Subscriptions Page: Hide Viewed Videos
// @namespace    hideViewedVideos_kk
// @description  Once a video is clicked, it will be hidden from the subscription page
// @version      0.5
// @author       Kai Krause <[email protected]>
// @match        http://www.youtube.com/feed/subscriptions*
// @match        https://www.youtube.com/feed/subscriptions*
// @run-at       document-end
// ==/UserScript==

// Hide 'video is hidden' message from hiding videos
var hideFunc;
function autoHideHidden (e) {
	var e = e || true;
	
	hideFunc = function () {
		var renderers = document.getElementsByTagName('ytd-grid-video-renderer');
		for (var i = 0; i < renderers.length; ++i) {
			var dismissedItem = renderers[i].getAttribute('is-dismissed');
			if (dismissedItem === "") {
				renderers[i].remove();
				break;
			}
		}
	}
	
	if (e) {
		setTimeout(hideFunc, 4);
	} else {
		hideFunc;
	}
}
document.addEventListener('mouseup', autoHideHidden);

// Hide videos when clicked
function autoHideClicked (e) {
	e = e || window.event;
	
	// Disable right-click
	var isRightMB;
	if ("which" in e) { // Gecko (Firefox), WebKit (Safari/Chrome) & Opera
		isRightMB = e.which == 3;
	} else if ("button" in e) { // IE, Opera
		isRightMB = e.button == 2;
	}
	if (isRightMB) return;
	
	var target = e.target || e.srcElement;
	
	// Disable video channel clicks from removing the video
	if (target.href && target.href.includes('/channel/')) return;
	// Disable video menu clicks from removing the video, and ignore the thumbnail 'play' animation
	if (target.tagName == 'BUTTON') return;
	if (target.tagName == 'YT-ICON' && target.id != "play") return;
	
	var targets = [];
	targets.push(target);
	while (targets) {
		var targetType = target.tagName;
		if (targetType == "YTD-GRID-VIDEO-RENDERER") {
			
			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');
				for (var i = 0; i < hideButton.length; ++i) {
					if (hideButton[i].innerHTML == "Hide") {
						hideButton[i].click();
						break;
					}
				}
				autoHideHidden(false);
			}, 4);
			
			break;
		} else {
			targets.unshift(target);
			target = target.parentNode;
		}
	}
}
document.addEventListener('mouseup', autoHideClicked);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址