youtube_ex

enhanced youtube

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        youtube_ex
// @namespace   http://userscripts.org/users/
// @include     https://www.youtube.com/*
// @version     0.2
// @grant	none
// @description enhanced youtube
// ==/UserScript==

//======  common ========

function parseQueryStringToDictionary(queryString)
{
	var dictionary = {};

	var pos=queryString.indexOf('?');
	if (pos>=0)
	{
		queryString = queryString.substr(pos+1);
	}

	var parts = queryString.split('&');

	for(var i = 0; i < parts.length; i++)
	{
		var keyValuePair = parts[i].split('=');
		var key = keyValuePair[0];
		var value = keyValuePair[1];

		value = decodeURIComponent(value);
		value = value.replace(/\+/g, ' ');

		dictionary[key] = value;
	}

	return dictionary;
}


var obv_cfg={attributes: false, childList: true, characterData: false};

function observer_factory(callback, isforeach=true)
{
	var cb=isforeach ? function(mutations) {mutations.forEach(callback);} : callback;
	return new MutationObserver(cb);
}

function simpleRemoveElement(sel)
{
	var sep=sel.indexOf("##");
	var selector=sep>=0 ? sel.substr(sep+2) : sel;
	var node=document.querySelector(selector);
	if (node) node.parentNode.removeChild(node);
}

function killElementAttribute(attrname)
{
	var nodes=document.querySelectorAll('['+attrname+']');
	for (var i=0;i<nodes.length;i++)
	{
		nodes[i].removeAttribute(attrname);
	}
}

//======= end of common =========

function trackless()
{
	observer_factory(function (stub) {
		killElementAttribute("data-sessionlink");
		killElementAttribute("data-visibility-tracking");
	},false).observe(document.body, obv_cfg);
}


trackless();

function norecommend()
{
	Array.prototype.slice.call(document.querySelectorAll("span.view-count")).filter(function (node){
		return /Recommended for you/i.test(node.innerHTML);
	}).forEach(function (node){
		var pnode=node.parentNode;
		while (pnode.tagName.toLowerCase()!="a" || Array.prototype.slice.call(pnode.classList).indexOf("content-link")<0){
			if (pnode==document.body) return;
			pnode=pnode.parentNode;
		}
		var recommend_link=pnode.href;
		while (pnode.tagName.toLowerCase()!="li" || Array.prototype.slice.call(pnode.classList).indexOf("video-list-item")<0){
			if (pnode==document.body) return;
			pnode=pnode.parentNode;
		}
		pnode.parentNode.removeChild(pnode);
		var vid=parseQueryStringToDictionary(recommend_link).v;
		//Array.prototype.slice.call(document.querySelectorAll('a#ytp-suggestion-set[href*="'+vid+'"]'));
	});
}

norecommend();