Last active
May 24, 2016 15:41
-
-
Save xsbr/b409c0149b7ac2029e81de6abdbb72aa to your computer and use it in GitHub Desktop.
MercadoLivre Anúncios AdvancedView
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
// @name MercadoLivre Anúncios AdvancedView | |
// @author Ricardo Santos | |
// @version 0.1 | |
var get_visits = function(data) { | |
html1 = '<tr>'; | |
html2 = '<tr>'; | |
for(var i=0; i<data.results.length; i++) { | |
v = data.results[i]; | |
html1 += '<th><small>'+v.date.substring(8,10)+'/'+v.date.substring(5,7)+'</small></th>'; | |
html2 += '<td>'+v.total+'</td>'; | |
} | |
html1 += '</tr>'; | |
html2 += '</tr>'; | |
html = '<fieldset style="margin-left: 100px"><table class="mytable">'+html1+html2+'</table></fieldset>'; | |
$('div.product-gallery-container').append(html); | |
} | |
var display_apijson = function(data) { | |
var st = data.start_time; | |
var d1 = new Date(st.substring(0,4), st.substring(5,7)-1, st.substring(8,10)); | |
var d2 = new Date(); | |
var days = Math.floor((d2-d1)/86400000); | |
var st_str = st.substring(8,10)+'-'+st.substring(5,7)+'-'+st.substring(0,4); | |
$('#tmbar').prepend('<b>Inicio:</b> '+st_str+' ('+days+' dias)'); | |
var comissao = 0.16; | |
if(data.listing_type_id == 'gold_special') { | |
comissao = 0.1; | |
} | |
var frete = 0; | |
if(data.shipping.free_shipping == true) { | |
frete = 14.02; | |
} | |
var liquido = data.price-(data.price*comissao)-frete; | |
liquido = Math.floor(liquido)+'<sup>'+Math.floor((liquido-Math.floor(liquido))*100)+'</sup>'; | |
$('article.price.ch-price').append(' <small style="font-size: 0.5em; color: #999">liquido: R$ '+liquido+'</small>'); | |
display_stoq(data.variations); | |
} | |
var start_tm = function() { | |
$(document).ready(function() { | |
var seller_link = $('a[title="Ver mais dados deste vendedor"]').attr('href'); | |
var seller_nick = seller_link.replace('http://perfil.mercadolivre.com.br/', ''); | |
var item_id = $('#productInfo input[name=item_id]').val(); | |
$('div[class="nav-path bg-great-info"').append('<div style="text-align: center; font-size: 1.5em; padding: 10px 0" id="tmbar"></div>'); | |
tmbar = $('#tmbar'); | |
tmbar.append(' - <b>ID:</b> '+item_id); | |
tmbar.append(' <a class="ch-btn" href="https://vender.mercadolivre.com.br/item/update?itemId='+item_id+'" target="_blank">Modificar</a>'); | |
tmbar.append(' <a class="ch-btn" href="https://myaccount.mercadolivre.com.br/sales/list#type=recent&page=1&search='+item_id.substr(3)+'" target="_blank">Vendas</a>'); | |
tmbar.append(' <b>Vendedor:</b> <a href="'+seller_link+'" target="_blank" style="color: #00f">'+seller_nick+'</a>'); | |
$.getJSON('https://api.mercadolibre.com/items/'+item_id+'/visits/time_window?last=10&unit=day', null, get_visits); | |
$.getJSON('https://api.mercadolibre.com/items/'+item_id, null, display_apijson); | |
//display_stoq(); | |
}); | |
} | |
function display_stoq(array_vars) { | |
//var l = ml.vip.isVariation.length; | |
var l = array_vars.length; | |
var variations = {}; | |
for(var i=0; i<l; i++) { | |
var v = array_vars[i]; | |
var thumb = v.picture_ids[0]; | |
if(typeof variations[thumb] == "undefined") { | |
variations[thumb] = []; | |
} | |
variations[thumb][variations[thumb].length] = v; | |
} | |
var html = '<style type="text/css">.mytable { background: #fff; border: 1px solid #000; font-size: 1em; text-align: center; border-collapse: collapse; } .mytable td, .mytable th { border: 1px solid #000; padding: 2px; vertical-align: middle; }</style>'; | |
html += '<fieldset><table class="mytable"><tr><th>Tam</th><th>Estoq</th><th>Modelo</th><th>Vendas</th></tr>'; | |
var bgcolor = '#fff'; | |
for(var thumb2 in variations) { | |
if( bgcolor == '#fff' ) { | |
bgcolor = '#e5e5ff'; | |
} else { | |
bgcolor = '#fff'; | |
} | |
var img = '<img src="http://mlb-s2-p.mlstatic.com/'+thumb2+'-R.jpg" width="70" height="70" />'; | |
var v = variations[thumb2]; | |
for(var j=0; j<v.length; j++) { | |
variation = v[j]; | |
html += '<tr style="background: '+bgcolor+'">'; | |
var t = '-'; | |
for(var k=0; k<variation.attribute_combinations.length; k++) { | |
if(variation.attribute_combinations[k].name == 'Tamanho') { | |
t = variation.attribute_combinations[k].value_name; | |
} | |
} | |
html += '<td><b>'+t+'</b></td>'; | |
html += '<td>'+variation.available_quantity+'</td>'; | |
if(j == 0) { | |
html += '<td rowspan="'+v.length+'">'+img+'</td>'; | |
} | |
html += '<td><small>'+variation.sold_quantity+'</small></td></tr>'; | |
} | |
} | |
html += '</table></fieldset>'; | |
$('fieldset.shipment-methods-fildset').after(html); | |
} | |
var check_jquery = function() { | |
if(typeof $ === "undefined") | |
{ | |
setTimeout(check_jquery, 1000); | |
} else { | |
start_tm(); | |
} | |
} | |
check_jquery(); |
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 MercadoLivre Anúncios AdvancedView | |
// @namespace http://produto.mercadolivre.com.br/ | |
// @version 0.1 | |
// @description MercadoLivre Anúncios AdvancedView | |
// @author Ricardo Santos | |
// @match http://produto.mercadolivre.com.br/MLB-* | |
// @grant none | |
// ==/UserScript== | |
var remoteScript = document.createElement('script'); | |
remoteScript.src = 'https://gist.githubusercontent.com/xsbr/b409c0149b7ac2029e81de6abdbb72aa/raw?ts='+(+new Date()); | |
document.body.appendChild(remoteScript); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment