Created
July 29, 2014 14:18
-
-
Save Mezzle/d81f88c715987588728e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Seed From toolbox | |
// @namespace http://esl.eu/ | |
// @version 0.2.9 | |
// @description Create button that will seed from toolbox | |
// @match http://www.esl.eu/eu/*/admin_contestants* | |
// @copyright 2014+, Martin Meredith | |
// ==/UserScript== | |
var cup_url; | |
cup_url = window.location.href.replace('/admin_contestants','/').replace(/\/\/$/, '/'); | |
jQuery.ajax({ | |
type: 'GET', | |
dataType: 'jsonp', | |
data: {}, | |
url: 'http://toolbox1.tedc.de/go4/get_series_by_url?url=' + cup_url + '&jsonpCallbackFunction=?', | |
success: function (data) { | |
var slug = data.slug | |
jQuery('input[value="Randomize Seedings"]').after('<input type="button" id="toolboxseed" value="Seed From Toolbox" />'); | |
jQuery('#toolboxseed').click( | |
function () { | |
var contestants = {}; | |
var count = 0; | |
var result; | |
var arrayToSeed = new Array(); | |
contestants_to_send = new Array(); | |
jQuery('form table tr').each(function (index) { | |
var id = jQuery(this).find('td').eq(2).html(); | |
if (id == parseInt(id)) { | |
contestants_to_send.push(id); | |
} | |
}); | |
jQuery.ajax({ | |
type: 'POST', | |
crossDomain: true, | |
data: {contestants: contestants_to_send.join(",")}, | |
url: 'http://toolbox1.tedc.de/go4/' + slug + '/seed', | |
success: function (data) { | |
console.log(data); | |
result = data; | |
var count = 0; | |
jQuery('form table tr').each(function (index) { | |
var id = jQuery(this).find('td').eq(2).html(); | |
var contestantRanking = data[id]; | |
if (!isNaN(contestantRanking) && contestantRanking > 0) { | |
arrayToSeed[count] = id; | |
count++; | |
} | |
}); | |
arrayToSeed.sort(function(a,b) { | |
return data[b]-data[a] | |
}); | |
console.log(arrayToSeed); | |
jQuery('form table tr').each(function (index) { | |
var id = jQuery(this).find('td').eq(2).html(); | |
var seed = arrayToSeed.indexOf(id); | |
var textfield = jQuery(this).find('td input:text').first(); | |
if (!isNaN(seed) && seed >= 0) { | |
jQuery(textfield).val(seed+1); | |
} else { | |
jQuery(textfield).val(0); | |
} | |
}); | |
} | |
}); | |
} | |
); | |
}} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment