Skip to content

Commit d0ef1f1

Browse files
committed
feat: 增加延迟,避免限流
1 parent 001bcd4 commit d0ef1f1

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

.changeset/nasty-dolls-add.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'steam-multisell': patch
3+
---
4+
5+
feat: 增加延迟,避免限流

packages/steam-multisell/src/market/listings.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,18 @@ function createMultiCancelButton() {
3737
const sessionid = window.g_sessionID
3838

3939
const cancel = async (id: string) => {
40-
const res = await fetch(
41-
`https://steamcommunity.com/market/removelisting/${id}`,
42-
{ body: new URLSearchParams({ sessionid }), method: 'POST' }
43-
)
44-
await sleep(200)
40+
await fetch(`https://steamcommunity.com/market/removelisting/${id}`, {
41+
body: new URLSearchParams({ sessionid }),
42+
method: 'POST',
43+
})
44+
45+
document.getElementById(`mylisting_${id}`)?.remove()
46+
47+
const countEl = document.getElementById('my_market_selllistings_number')
48+
if (countEl) {
49+
const count = parseInt(countEl.textContent || '0', 10) - 1
50+
countEl.textContent = count.toString()
51+
}
4552
}
4653

4754
document
@@ -82,8 +89,16 @@ function createMultiCancelButton() {
8289
)
8390
})
8491

92+
let lock = false
8593
button.addEventListener('click', async () => {
86-
await Promise.all(ids.map(cancel))
94+
if (lock) return
95+
lock = true
96+
97+
for (let i = 0, size = 3; i < ids.length; i += size) {
98+
const chunk = ids.slice(i, i + size)
99+
await Promise.all(chunk.map(cancel))
100+
await sleep(200)
101+
}
87102
window.location.reload()
88103
})
89104

0 commit comments

Comments
 (0)