steamutils 1.2.86 → 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 +23 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -5490,8 +5490,7 @@ class SteamUser {
5490
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,11 +5583,10 @@ 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)
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)) {
5592
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')
@@ -5602,14 +5600,14 @@ class SteamUser {
5602
5600
  instanceid,
5603
5601
  contextid,
5604
5602
  steamId,
5605
- plusminus: items_plusminus,
5603
+ plusminus,
5606
5604
  ...(descriptions[appID]?.[classid + '_' + instanceid])
5607
5605
  })
5608
5606
  }
5609
- })
5610
- })
5607
+ }
5608
+ }
5611
5609
 
5612
- if(tradehistory_items.length){
5610
+ if (tradehistory_items.length) {
5613
5611
  const id = [timestamp, description, plusminus, tradehistory_items.map(item => (item.classid || '0') + "_" + (item.instanceid || '0')).join('|')]
5614
5612
  .map(item => item.toString().replaceAll(/[^a-zA-Z0-9-+_|]/gi, ''))
5615
5613
  .join('_').toLowerCase()
@@ -5628,7 +5626,7 @@ class SteamUser {
5628
5626
  fs.writeFileSync('tradehistory_items_empty_' + steamId + "_" + new Date().getTime(), html)
5629
5627
  console.error("tradehistory_items empty", steamId);
5630
5628
  }
5631
- })
5629
+ }
5632
5630
 
5633
5631
  return {cursor: result.cursor, tradehistory}
5634
5632
  const exampleTradeHistory = [
@@ -6100,4 +6098,17 @@ function plainText(text) {
6100
6098
  return text?.replaceAll(/[\t\n\r]/gi, ' ')?.replaceAll(/\s+/g, ' ')?.trim()
6101
6099
  }
6102
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
+
6103
6114
  export default SteamUser
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.2.86",
3
+ "version": "1.2.87",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "axios": "^1.5.1",