Greasy Fork

Greasy Fork is available in English.

Youtube: Hide Recommended Videos

Hide the recommended videos section

当前为 2016-09-14 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name            Youtube: Hide Recommended Videos
// @namespace       https://github.com/Zren
// @version         2
// @description     Hide the recommended videos section
// @icon            https://youtube.com/favicon.ico
// @author          Zren
// @include         http*://*.youtube.com/*
// @include         http*://youtube.com/*
// @include         http*://*.youtu.be/*
// @include         http*://youtu.be/*
// @run-at          document-start
// ==/UserScript==

//--- Utils
function observe(selector, config, callback) {
	var observer = new MutationObserver(function(mutations) {
		mutations.forEach(function(mutation){
			callback(mutation);
		});
	});
	var target = document.querySelector(selector);
	observer.observe(target, config);
	return observer;
}

var documentLoaded = false;
function tickUntilLoad(callback) {
	function tick() {
		callback();
		if (!documentLoaded) {
			window.requestAnimationFrame(tick);
		}
	}
	callback();
	window.requestAnimationFrame(tick);
}

function watchBodyForChanged(callback) {
	callback();
	observe('body', {
		attributes: true,
	}, function(mutation) {
		if (mutation.attributeName === 'class') {
			callback();
		}
	});
}

//---
function getParent(e, selector) {
	var e2 = e.parentNode;
	while (e2) {
		if (e2.matches(selector)) {
			return e2;
		}
		e2 = e2.parentNode;
	}
	return null;
}

function hideSection(url) {
	var a = document.querySelector('.shelf-title-row a[href="' + url + '"]');
	if (a) {
		var section = getParent(a, '.item-section');
		section.style.display = 'none';
	}
}

function hideStuff() {
	hideSection("/feed/recommended");
	//hideSection("/feed/history"); // Watch it Again
	//hideSection("/user/IGNentertainment"); // IGN
}

tickUntilLoad(hideStuff);
document.addEventListener('DOMContentLoaded', function(){
	documentLoaded = true;
	hideStuff();
	watchBodyForChanged(hideStuff);
});