what.cd highlighting

Adds an extra column of the ratio of seeds to leeches. Useful for looking at good torrents to seed

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

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

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         what.cd highlighting
// @namespace    
// @version      0.1
// @description  Adds an extra column of the ratio of seeds to leeches. Useful for looking at good torrents to seed
// @author       Jordan
// @match        https://what.cd/torrents.php*
// @grant        none
// ==/UserScript==

function median(values) {
    values.sort( function(a,b) {return a - b;} );
    var half = Math.floor(values.length/2);
    if(values.length % 2)
        return values[half];
    else
        return (values[half-1] + values[half]) / 2.0;
}

$('.edition_info').attr('colspan',10);
$('.sign.leechers').after('<td>Ratio</td>');

// Loop all rows, calculate ratio, add to an array of ratios to get median later
all_ratios = [];
$('tr.group_torrent, tr.group').each(function() {
     var leechers = $(this).find('td.number_column:last').html();
     var seeders = $(this).find('td.number_column:last').prev().html();
     if(typeof leechers == 'undefined' || typeof seeders == 'undefined') {
     	// console.log('undefined');
     } else {
	     leechers = leechers.replace(',','');
	     seeders = seeders.replace(',','');
	 }
     var ratio = (leechers/seeders);
     if(typeof ratio != 'undefined' && !isNaN(ratio) && ratio != 'Infinity' ) {
     	all_ratios.push(ratio);
     }
});


// Get the median, get the max, find a point inbetween to give us useful highlighting
var ratio_median = median(all_ratios);
var max = Math.max.apply( Math, all_ratios );
var upper_fourth = ratio_median + ((max - ratio_median) / 3 );

// Loop again, this should probably have been unified with the looping above
// Output an extra cell per row, highlighted if above the target level
$('tr.group_torrent, tr.group').each(function() {
     var leechers = $(this).find('td.number_column:last').html();
     var seeders = $(this).find('td.number_column:last').prev().html();
     if(typeof leechers == 'undefined' || typeof seeders == 'undefined') {
     	// console.log('undefined');
     } else {
	     leechers = leechers.replace(',','');
	     seeders = seeders.replace(',','');
	 }
     // console.log(leechers + '/' + seeders + '=' + ratio);
     var ratio = (leechers/seeders).toFixed(2);
     if(typeof ratio != 'undefined' && !isNaN(ratio) ) {
     	all_ratios.push(ratio);
     	if(ratio > upper_fourth || ratio == 'Infinity') {
     		var style = 'font-weight:bold;';
     	} else {
     		var style = null;
     	}
        $(this).find('td.number_column:last').after('<td style="' + style + '">' + ratio + '</td>');
     }
});