NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name SG color-code entry amount.
// @namespace https://www.steamgifts.com
// @version 0.2
// @description Color-codes the "giveaway column" line in steamgifts.com according to the number of entries to a giveaway.
// @author Moo64c
// @match *://www.steamgifts.com/*
// @grant GM_xmlhttpRequest
// ==/UserScript==
var current_url = window.location.href;
$( document ).ready(function() {
if (/www.steamgifts.com\/($|giveaways$|giveaways\/search)/.test(current_url)) {
// On main giveaways list page.
// Add color-coded "chance calculation".
var morph = function(start, stop, point,scale) {
return Math.round(((stop - start) * point / scale) + start);
};
$('.giveaway__links').each(function() {
var span = $(this).find('.fa-tag').siblings('span');
var parent = span.parent().parent().parent();
// Find out if there are more copies.
var copies = 1;
parent.find('.giveaway__heading span.giveaway__heading__thin').each(function() {
var text = $(this).text();
if (text.indexOf('Copies') >= 0) {
copies = parseInt(text.replace(/[^0-9]/gi, ''));
}
});
var entries = parseInt(span.text().replace(/[^0-9]/gi, ''));
var value = entries / copies;
// Choose color.
var hue = morph(120,0,value,2000); // Green - 120, yellow ~ 60, Red - 0.
var saturation = '100%';
// Should be ~50%
var lightnessCalc = morph(70,20,value,2000);
if (value > 2000) {
// Only darken from this point on.
lightnessCalc = morph(40,10,value,6000);
hue = 0;
}
var lightness = lightnessCalc+'%';
var hsl = 'hsl('+hue+','+saturation+','+lightness+')';
var hslText = 'hsl('+(120+hue)+','+saturation+','+(100-lightnessCalc)+'%)';
parent.find('.giveaway__columns').first().children().each(function() {
$(this).css({
background: hsl,
color: hslText,
fontWeight: 'bold'
});
});
});
}
});