Created
September 15, 2012 16:58
-
-
Save anonymous/3728825 to your computer and use it in GitHub Desktop.
http://www.gw2spidy.com Greasemonkey script to improve search list.
This file contains 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 gw2spidy | |
// @description Improve gw2spidy results view | |
// @include http://www.gw2spidy.com/* | |
// @version 1 | |
// ==/UserScript== | |
function pad_me(value) | |
{ | |
return value > 9 ? value : '0' + value; | |
} | |
function price_to_number(value) | |
{ | |
var gold = value.match(/(\d+)g/); | |
var silver = value.match(/(\d+)s/); | |
var copper = value.match(/(\d+)c/); | |
var result = 0; | |
if (gold) result += parseInt(gold[1]) * 10000; | |
if (silver) result += parseInt(silver[1]) * 100; | |
if (copper) result += parseInt(copper[1]); | |
return result; | |
} | |
function number_to_price(value) | |
{ | |
if (value == 0) | |
{ | |
return 'n/a'; | |
} | |
var copper = value % 100; | |
value = (value - copper) / 100; | |
var result = '<span class="copper">' + (value > 0 ? pad_me(copper) : copper) + '</span>'; | |
if (value > 0) | |
{ | |
var silver = value % 100; | |
value = (value - silver) / 100; | |
result = '<span class="silver">' + (value > 0 ? pad_me(silver) : silver) + '</span> ' + result; | |
} | |
if (value > 0) | |
{ | |
var gold = value % 100; | |
result = '<span class="gold">' + gold + '</span> ' + result; | |
} | |
return result; | |
} | |
function count_to_number(value) | |
{ | |
return parseInt(value); | |
} | |
var whole_table = $('.item-list-table'); | |
whole_table.before("<style> \ | |
.item .name img { height: 32px; } \ | |
.well { background-color: rgba(45, 45, 45, 0.8); color: white; } \ | |
.table-striped tbody tr:nth-child(2n) td, .table-striped tbody tr:nth-child(2n) th \ | |
{ background-color: rgba(79, 79, 79, 0.6) } \ | |
.table-striped tr:hover td { background-color: transparent !important; } \ | |
.table-striped tr:hover { background-color: black; } \ | |
.item .currency, .item .numeric_count { text-align: right; } \ | |
.item .profit { font-weight: bold; } \ | |
.item .gold { color: #FDC84E; } \ | |
.item .silver { color: #CBCBCB; } \ | |
.item .copper { color: #D47F46; } \ | |
.table-striped tr.selected { background-color: green; } \ | |
th.profit { text-align: right; } \ | |
</style>" | |
); | |
whole_table.find('th.min_sale_unit_price').attr('colspan', 2); | |
whole_table.find('th.max_offer_unit_price').attr('colspan', 2) | |
.after('<th class="profit" title="May be off by several copper, be cautious with tiny profits!">Potential Profit *</th>'); | |
whole_table.find('.item').each(function(a, b) | |
{ | |
var row = $(b) | |
var sales_cell = row.find('.min_sale_unit_price'); | |
var offers_cell = row.find('.max_offer_unit_price'); | |
var sales = count_to_number(sales_cell.attr('title')); | |
var sell_for = price_to_number(sales_cell.text()); | |
var offers = count_to_number(offers_cell.attr('title')); | |
var buy_for = price_to_number(offers_cell.text()); | |
var profit = 'n/a'; | |
if (sell_for != 0 && buy_for != 0) | |
{ | |
profit = Math.floor(sell_for * 0.85 - buy_for); | |
if (profit == 0) | |
{ | |
profit = 'none'; | |
} | |
else if (profit < 0) | |
{ | |
profit = 'loss'; | |
} | |
else | |
{ | |
profit = number_to_price(profit); | |
} | |
} | |
sales_cell.remove(); | |
offers_cell.remove(); | |
row.append('<td class="numeric_count">' + sales + '</td>'); | |
row.append('<td class="currency">' + number_to_price(sell_for) + '</td>'); | |
row.append('<td class="numeric_count">' + offers + '</td>'); | |
row.append('<td class="currency">' + number_to_price(buy_for) + '</td>'); | |
row.append('<td class="currency profit">' + profit + '</td>'); | |
}) | |
.click(function(event) | |
{ | |
$(this).toggleClass('selected'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment