Skip to content

Instantly share code, notes, and snippets.

@walkeralencar
Created February 16, 2020 05:05
Show Gist options
  • Save walkeralencar/68c967fd3b5e36ab52eff3cdac2fa30e to your computer and use it in GitHub Desktop.
Save walkeralencar/68c967fd3b5e36ab52eff3cdac2fa30e to your computer and use it in GitHub Desktop.
Improve informations from albiononline2d
// Improve informations from albiononline2d
// Load any page, open console, and use the code.
// Author: Walker de Alencar <walkeralencar@gmail.com>
/* Works only for journals
config.itemsForMarketData = config.itemsForMarketData.split(',')
config.itemsForMarketData.forEach(function(item,key){
if (!item.includes('_FULL')) {
$("#" + item).prop('id',item + '_FULL');
config.itemsForMarketData[key] = item + '_FULL';
}
});
config.itemsForMarketData = config.itemsForMarketData.join(',');
/* JournalsEnd */
var locations = 'Caerleon,Bridgewatch,Thetford,Fort%20Sterling,Lymhurst,Martlock,Black%20Market';
var tData = [];
$.get('https://www.albion-online-data.com/api/v2/stats/prices/' + config.itemsForMarketData + '?locations=' + locations, function(response) {
var item_id = '';
response.forEach(function(cityItem) {
if (cityItem.item_id != item_id) {
$('#' + $.escapeSelector(cityItem.item_id) + " span").remove();
$('#' + $.escapeSelector(cityItem.item_id)).html($('#' + $.escapeSelector(cityItem.item_id)).html().replace(/&nbsp;/gi,''));
if (item_id !== '' && tData[item_id] !== undefined){
tData[item_id].sort(function(a,b){
return a.sell - b.sell;
});
$("#" + $.escapeSelector(item_id) + ' [title="' + tData[item_id][0].city + '"]').addClass("border rounded-circle");
$("#" + $.escapeSelector(item_id) + ' [title="' + tData[item_id].pop().city + '"]').addClass("border");
}
item_id = cityItem.item_id;
}
//if (!cityItem.sell_price_min) return;
var formattedBuyPrice = new Intl.NumberFormat().format(cityItem.buy_price_max);
var formattedSellPrice = new Intl.NumberFormat().format(cityItem.sell_price_min);
var node = '<span class="badge badge-:class" title=":city">:buy | :sell</span>&nbsp;'
.replace(':class', cityMapping[cityItem.city])
.replace(':city', cityItem.city)
.replace(':buy', formattedBuyPrice)
.replace(':sell', formattedSellPrice);
if ( tData[item_id] === undefined ) {
tData[item_id] = [];
}
tData[item_id].push({city: cityItem.city, buy: cityItem.buy_price_max, sell: cityItem.sell_price_min})
$('#' + $.escapeSelector(cityItem.item_id)).append(node);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment