what.cd highlighting

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==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>');
     }
});