🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

YouTube Subscriptions Page: Hide Viewed Videos

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

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==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      1.6
// @author       Kai Krause <[email protected]>
// @match        http://*.youtube.com/*
// @match        https://*.youtube.com/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

// Youtube's inline loading method may confuse the browser
if (!location.href.includes('youtube.com/feed/subscriptions')) return;

// Helper functions
function getTarget(e) {
	e = e || window.event;
	return e.target || e.srcElement;
}
function rightClick(e) {
	e = e || window.event;
	if ("which" in e) { // Gecko (Firefox), WebKit (Safari/Chrome) & Opera
		return e.which === 3;
	} else if ("button" in e) { // IE, Opera
		return e.button === 2;
	}
}

// Hide 'video is hidden' message from hidden videos
function autoHideHidden () {
	setTimeout(function(){
		let dismissed = document.querySelectorAll('[is-dismissed], .ytDismissibleItemReplacedContent');
		for (let d of dismissed) {
			d.remove();
		}
	}, 100);
}
//document.addEventListener('mouseup', autoHideHidden);

setInterval(() => {
	// Disable video preview in new YT subscription page for click target context
	document.querySelector("#video-preview")?.remove();
}, 100);

// Hide videos when clicked
function autoHideClicked (e) {
	if (rightClick(e)) return;
	let target = getTarget(e);

	// Disable video channel clicks from removing the video
	if (target.href && (target.href.includes('/user/') || target.href.includes('/channel/'))) return;
	// Disable video menu clicks from removing the video, and ignore the thumbnail 'play' animation
	if (target.tagName === "BUTTON" || target.tagName === "YT-ICON" && target.id !== "play") return;

	while (target) {
		// ignore menu button and hidden video elements on-click
		let ignoredClasses = ["yt-icon-button", "yt-spec-touch-feedback-shape__fill", "ytDismissibleItemReplacedContent"];
		for (let iClass of ignoredClasses) {
			if (target?.classList?.contains(iClass)) return;
			//if (target.querySelector(iClass)) return;
		}

		if (
			["ytd-grid-video-renderer", "ytd-rich-item-renderer"].includes(target?.tagName.toLowerCase()) ||
			target.id === "dismissible" && target?.classList?.contains("ytd-rich-grid-media")
		){
			let isVideo = target.querySelector('[href*="/watch"]');
			let isShort = target.querySelector('[href*="/shorts/"]');
			if (!isVideo && !isShort) break;

			let 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
				let hideMenu = document.querySelector(".style-scope tp-yt-iron-dropdown") || document.querySelector(".ytd-menu-popup-renderer");
				let hideButton = hideMenu.querySelectorAll("yt-formatted-string, yt-list-item-view-model");
				if (!isShort) hideButton[hideButton.length-1].click();
				else hideButton[hideButton.length-2].click();
				//autoHideHidden();
			}, 4);

			break;
		}
		else {
			target = target.parentNode;
		}
	}
}
document.addEventListener('mouseup', autoHideClicked);