koishi-plugin-steaminfo-xiaoheihe 0.1.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +45 -12
- package/package.json +1 -1
package/lib/index.js
CHANGED
@@ -86,21 +86,54 @@ function apply(ctx, config) {
|
|
86
86
|
const searchUrl = `https://www.xiaoheihe.cn/app/search?q=${encodeURIComponent(game)}`;
|
87
87
|
log(`准备导航到搜索页面: ${searchUrl}`);
|
88
88
|
await page.goto(searchUrl, { waitUntil: "load", timeout: config.waitTimeout });
|
89
|
-
|
90
|
-
let
|
89
|
+
let finalUrl;
|
90
|
+
let navigationCompleted = false;
|
91
|
+
const listGameSelector = 'a[href*="/app/topic/game/"]';
|
92
|
+
log(`[Plan A] 尝试寻找列表页的游戏链接: "${listGameSelector}"`);
|
91
93
|
try {
|
92
|
-
|
93
|
-
await page
|
94
|
-
|
94
|
+
await page.waitForSelector(listGameSelector, { timeout: 5e3 });
|
95
|
+
const gamePageHref = await page.$eval(listGameSelector, (el) => el.getAttribute("href"));
|
96
|
+
finalUrl = `https://www.xiaoheihe.cn${gamePageHref}`;
|
97
|
+
log(`[Plan A] 成功!获取到链接: ${finalUrl}`);
|
95
98
|
} catch (e) {
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
99
|
+
log(`[Plan A] 失败。切换到 Plan B...`);
|
100
|
+
try {
|
101
|
+
const communityLinkSelector = ".search-topic__topic-name";
|
102
|
+
log(`[Plan B] 尝试寻找社区链接: "${communityLinkSelector}"`);
|
103
|
+
await page.waitForSelector(communityLinkSelector, { timeout: 5e3 });
|
104
|
+
await Promise.all([
|
105
|
+
page.waitForNavigation({ waitUntil: "load", timeout: config.waitTimeout }),
|
106
|
+
page.click(communityLinkSelector)
|
107
|
+
]);
|
108
|
+
const gameTabSelector = ".slide-tab__tab-label";
|
109
|
+
await page.waitForSelector(gameTabSelector, { timeout: 1e4 });
|
110
|
+
await Promise.all([
|
111
|
+
page.waitForNavigation({ waitUntil: "load", timeout: config.waitTimeout }),
|
112
|
+
page.click(gameTabSelector)
|
113
|
+
]);
|
114
|
+
navigationCompleted = true;
|
115
|
+
log(`[Plan B] 成功到达最终游戏页面: ${page.url()}`);
|
116
|
+
} catch (e2) {
|
117
|
+
log(`[Plan B] 失败。切换到 Plan C...`);
|
118
|
+
try {
|
119
|
+
const singleGameCardSelector = ".search-result__game .game-rank__game-card";
|
120
|
+
log(`[Plan C] 尝试寻找并点击独立游戏卡片: "${singleGameCardSelector}"`);
|
121
|
+
await page.waitForSelector(singleGameCardSelector, { timeout: 5e3 });
|
122
|
+
await page.click(singleGameCardSelector);
|
123
|
+
navigationCompleted = true;
|
124
|
+
log(`[Plan C] 点击成功!页面将原地跳转。`);
|
125
|
+
} catch (e3) {
|
126
|
+
if (config.debug) logger.warn("在搜索页未能找到游戏链接,所有方案均失败。");
|
127
|
+
const screenshot = await page.screenshot({ fullPage: true });
|
128
|
+
await session.send(["未能找到游戏专题链接。这是当前页面的截图:", import_koishi.segment.image(screenshot)]);
|
129
|
+
return;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
}
|
133
|
+
if (!navigationCompleted) {
|
134
|
+
log(`正在导航到: ${finalUrl}`);
|
135
|
+
await page.goto(finalUrl, { waitUntil: "load", timeout: config.waitTimeout });
|
100
136
|
}
|
101
|
-
const finalUrl = `https://www.xiaoheihe.cn${gamePageHref}`;
|
102
|
-
log(`已获取详情页链接,正在导航到: ${finalUrl}`);
|
103
|
-
await page.goto(finalUrl, { waitUntil: "load", timeout: config.waitTimeout });
|
104
137
|
const mainContentSelector = ".game-detail-page-detail";
|
105
138
|
log(`等待核心内容 "${mainContentSelector}" 出现...`);
|
106
139
|
await page.waitForSelector(mainContentSelector, { timeout: config.waitTimeout });
|