YTRating

Shows the rating of videos in the related videos

La data de 15-06-2014. Vezi ultima versiune.

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

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

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.

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

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          YTRating
// @namespace     absolut-fair.com
// @description   Shows the rating of videos in the related videos
// @include       http://*youtube.com*
// @include       https://*youtube.com*
// @require       http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
// @version       1.0.3
// ==/UserScript==

$(document).ready(function () {
	window.setInterval(function() { loadrating(); },1000);
});

function loadrating(div,link)
{
	$('.yt-thumb-clip, img[alt="Thumbnail"], img[data-thumb]').closest('a').each(function (i) {
        //console.log("ytrating "+i);
		if( $(this).attr('done') == 1) return true;
		else $(this).attr('done','1');
	
		var that=this;
		var inda=i;
		var hrea = $(this).attr('href');
		if(hrea.indexOf('?v=')==-1) 
		{
			if($(this).closest('div[data-context-item-id]').length)
			{
				hrea = "/watch?v="+($(this).closest('div[data-context-item-id]').attr("data-context-item-id"));
			}
			else return true;
		}
		hrea = hrea.replace("&","&");
		hrea=hrea+"&";
		var vidid = hrea.between('?v=','&');
		
		//alert(vidid);
	
		GM_xmlhttpRequest({
			method: "GET",
			url: "http://gdata.youtube.com/feeds/api/videos/"+vidid+"?v=2",
			headers: {
				"Accept": "text/xml",
				"GData-Version": "2",
				"X-GData-Key": "key=AI39si59MgtnnLtTwZTnvZ--XNvnXWlYpVcDfYO8AJK-CJSmS3pTytqktlxTp3YVriK0IYGcx1z2BK1_ud1DEduKBAI7T3JdpQ"
			  },
			onload: function(resp) {
				var xmldat = new DOMParser().parseFromString(resp.responseText, "text/xml");
				var conti=resp.responseText;
				var rating = xmldat.getElementsByTagNameNS("http://gdata.youtube.com/schemas/2007","rating");
				if(conti.indexOf("yt:rating")!=-1)
				{
					var likes = rating[0].getAttribute("numLikes");
					var dislikes = rating[0].getAttribute("numDislikes");
				}
				else 
				{
					var likes="1";
					var dislikes="0";
				}
				//console.log("Ergebnis:"+likes+"/"+dislikes);
				likes=likes.replace('.', '');
				dislikes=dislikes.replace('.', '');
				if(likes.length>0 && conti.indexOf("action='rate' permission='denied'")==-1)
				{
					var resul = likes+"/"+dislikes;
					likes=parseInt(likes);
					dislikes=parseInt(dislikes);
					
					var dr = (likes/(likes+dislikes))*100;
					dr=Math.round(dr);

					if((likes+dislikes)>80)
					{
						if(dr > 70) $('.video-time', that).append("<label style='color:#82FA58;font-size:18px;'> "+dr+"%</label>");
						else if(dr > 40) $('.video-time', that).append("<label style='color:#C9C618;font-size:18px;'> "+dr+"%</label>");
						else $('.video-time', that).append("<label style='color:red;font-size:18px;'> "+dr+"%</label>");
					}
					else 
					{
						if((likes+dislikes)==0)	$('.video-time', that).append("<label style='color:#848484; font-size:18px;'> NO</label>");
						else $('.video-time', that).append("<label style='color:#848484; font-size:18px;'> "+dr+"%</label>");
					}
				}
				else 
				{
					$('.video-time', that).append("<label style='color:red;font-size:18px;'> OFF</label>");
				}
			}
		});
		//return false;
	});
}


String.prototype.between = function(prefix, suffix) {
s = this;
var i = s.indexOf(prefix);
if (i >= 0) {
s = s.substring(i + prefix.length);
}
else {
return '';
}
if (suffix) {
i = s.indexOf(suffix);
if (i >= 0) {
s = s.substring(0, i);
}
else {
return '';
}
}
return s;
}