更新
This commit is contained in:
parent
302006530e
commit
412198358d
13
CHANGELOG.md
13
CHANGELOG.md
@ -5,6 +5,19 @@
|
||||
|
||||
# CHANGE
|
||||
|
||||
## 0.9.7
|
||||
|
||||
2023年06月05日
|
||||
|
||||
### 添加
|
||||
|
||||
- bazaar快速开关店
|
||||
- 购物助手
|
||||
|
||||
### 修改
|
||||
|
||||
- 部分样式修改
|
||||
|
||||
## 0.9.6
|
||||
|
||||
2023年06月01日
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "wuhu-torn-helper",
|
||||
"version": "0.9.6",
|
||||
"version": "0.9.7",
|
||||
"description": "芜湖助手",
|
||||
"scripts": {
|
||||
"release": "cross-env NODE_ENV=production rollup -c && node build.mjs",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -15,13 +15,39 @@
|
||||
</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<div v-if="itemOnList">
|
||||
<div v-for="item in itemOnList">
|
||||
<div>{{ item.playerName }}[{{ item.playerId }}] ${{ toThousands(item.price) }} x {{ item.amount }}</div>
|
||||
<el-input :model-value="item.amount"/>
|
||||
<el-button @click="buy(item.playerId)">购买</el-button>
|
||||
</div>
|
||||
<div v-if="itemOnList.length > 0">
|
||||
<span :style="{backgroundImage: 'url(/images/items/' + itemName2IdMap[itemName] + '/small.png)'}"
|
||||
style="display:inline-block;width:38px;height:19px;"/>
|
||||
<el-table :data="itemOnList" style="width: 100%" table-layout="auto">
|
||||
<el-table-column label="卖家">
|
||||
<template #default="scope">
|
||||
<!-- <div style="display: flex; align-items: center"-->
|
||||
<!-- v-text="scope.row.playerName + `[${scope.row.playerId}]`"></div>-->
|
||||
<el-link
|
||||
:href="'/bazaar.php?userId=' + scope.row.playerId" :underline="false"
|
||||
target="_blank"
|
||||
type="primary"
|
||||
v-text="scope.row.playerName + `[${scope.row.playerId}]`"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="单价">
|
||||
<template #default="scope">
|
||||
<div style="display: flex; align-items: center" v-text="'$' + toThousands(scope.row.price)"></div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="在售" prop="amount"/>
|
||||
<el-table-column label="批量购买">
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.inputAmount" style="width: 60px;"/>
|
||||
<el-button :loading="scope.row.onBuying"
|
||||
type="primary" @click="buy(itemName, itemName2IdMap[itemName], scope.row)">购买
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
<el-skeleton v-if="listLoading" animated count="5" style="margin-top: 1em"/>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
@ -37,17 +63,30 @@ import { LoggerKey } from "../ts/class/Logger";
|
||||
import { ItemHelperKey } from "../ts/class/utils/ItemHelper";
|
||||
import { itemNameDict } from "../ts/dictionary/translation";
|
||||
import toThousands from "../ts/func/utils/toThousands";
|
||||
import { ElMessage } from "element-plus";
|
||||
|
||||
const logger = inject(LoggerKey);
|
||||
const itemHelper = inject(ItemHelperKey);
|
||||
|
||||
let itemName2IdMap: { [p: string]: number } = null;
|
||||
const itemName = ref('');
|
||||
const itemNameList = ref([]);
|
||||
const html = ref('');
|
||||
const itemOnList = ref<{ playerId: string, playerName: string, price: string, amount: number }[]>([]);
|
||||
const itemName = ref<string>('');
|
||||
const itemNameList = ref<{ value: string, label: string }[]>([]);
|
||||
const html = ref<string>('');
|
||||
type ItemInfo = {
|
||||
playerId: string,
|
||||
playerName: string,
|
||||
price: number,
|
||||
amount: number,
|
||||
inputAmount: number,
|
||||
// index: number,
|
||||
onBuying: boolean,
|
||||
};
|
||||
const itemOnList = ref<ItemInfo[]>([]);
|
||||
const listLoading = ref<boolean>(false);
|
||||
|
||||
const doGetIMarketList = async (id) => {
|
||||
itemOnList.value = [];
|
||||
listLoading.value = true;
|
||||
const queryItemListHtml = await (await fetch(window.addRFC("https://www.torn.com/imarket.php"), {
|
||||
"headers": {
|
||||
"accept": "*/*",
|
||||
@ -65,23 +104,38 @@ const doGetIMarketList = async (id) => {
|
||||
"mode": "cors",
|
||||
"credentials": "include"
|
||||
})).text();
|
||||
itemOnList.value = [];
|
||||
const container = document.createElement('div');
|
||||
listLoading.value = false;
|
||||
|
||||
let container = document.createElement('div');
|
||||
container.innerHTML = queryItemListHtml;
|
||||
const list = container.querySelectorAll('ul.items>li');
|
||||
const list = container.querySelectorAll('ul.items li.private-bazaar');
|
||||
logger.info({ list });
|
||||
list.forEach(li => {
|
||||
let item = { playerId: null, playerName: null, price: null, amount: null };
|
||||
list.forEach((li, index) => {
|
||||
let item = {
|
||||
playerId: null,
|
||||
playerName: null,
|
||||
price: null,
|
||||
amount: null,
|
||||
inputAmount: null,
|
||||
index,
|
||||
onBuying: false
|
||||
};
|
||||
item.playerId = li.querySelector("a.user.name").getAttribute('href').trim().split('XID=')[1];
|
||||
item.playerName = li.querySelector("a.user.name span").innerText.trim();
|
||||
item.price = Number(li.querySelector("span.cost-price").innerText.trim().replace('$', '').replaceAll(',', ''));
|
||||
item.amount = Number(li.querySelector("span.cost-amount").innerText.trim().split(' ')[0].replace('(', ""))
|
||||
item.inputAmount = item.amount;
|
||||
itemOnList.value.push(item);
|
||||
});
|
||||
container = null;
|
||||
};
|
||||
const buy = async (userId) => {
|
||||
const bazaarItemList = await (await fetch(
|
||||
`https://www.torn.com/bazaar.php?sid=bazaarData&step=getBazaarItems&start=0&ID=${ userId }&order=default&by=asc&categorised=0&limit=1000&searchname=`,
|
||||
const buy = async (itemName: string, itemId: number, itemInfo: ItemInfo) => {
|
||||
itemInfo.onBuying = true;
|
||||
try {
|
||||
// 获取玩家id bazaar信息
|
||||
let bazaarId;
|
||||
const bazaarItemList: { list: { bazaarID: string, itemID: string }[] } = await (await fetch(
|
||||
`https://www.torn.com/bazaar.php?sid=bazaarData&step=getBazaarItems&start=0&ID=${ itemInfo.playerId }&order=default&by=asc&categorised=0&limit=1000&searchname=`,
|
||||
{
|
||||
"headers": {
|
||||
"accept": "*/*",
|
||||
@ -91,14 +145,61 @@ const buy = async (userId) => {
|
||||
"sec-fetch-site": "same-origin",
|
||||
"x-requested-with": "XMLHttpRequest"
|
||||
},
|
||||
"referrer": "https://www.torn.com/bazaar.php?userId=" + userId,
|
||||
"referrer": "https://www.torn.com/bazaar.php?userId=" + itemInfo.playerId,
|
||||
"referrerPolicy": "strict-origin-when-cross-origin",
|
||||
"body": null,
|
||||
"method": "GET",
|
||||
"mode": "cors",
|
||||
"credentials": "include"
|
||||
})).json();
|
||||
let bazaarId;
|
||||
for (let i = 0; i < bazaarItemList.list.length; i++) {
|
||||
if (bazaarItemList.list[i].itemID === itemId.toString()) {
|
||||
bazaarId = bazaarItemList.list[i].bazaarID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!bazaarId) {
|
||||
ElMessage.error('上架商品未找到');
|
||||
logger.error('物品id未找到对应bazaar项目', bazaarItemList, itemId);
|
||||
(() => {
|
||||
throw new Error('bazaarId为空')
|
||||
})();
|
||||
}
|
||||
|
||||
// 从baz买货
|
||||
let buyResponse = await (await fetch("https://www.torn.com/bazaar.php?sid=bazaarData&step=buyItem", {
|
||||
"headers": {
|
||||
"accept": "*/*",
|
||||
"sec-ch-ua-mobile": "?0",
|
||||
"sec-fetch-dest": "empty",
|
||||
"sec-fetch-mode": "cors",
|
||||
"sec-fetch-site": "same-origin",
|
||||
"x-requested-with": "XMLHttpRequest"
|
||||
},
|
||||
"referrer": "https://www.torn.com/bazaar.php?userId=" + itemInfo.playerId,
|
||||
"referrerPolicy": "strict-origin-when-cross-origin",
|
||||
"body": (() => {
|
||||
const data = new FormData();
|
||||
data.append('userID', itemInfo.playerId);
|
||||
data.append('id', bazaarId);
|
||||
data.append('itemID', itemId.toString());
|
||||
data.append('amount', itemInfo.inputAmount.toString());
|
||||
data.append('price', itemInfo.price.toString());
|
||||
data.append('beforeval', (itemInfo.price * itemInfo.inputAmount).toString());
|
||||
return data;
|
||||
})(),
|
||||
"method": "POST",
|
||||
"mode": "cors",
|
||||
"credentials": "include"
|
||||
})).json();
|
||||
if (!buyResponse.success) {
|
||||
ElMessage.error('购买失败 ' + buyResponse.text);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error(e.stack);
|
||||
ElMessage.error('出错了 ' + e.message);
|
||||
}
|
||||
itemInfo.onBuying = false;
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user