Skip to content

Commit

Permalink
Improve message
Browse files Browse the repository at this point in the history
  • Loading branch information
lndgalante committed Dec 16, 2019
1 parent a54fad8 commit 7804c3a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.16.0
2 changes: 1 addition & 1 deletion dist/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "MercadoLibre Más Vendidos",
"author": "Leonardo Galante",
"short_name": "Más Vendidos",
"version": "1.1.1",
"version": "1.1.2",
"description": "Busca los artículos más vendidos en MercadoLibre con esta extensión",
"homepage_url": "https://mercadolibre-masvendidos.now.sh",
"icons": {
Expand Down
2 changes: 1 addition & 1 deletion dist/src/content-script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mercadolibre-mas-vendidos",
"version": "1.1.0",
"version": "1.1.2",
"description": "Busca los artículos más vendidos en MercadoLibre con esta extensión",
"repository": "fenwil/mercadolibre-masvendidos",
"homepage": "https://mercadolibre-masvendidos.now.sh",
Expand Down
13 changes: 8 additions & 5 deletions src/content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ function sortItems() {
// Declare ids and class selectors
const listSelector = '#searchResults'
const itemSelector = '.results-item'
const soldQuantitySelector = '.item__condition'
const soldQuantitySelector = '.stack_column_item.status'

// Get all elements IDs
const rowItems = [...document.querySelectorAll(itemSelector)]
const ids = rowItems.map(rowItem => getItemId(rowItem)).filter(id => !id || id !== 'MLA')
console.log('TCL: sortItems -> ids', ids)

// Create chunks every 20 items, since ML API can only receive until 20 ids
const idChunks = chunk(ids, 20)
Expand All @@ -39,7 +38,6 @@ function sortItems() {
fetch(`https://api.mercadolibre.com/items?ids=${idChunk.join(',')}&attributes=id,sold_quantity`)
.then(res => res.json())
.then(data => {
console.log('TCL: sortItems -> data', data)
return data.map(item => ({
id: item.body.hasOwnProperty('id') ? item.body.id : 0,
soldQuantity: item.body.hasOwnProperty('sold_quantity') ? item.body.sold_quantity : 0,
Expand All @@ -55,9 +53,14 @@ function sortItems() {
rowItems.forEach(rowItem => {
const id = getItemId(rowItem)
const item = flattenData.find(({ id: itemId }) => itemId === id) || { soldQuantity: 0 }

const $soldQuantity = rowItem.querySelector(soldQuantitySelector)
$soldQuantity.textContent = `+${item.soldQuantity} vendidos - ${$soldQuantity.textContent}`

console.log('TCL: sortItems -> $soldQuantity.textContent', $soldQuantity.textContent)
console.log($soldQuantity.textContent)
const hasTextContent = Boolean($soldQuantity.textContent.trim(''))
$soldQuantity.textContent = `${item.soldQuantity > 0 ? '+' : ''}${item.soldQuantity} vendidos${
hasTextContent ? ' - ' : ''
}${$soldQuantity.textContent}`
})

// Sort all the quantity of sold products descendly
Expand Down

0 comments on commit 7804c3a

Please sign in to comment.