steamutils 1.2.85 → 1.2.87

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +39 -31
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -5486,12 +5486,11 @@ class SteamUser {
5486
5486
  if (!result) return
5487
5487
 
5488
5488
  const descriptions = result.descriptions
5489
- const $ = cheerio.load(result.html?.replaceAll(/[\t\n\r]/gi, '')
5490
- ?.trim() || '')
5489
+ const html = result.html?.replaceAll(/[\t\n\r]/gi, '')?.trim() || ''
5490
+ const $ = cheerio.load(html)
5491
5491
 
5492
5492
  const tradehistory = []
5493
- $('.tradehistoryrow').each(function () {
5494
- const tradehistoryrow_el = $(this)
5493
+ for (const tradehistoryrow_el of querySelectorAll($, '.tradehistoryrow')) {
5495
5494
  const tradehistory_date_el = tradehistoryrow_el.find('.tradehistory_date')
5496
5495
  const tradehistory_timestamp_el = tradehistory_date_el.find('.tradehistory_timestamp')
5497
5496
 
@@ -5584,40 +5583,31 @@ class SteamUser {
5584
5583
 
5585
5584
  const plusminus = tradehistoryrow_el.find('.tradehistory_items_plusminus').text().trim()//+ -
5586
5585
  const tradehistory_items = []
5587
- tradehistoryrow_el.find('.tradehistory_items').each(function () {
5588
- const tradehistory_items_el = $(this)
5589
- const items_plusminus = tradehistory_items_el.find('.tradehistory_items_plusminus').text().trim()
5590
- tradehistory_items_el.find('.tradehistory_items_group > .history_item').each(function () {
5591
- const itemEl = $(this)
5592
- const text = itemEl.text().trim()//You did not receive any items in this trade.
5586
+
5587
+ for (const tradehistory_items_el of querySelectorAll($, '.tradehistory_items', tradehistoryrow_el)) {
5588
+ const plusminus = tradehistory_items_el.find('.tradehistory_items_plusminus').text().trim()
5589
+ for (const itemEl of querySelectorAll($, '.tradehistory_items_group > .history_item', tradehistory_items_el)) {
5590
+ const text = plainText(itemEl.text())//You did not receive any items in this trade.
5593
5591
  const appID = itemEl.attr('data-appid')
5594
5592
  const classid = itemEl.attr('data-classid')
5595
5593
  const instanceid = itemEl.attr('data-instanceid')
5596
5594
  const contextid = itemEl.attr('data-contextid')
5597
5595
 
5598
5596
  if (text !== `You did not receive any items in this trade.`) {
5599
- if (descriptions[appID]) {
5600
- const item = descriptions[appID][classid + '_' + instanceid]
5601
- if (item) {
5602
- tradehistory_items.push({...item, plusminus: items_plusminus})
5603
- } else {
5604
- tradehistory_items.push({
5605
- appID,
5606
- classid,
5607
- instanceid,
5608
- contextid,
5609
- steamId,
5610
- plusminus: items_plusminus
5611
- })
5612
- }
5613
- } else {
5614
- // console.log("No app descriptions", appID);
5615
- }
5597
+ tradehistory_items.push({
5598
+ appID,
5599
+ classid,
5600
+ instanceid,
5601
+ contextid,
5602
+ steamId,
5603
+ plusminus,
5604
+ ...(descriptions[appID]?.[classid + '_' + instanceid])
5605
+ })
5616
5606
  }
5617
- })
5618
- })
5607
+ }
5608
+ }
5619
5609
 
5620
- if(tradehistory_items.length){
5610
+ if (tradehistory_items.length) {
5621
5611
  const id = [timestamp, description, plusminus, tradehistory_items.map(item => (item.classid || '0') + "_" + (item.instanceid || '0')).join('|')]
5622
5612
  .map(item => item.toString().replaceAll(/[^a-zA-Z0-9-+_|]/gi, ''))
5623
5613
  .join('_').toLowerCase()
@@ -5633,9 +5623,10 @@ class SteamUser {
5633
5623
  ...(!!tradePeople && {tradePeople})
5634
5624
  })
5635
5625
  } else {
5626
+ fs.writeFileSync('tradehistory_items_empty_' + steamId + "_" + new Date().getTime(), html)
5636
5627
  console.error("tradehistory_items empty", steamId);
5637
5628
  }
5638
- })
5629
+ }
5639
5630
 
5640
5631
  return {cursor: result.cursor, tradehistory}
5641
5632
  const exampleTradeHistory = [
@@ -6103,4 +6094,21 @@ class SteamUser {
6103
6094
  }
6104
6095
  }
6105
6096
 
6097
+ function plainText(text) {
6098
+ return text?.replaceAll(/[\t\n\r]/gi, ' ')?.replaceAll(/\s+/g, ' ')?.trim()
6099
+ }
6100
+
6101
+ function querySelectorAll($, selector, root) {
6102
+ try {
6103
+ if (root) {
6104
+ return [...root.find(selector)].map(el => $(el))
6105
+ } else {
6106
+ return [...$(selector)].map(el => $(el))
6107
+ }
6108
+ } catch (e) {
6109
+ console.error(e);
6110
+ return []
6111
+ }
6112
+ }
6113
+
6106
6114
  export default SteamUser
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.2.85",
3
+ "version": "1.2.87",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "axios": "^1.5.1",