// ==UserScript== // @name Amazon a Pesos Argentos // @namespace dsr-amazon-pesos-argentos // @description Mostrar precios en pesos argentinos y comparador de precios con MercadoLibre y otras tiendas de amazon // @version 1.0 // @require https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js // @require https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.2.1/mustache.min.js // @include *amazon.com/* // @include *amazon.co.uk/* // @include *amazon.ca/* // @include *amazon.es/* // @include *amazon.de/* // @include *amazon.fr/* // @include *amazon.it/* // @connect amazon.com // @connect amazon.co.uk // @connect amazon.ca // @connect amazon.es // @connect amazon.de // @connect amazon.fr // @connect amazon.it // @connect geeklab.com.ar // @connect europa.eu // @connect mercadolibre.com // @downloadURL none // ==/UserScript== var BANNER = "[ARG-LOG]"; var LAST_RUN = "last_run_"; var CURRENCY_RATE = "currency_rate_"; var CURRENCY_RATE_EUR = "currency_rate_eur_"; var decimalPlaces = 2; var prefixCurrencySymbol = true; var taxPorcentage = 0; //3.6; //no se de donde es esto var currencyToSymbol = 'ARS $'; // estos shims son de https://gist.githubusercontent.com/arantius/3123124/raw/grant-none-shim.js function GM_addStyle(aCss) { 'use strict'; let head = document.getElementsByTagName('head')[0]; if (head) { let style = document.createElement('style'); style.setAttribute('type', 'text/css'); style.textContent = aCss; head.appendChild(style); return style; } return null; } function GM_getValue(aKey, aDefault) { 'use strict'; let val = localStorage.getItem('dsr-amazon-pesos-argentos_config' + aKey) if (null === val && 'undefined' != typeof aDefault) return aDefault; return val; } function GM_setValue(aKey, aVal) { 'use strict'; localStorage.setItem('dsr-amazon-pesos-argentos_config' + aKey, aVal); } (function() { if (typeof jQuery === 'undefined') { console.log(BANNER, 'jQuery === undefined'); return; } console.log(BANNER, 'principal'); GM_addStyle('.price-ars{color:green;display:inline-block;margin:0 8px;background:linear-gradient(to bottom,#add8e6,#fff,#add8e6);border-radius:8px;padding:0 6px}' + '#sc-buy-box .price-ars{font-size:12px;display:block;padding:0;margin:0;background:0 0}div#sc-buy-box{margin-bottom:-14px}'); GM_addStyle('#snoop-icon{margin-left:4px;width:30px;height:20px}#snoop-placeholder{width:32px}div.snoop-loader{width:13px;height:13px}div.snoop-tooltip,div.snoop-tooltip-ml{display:none;font-size:13px;border-image:none;letter-spacing:0}' + 'div.snoop-tooltip div.entry,div.snoop-tooltip-ml div.entry{padding-top:5px}span.snoop-price{color:#900;font-size:1em;font-weight:700}span.snoop-warning{color:#C60!important}.snoop-not-found{text-decoration:line-through}' + 'span.snoop-on{color:#000;font-weight:400}div.snoop-credits{font-size:.75em;font-style:italic;text-align:center;margin-top:13px;font-weight:400;color:#666}span.back-link{line-height:0;margin-left:1px;top:-10px;position:relative}' + 'span.back-link>img{top:1;position:relative}span.back-link>a{font-size:1em;text-decoration:none!important}#snoop-icon-ml{margin-left:10px}'); var domainData = { com: { amazonSeller: "ATVPDKIKX0DER", withVAT: false, vat: 0, tag: "23wkznfuzx-20", symbol: "$", priceRegex: /\$\s*([\d,.]+\d)/, currencyFrom: "USD" }, ca: { amazonSeller: "A3DWYIK6Y9EEQB", withVAT: false, vat: 0, tag: "23wkznfuzx01-20", symbol: "CDN$ ", priceRegex: /CDN\$\s*([\d,.]+\d)/, currencyFrom: "CAD" }, uk: { amazonSeller: "A3P5ROKL5A1OLE", withVAT: true, vat: 1.20, tag: "23wkznfuzx00-21", symbol: "£", priceRegex: /£\s*([\d,.]+\d)/, currencyFrom: "GBP" }, es: { amazonSeller: "A1AT7YVPFBWXBL", withVAT: true, vat: 1.21, tag: "23wkznfuzx-21", symbol: "EUR ", priceRegex: /EUR\s*([\s\d,.]+\d)/, currencyFrom: "EUR" }, de: { amazonSeller: "A3JWKAKR8XB7XF", withVAT: true, vat: 1.19, tag: "23wkznfuzx0b-21", symbol: "EUR ", priceRegex: /EUR\s*([\s\d,.]+\d)/, currencyFrom: "EUR" }, fr: { amazonSeller: "A1X6FK5RDHNB96", withVAT: true, vat: 1.20, tag: "23wkznfuzx08-21", symbol: "EUR ", priceRegex: /EUR\s*([\s\d,.]+\d)/, currencyFrom: "EUR" }, it: { amazonSeller: "A11IL2PNWYJU7H", withVAT: true, vat: 1.22, tag: "23wkznfuzx02-21", symbol: "EUR ", priceRegex: /EUR\s*([\s\d,.]+\d)/, currencyFrom: "EUR" }, parseLinks: GM_getValue('parseLinks', true) }; var domain = document.domain.substr(document.domain.lastIndexOf('.') + 1); var rounding = Math.pow(10, decimalPlaces); var rate = GM_getValue(CURRENCY_RATE + domainData[domain].currencyFrom); var lastRun = GM_getValue(LAST_RUN, false); var showVAT = GM_getValue('show_vat', true); function regularPriceParser(price, currency) { price = price.replace(/\s/g, ''); var regex = /^[\d.]+,[\d]{2}$/; var needProperPrice = regex.exec(price); if (needProperPrice) { price = price.replace(/\./g, '').replace(/,/, '.'); } else { price = price.replace(/\,/g, ''); } return parseFloat(price); } function fetchCurrencyData(callback) { jQuery.getJSON( "http://ws.geeklab.com.ar/dolar/get-dolar-json.php" ).done( function(data) { // la api devuelve el precio libre y el blue console.log(BANNER, data); GM_setValue(CURRENCY_RATE + 'USD', data.libre); callback(); } ); } function appendConversionNoVAT(price, matched, offset, string) { return appendConversion(price, matched, offset, string, true); } function appendConversion(price, matched, offset, string, novat, customvat) { var originalPrice = regularPriceParser(matched, domainData[domain].currencyFrom); if (isNaN(originalPrice)) { return price; } if (novat !== true) { if (customvat > 1) { originalPrice /= customvat; } else if (customvat === undefined && domainData[domain].withVAT) { originalPrice /= domainData[domain].vat; } } if (isNaN(rate)) { rate = GM_getValue(CURRENCY_RATE + domainData[domain].currencyFrom); console('fix?', rate); } var converted = formatCurrency(originalPrice * (rate * (taxPorcentage / 100 + 1)), rounding, currencyToSymbol, prefixCurrencySymbol); if (showVAT && novat !== true && (customvat > 1 || (customvat === undefined && domainData[domain].withVAT))) { originalPrice = formatCurrency(originalPrice, rounding, domainData[domain].symbol, prefixCurrencySymbol); return '' + originalPrice + '
' + converted + '
'; } else { return price + '
' + converted + '
'; } } function formatCurrency(num, rounding, symbol, prefix) { sign = (num == (num = Math.abs(num))); num = Math.floor(num * rounding + 0.50000000001); cents = num % rounding; num = Math.floor(num / rounding).toString(); if (cents < 10) { cents = "0" + cents; } for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) { num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3)); } if (prefix) { return (symbol + ((sign) ? '' : '-') + num + '.' + cents); } else { return (((sign) ? '' : '-') + num + '.' + cents + symbol); } } convertCurrency = function(carrito, vat) { switch (carrito) { case 1: if (jQuery('.a-size-base.a-text-bold:contains(Order summary)').length === 0 && jQuery('.a-size-base.a-text-bold:contains(Récapitulatif de commande)').length === 0 && jQuery('.a-size-base.a-text-bold:contains(Riepilogo ordine)').length === 0 && jQuery('.a-size-base.a-text-bold:contains(Resumen del pedido)').length === 0 && jQuery('.a-size-base.a-text-bold:contains(Zusammenfassung der Bestellung)').length === 0 && jQuery('.ap_popover.ap_popover_sprited.snoop-tooltip').length === 0) { return false; } else { if (jQuery('#sc-buy-box.price-ars-cart').length === 0) { jQuery('#sc-buy-box').addClass('price-ars-cart'); } else { return false; } } break; case 2: if (jQuery('.entry.snoop-price:not(.snoop-warning):not(.price-ars-cart)').length === 0) { return false; } break; default: break; } console.log(BANNER, 'Cambiando precios', carrito); jQuery('.a-column.a-span3.a-text-right.a-span-last.sc-value').removeClass('a-span3').addClass('a-span4'); jQuery('.a-column.a-span9.sc-text').removeClass('a-span9').addClass('a-span8'); jQuery('a.a-popover-trigger.a-declarative:contains(Estimated)').html('Shipping & handling '); if (carrito == 2) { jQuery('.entry.snoop-price:not(.snoop-warning)').each(function() { var text = jQuery(this).text(); if (jQuery(this).children().length === 0 && text.indexOf(domainData[domain].symbol) != -1 && text.indexOf('ARS') == -1) { jQuery(this).addClass('price-ars-cart').html(text.replace(domainData[domain].priceRegex, appendConversion)); } }); } else { jQuery('span:not(:has(*))').each(function() { var text = jQuery(this).text(); if (jQuery(this).children().length === 0 && text.indexOf(domainData[domain].symbol) != -1 && text.indexOf('ARS') == -1) { if (jQuery(this).parents('#sc-buy-box').length == 1 || window.location.href.indexOf("/gp/css/summary/") > -1 || window.location.href.indexOf("/order-details") > -1 || window.location.href.indexOf("/order-history") > -1) { jQuery(this).html(text.replace(domainData[domain].priceRegex, appendConversionNoVAT)); } else { var customVAT = function(price, matched, offset, string) { return appendConversion(price, matched, offset, string, false, vat); }; jQuery(this).html(text.replace(domainData[domain].priceRegex, customVAT)); } } }); } }; function parseLinks() { $('head').append(''); $('a[href*="/dp/"]:not([href*="?tag="])').each(function(i, item) { $(item).attr('href', $(item).attr('href').replace('?', '?tag=' + domainData[domain].tag + '&')); }); } var running_convert_1 = false; var running_convert_2 = false; $(document).ready(function() { console.log(BANNER, 'onReady'); //$('#nav-tools').prepend('Configurar Script'); if (domainData.parseLinks) { parseLinks(); } var ageInHours = lastRun ? (new Date() - lastRun) / 1000 / 60 / 60 : false; if (isNaN(rate) || ageInHours === false || ageInHours < 3) { console.log(BANNER, 'Refreshing conversion rates...', ageInHours, lastRun); fetchCurrencyData(function () { refreshRates(function () { lastRun = new Date(); GM_setValue(LAST_RUN, lastRun); convertCurrency(); }); }); } else { console.log(BANNER, 'Currency rate from cache: ', rate); convertCurrency(); } $('.a-fixed-right-grid-col.a-col-right').bind("DOMSubtreeModified", function(e) { if (running_convert_1 === false) { console.log(BANNER, 'Auto 1'); running_convert_1 = true; setTimeout(function() { convertCurrency(1); running_convert_1 = false; }, 1000); } }); // este es el contenedor donde se ve el precio del producto $('#priceblock_ourprice').bind("DOMSubtreeModified", function(e) { if (running_convert_2 === false) { console.log(BANNER, 'Auto 2'); running_convert_2 = true; setTimeout(function() { convertCurrency(2); running_convert_2 = false; }, 1000); } }); /* //////////////////////////////////////////////////////////////// PRECIOS DE OTRAS TIENDAS //////////////////////////////////////////////////////////////// */ var asin = $('#ASIN').val(); if (asin === undefined) { return; } snoop.initialize(asin, domainData, domain); }); })(); function refreshRates(callback) { jQuery.get( 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml' ).done(function(data) { var $document = $(data); // cotizaciones usdToEur = parseFloat($document.find('Cube[currency="USD"]').attr('rate')); gbpToEur = parseFloat($document.find('Cube[currency="GBP"]').attr('rate')); GM_setValue(CURRENCY_RATE_EUR + 'USD', usdToEur); GM_setValue(CURRENCY_RATE_EUR + 'GBP', gbpToEur); GM_setValue(CURRENCY_RATE_EUR + 'EUR', 1); arsToUsd = GM_getValue(CURRENCY_RATE + 'USD'); arsToEur = arsToUsd * usdToEur; // pesificaciones GM_setValue(CURRENCY_RATE + 'GBP', (1 / gbpToEur) * arsToEur); GM_setValue(CURRENCY_RATE + 'EUR', arsToEur); callback(); }); } var Money = function(amount, currency, currency_symbol, extraAmount) { this.amount = amount; this.extraAmount = extraAmount; this.currency = currency; this.currency_symbol = currency_symbol; }; Money.prototype.for = function(currency, currency_symbol) { rate = GM_getValue(CURRENCY_RATE_EUR + this.currency); if (rate === undefined) { return this; } convertedAmount = this.amount * rate; convertedExtraAmount = this.extraAmount !== undefined ? this.extraAmount * rate : undefined; return new Money(convertedAmount, currency, currency_symbol, convertedExtraAmount); }; Money.prototype.toString = function() { if (this.extraAmount === undefined){ return this.currency_symbol + (this.amount.toFixed(2)); } else { return this.currency_symbol + (this.amount.toFixed(2)) + ' - ' + this.currency_symbol + (this.extraAmount.toFixed(2)); } }; Number.prototype.formatMoney = function(c, d, t) { var n = this; c = isNaN(c = Math.abs(c)) ? 2 : c; d = d === undefined ? "." : d; t = t === undefined ? "," : t; var s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); }; var Shop = function(id, title, domain, base_url, currency, currency_symbol, vat, seller) { this.id = id; this.title = title; this.domain = domain; this.base_url = base_url; this.url = this.base_url; this.currency = currency; this.currency_symbol = currency_symbol; this.vat = vat; this.seller = seller; this.setAsin = function(asin) { this.url = this.urlFor(asin); }; this.urlFor = function(asin) { return this.base_url.replace('{asin}', asin); }; this.moneyFrom = function(amount) { console.log(BANNER, 'moneyfrom()', amount); var culture = this.culture; if (amount.indexOf('-') == -1) { var sanitizedAmount = amount.replace(/[^\d^,^.]/g, ''); var regex = /^[\d.]+,[\d]{2}$/; var needProperPrice = regex.exec(sanitizedAmount); if (needProperPrice) { sanitizedAmount = sanitizedAmount.replace(/\./g, '').replace(/,/, '.'); } else { sanitizedAmount = sanitizedAmount.replace(/\,/g, ''); } return new Money(sanitizedAmount, this.currency); } var sanitizedAmounts = amount.split('-').map(function(a) { return a.replace(/[^\d^,^.]/g, ''); }); return new Money(sanitizedAmounts[0], this.currency, sanitizedAmounts[1]); }; }; var Settings = function(asin, domainData, domain) { console.log(BANNER, 'Settings()', asin); this.asin = asin; this.shops = [ new Shop(1, 'amazon.co.uk', 'www.amazon.co.uk', 'https://www.amazon.co.uk/dp/{asin}?smid=A3P5ROKL5A1OLE' + (domainData.parseLinks ? '&tag=' + domainData.uk.tag : ''), 'GBP', '£', domainData.uk.vat, 'Dispatched from and sold by Amazon'), new Shop(2, 'amazon.de', 'www.amazon.de', 'https://www.amazon.de/dp/{asin}?smid=A3JWKAKR8XB7XF' + (domainData.parseLinks ? '&tag=' + domainData.de.tag : ''), 'EUR', 'EUR ', domainData.de.vat, 'Dispatched from and sold by Amazon|Verkauf und Versand durch Amazon'), new Shop(3, 'amazon.es', 'www.amazon.es', 'https://www.amazon.es/dp/{asin}?smid=A1AT7YVPFBWXBL' + (domainData.parseLinks ? '&tag=' + domainData.es.tag : ''), 'EUR', 'EUR ', domainData.es.vat, 'Vendido y enviado por Amazon'), new Shop(4, 'amazon.fr', 'www.amazon.fr', 'https://www.amazon.fr/dp/{asin}?smid=A1X6FK5RDHNB96' + (domainData.parseLinks ? '&tag=' + domainData.fr.tag : ''), 'EUR', 'EUR ', domainData.fr.vat, 'Expédié et vendu par Amazon'), new Shop(5, 'amazon.it', 'www.amazon.it', 'https://www.amazon.it/dp/{asin}?smid=A11IL2PNWYJU7H' + (domainData.parseLinks ? '&tag=' + domainData.it.tag : ''), 'EUR', 'EUR ', domainData.it.vat, 'Venduto e spedito da Amazon'), new Shop(6, 'amazon.com', 'www.amazon.com', 'https://www.amazon.com/dp/{asin}?smid=ATVPDKIKX0DER' + (domainData.parseLinks ? '&tag=' + domainData.com.tag : ''), 'USD', '$', domainData.com.vat, 'Ships from and sold by Amazon.com'), new Shop(7, 'amazon.ca', 'www.amazon.ca', 'https://www.amazon.ca/dp/{asin}?smid=ATVPDKIKX0DER' + (domainData.parseLinks ? '&tag=' + domainData.ca.tag : ''), 'CAD', 'CDN$', domainData.ca.vat, 'Ships from and sold by Amazon.ca') ]; this.shops.forEach(function(shop) { shop.setAsin(asin); }); this.currentShop = this.shops.filter(function(shop) { return shop.domain == document.domain; })[0]; this.desiredCurrency = this.currentShop.currency; if (this.currentShop.currency != this.desiredCurrency) { this.filteredShops = this.shops; } else { this.filteredShops = this.shops.filter(function(shop) { return shop.domain != document.domain; }); } this.shop = function(id) { var shopById = this.shops.filter(function(shop) { return shop.id == id; }); if (shopById.length == 1) return shopById[0]; return null; }; }; var pageScraper = { warning: { networkError: 'Error al consultar', unavailable: 'No disponible', wrongSeller: 'No vendido por Amazon', notFound: 'No encontrado', multipleOptions: 'Opciones multiples' }, getPriceOn: function(shop, displayPriceCB, displayWarningCB) { console.log(BANNER, 'pageScraper.getPriceOn()') jQuery.get( shop.url ).done(function(data) { var regex = /[nb]\s*?id="priceblock_[\w]*?price".*?>(.*?)
' + '
{{#shops}}
' + ' en {{title}}
{{/shops}}
' + ''; var page = { addTooltipToPage: function(tooltipMarkup) { var $placeholderMarkup = $('Placeholder'); var $imageMarkup = $(''); var $imageMarkupMELI = $(''); var $container = this.findAppropriateTooltipContainer(); var $settings = 'Configurar Script'; var $containerHeader = $('#nav-tools'); var tooltipTemplateML = '
' + '
' + '
Cargando...
'; var tooltipTemplateSettings = ''; if ($('#merchant-info').text().trim().replace(/\s\s+/g, ' ').match(new RegExp(settings.currentShop.seller, 'i')) === null && $('#olp_feature_div').length > 0) { var merchant_expected = settings.currentShop.base_url.match(/smid=([A-Z0-9]+)/); var merchant_current = window.location.href.match(/smid=([A-Z0-9]+)/); if (merchant_expected && merchant_current && merchant_expected[1] == merchant_current[1]) { $container.after('   [Este producto no lo vende Amazon]   '); } else { $container.after('   [Cambiar al vendido por Amazon]   '); } } $container.after($imageMarkupMELI); $container.after(tooltipTemplateML); $container.after($imageMarkup); $container.after(tooltipMarkup); if ($('#pesos-config').length === 0) { $containerHeader.prepend($settings); $containerHeader.prepend(tooltipTemplateSettings); tooltipSettings.registerShowHideHandlers(); } tooltip.registerShowHideHandlers(); tooltipML.registerShowHideHandlers(); convertCurrency(); }, findAppropriateTooltipContainer: function() { var $tries = [ $('table.product .priceLarge:first', $('#priceBlock')), $('#priceblock_ourprice'), $('#priceblock_saleprice'), $('#availability_feature_div > #availability > .a-color-price'), $('div.buying span.availGreen', $('#handleBuy')), $('div.buying span.availRed:nth-child(2)', $('#handleBuy')) ]; for (var i = 0; i < $tries.length; i++) { if ($tries[i].length > 0) { return $tries[i]; } } throw new Error('Unable to find the price section.'); }, displayPrice: function($shopInfo, price, vat) { var convertedPrice = price.for(settings.currentShop.currency, settings.currentShop.currency_symbol); var convertedString = convertedPrice.toString(); // este es un fix provisorio hasta que termine el refactor if (convertedString !== 'EUR 0.00') { $shopInfo.text(convertedPrice.toString()); convertCurrency(0, vat); } }, displayWarning: function($shopInfo, warning, addNotFoundClass) { $shopInfo.text(warning).addClass('snoop-warning'); if (addNotFoundClass) { $shopInfo.parent().addClass('snoop-not-found'); } }, registerInitializationHandler: function(shops) { $('#snoop-icon').mouseover(function() { if (window.snoop_tooltipInitialized !== undefined && window.snoop_tooltipInitialized !== false) return; window.snoop_tooltipInitialized = true; $.each(shops, function(index, shop) { var $shopInfo = $('#snoop-shop-' + shop.id); pageScraper.getPriceOn( shop, function(price) { page.displayPrice($shopInfo, shop.moneyFrom(price), shop.vat); }, function(warning, addNotFoundClass) { page.displayWarning($shopInfo, warning, addNotFoundClass); } ); }); }); $('#snoop-icon-ml').mouseover(function() { if (window.snoopML_tooltipInitialized !== undefined && window.snoopML_tooltipInitialized !== false) return; window.snoopML_tooltipInitialized = true; var productName = decodeURI(jQuery('#productTitle').html().replace(' ', ' ').replace(/[^\w\d\s\.]/g, ' ').trim()); meli.showPrices(productName); }); } }; var settings; var snoop = { tooltip: null, asin: null, _startMonitoringAsin: function(domainData, domain) { var observer = new MutationObserver(function(mutations) { var asinHasProbablyChanged = mutations.some(function(mutation) { return mutation.addedNodes.length > 0; }); if (!asinHasProbablyChanged) return; var newAsin = $('#ASIN').val(); if (snoop.asin == newAsin) return; snoop.run(newAsin, domainData, domain); }); if ($('#buybox_feature_div').get(0)) { observer.observe($('#buybox_feature_div').get(0), { attributes: true, subtree: true, childList: true, characterData: true }); } }, initialize: function(asin, domainData, domain) { this.asin = asin; this._startMonitoringAsin(domainData, domain); //refreshRates(); console.log(BANNER, 'snoop.initialize()'); settings = new Settings(asin, domainData, domain); snoop.tooltip = Mustache.to_html(tooltipTemplate, { shops: settings.filteredShops, from_shop: settings.currentShop.id, from_asin: settings.asin, loader_url: 'https://i.imgur.com/Dp92MjH.gif' }); snoop.run(asin, domainData, domain); }, run: function(asin, domainData, domain) { console.log(BANNER, 'snoop.run()'); this.asin = asin; settings = new Settings(asin, domainData, domain); window.snoop_tooltipInitialized = false; window.snoopML_tooltipInitialized = false; var ensureTooltipHasBeenLoaded = function() { if (snoop.tooltip === null) { setTimeout(ensureTooltipHasBeenLoaded, 50); } else { var tooltipMarkup = snoop.tooltip.replace(/{asin}/gm, settings.asin); page.addTooltipToPage(tooltipMarkup); page.registerInitializationHandler(settings.filteredShops); } }; ensureTooltipHasBeenLoaded(); } }; var meli = { showPrices: function(productName) { console.log(BANNER, 'meli.fetchApiData()'); meli.fetchApiData(productName, meli.showProducts); }, showProducts: function(data) { var meliProducts = $('.snoop-tooltip-ml .tmm_popover'); meliProducts.html('
Buscando por: ' + data.query + '
'); if (data.results.length === 0) { meliProducts.append('
No se encontraron productos en MercadoLibre con esta búsqueda.
'); } data.results.forEach(function(product) { meliProducts.append('
ARS $' + product.price.formatMoney(2) + '
» ' + product.title + '
'); }); }, fetchApiData: function(productName, callback) { jQuery.getJSON( "https://api.mercadolibre.com/sites/MLA/search?q=" + encodeURI(productName) + "&condition=new" ).done(function(data) { callback(data); }); } };