@xbrowser/quanjing 1.0.0

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.
Files changed (2) hide show
  1. package/index.ts +69 -0
  2. package/package.json +20 -0
package/index.ts ADDED
@@ -0,0 +1,69 @@
1
+ import { z } from 'zod';
2
+ import type { XCLIAPI } from '@dyyz1993/xcli-core';
3
+ import { ok, fail } from '@dyyz1993/xcli-core';
4
+
5
+ export default function (xcli: XCLIAPI): void {
6
+ const quanjing = xcli.createSite({
7
+ name: 'quanjing',
8
+ url: 'https://www.quanjing.com',
9
+ description: '全景创意图片搜索',
10
+ requiresLogin: false,
11
+ });
12
+
13
+ quanjing.command('search-image', {
14
+ description: '全景网图片搜索 - 搜索创意素材图片',
15
+ scope: 'browser',
16
+ parameters: z.object({
17
+ query: z.string().describe('搜索关键词'),
18
+ limit: z.number().optional().default(10),
19
+ page: z.any().optional(),
20
+ timeout: z.number().optional().default(20000),
21
+ }),
22
+ result: z.any(),
23
+ handler: async (params, ctx) => {
24
+ const page = (params.page as import('playwright').Page)
25
+ || (ctx as Record<string, unknown>).page as import('playwright').Page;
26
+ if (!page) throw new Error('需要浏览器页面');
27
+
28
+ try {
29
+ const url = `https://www.quanjing.com/search?kw=${encodeURIComponent(params.query)}`;
30
+ await page.goto(url, { waitUntil: 'domcontentloaded', timeout: params.timeout });
31
+ await page.waitForTimeout(3000);
32
+ await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight / 2));
33
+ await page.waitForTimeout(1000);
34
+
35
+ const results = await page.evaluate((limit: number) => {
36
+ const images: Array<{
37
+ title: string; thumbnailUrl: string; sourceUrl: string;
38
+ width: number; height: number;
39
+ }> = [];
40
+
41
+ document.querySelectorAll('img[src*="quanjing"]').forEach((img, idx) => {
42
+ if (idx >= limit) return;
43
+ const el = img as HTMLImageElement;
44
+ if (el.naturalWidth < 80) return;
45
+ images.push({
46
+ title: el.alt || '',
47
+ thumbnailUrl: el.src,
48
+ sourceUrl: el.closest('a')?.getAttribute('href') || '',
49
+ width: el.naturalWidth,
50
+ height: el.naturalHeight,
51
+ });
52
+ });
53
+
54
+ return images;
55
+ }, params.limit);
56
+
57
+ return ok({
58
+ query: params.query,
59
+ engine: 'quanjing',
60
+ results: results.map(r => ({ ...r, sourceSite: 'quanjing' })),
61
+ total: results.length,
62
+ timestamp: Date.now(),
63
+ });
64
+ } catch (error) {
65
+ return fail(error instanceof Error ? error.message : '未知错误');
66
+ }
67
+ },
68
+ });
69
+ }
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@xbrowser/quanjing",
3
+ "version": "1.0.0",
4
+ "description": "全景创意图片搜索",
5
+ "main": "index.ts",
6
+ "keywords": [
7
+ "xbrowser",
8
+ "xbrowser-plugin",
9
+ "quanjing"
10
+ ],
11
+ "author": "dyyz1993",
12
+ "license": "MIT",
13
+ "xbrowser": {
14
+ "site": "https://www.quanjing.com",
15
+ "requiresLogin": false,
16
+ "commands": [
17
+ "search-image"
18
+ ]
19
+ }
20
+ }