browser-web-search 0.2.2 → 0.3.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.
@@ -1,90 +0,0 @@
1
- /* @meta
2
- {
3
- "name": "douban/search",
4
- "description": "Search Douban across movies, books, and music",
5
- "domain": "www.douban.com",
6
- "args": {
7
- "keyword": {"required": true, "description": "Search keyword (Chinese or English)"}
8
- },
9
- "capabilities": ["network"],
10
- "readOnly": true,
11
- "example": "ping-browser site douban/search 三体"
12
- }
13
- */
14
-
15
- async function(args) {
16
- if (!args.keyword) return {error: 'Missing argument: keyword'};
17
- const q = encodeURIComponent(args.keyword);
18
-
19
- // Try the rich search_suggest endpoint (requires www.douban.com origin)
20
- var resp;
21
- var usedFallback = false;
22
- try {
23
- resp = await fetch('https://www.douban.com/j/search_suggest?q=' + q, {credentials: 'include'});
24
- if (!resp.ok) throw new Error('HTTP ' + resp.status);
25
- } catch (e) {
26
- // Fallback: use movie.douban.com subject_suggest (works cross-subdomain via same eTLD+1 cookies)
27
- try {
28
- resp = await fetch('/j/subject_suggest?q=' + q, {credentials: 'include'});
29
- usedFallback = true;
30
- } catch (e2) {
31
- return {error: 'Search failed: ' + e2.message, hint: 'Not logged in? Navigate to www.douban.com first.'};
32
- }
33
- }
34
-
35
- if (!resp.ok) return {error: 'HTTP ' + resp.status, hint: 'Not logged in?'};
36
- var d = await resp.json();
37
-
38
- if (usedFallback) {
39
- // subject_suggest returns an array directly
40
- var items = (Array.isArray(d) ? d : []).map(function(c, i) {
41
- return {
42
- rank: i + 1,
43
- id: c.id,
44
- type: c.type === 'movie' ? 'movie' : c.type === 'b' ? 'book' : c.type || 'unknown',
45
- title: c.title,
46
- subtitle: c.sub_title || '',
47
- rating: null,
48
- info: '',
49
- year: c.year || null,
50
- cover: c.img || c.pic || null,
51
- url: c.url
52
- };
53
- });
54
- return {
55
- keyword: args.keyword,
56
- count: items.length,
57
- results: items,
58
- suggestions: [],
59
- note: 'Limited results (movie/book only). For richer results, navigate to www.douban.com first.'
60
- };
61
- }
62
-
63
- // Rich search_suggest response with cards
64
- var cards = (d.cards || []).map(function(c, i) {
65
- var id = c.url && c.url.match(/subject\/(\d+)/);
66
- id = id ? id[1] : null;
67
- var ratingMatch = c.card_subtitle && c.card_subtitle.match(/([\d.]+)分/);
68
- return {
69
- rank: i + 1,
70
- id: id,
71
- type: c.type || 'unknown',
72
- title: c.title,
73
- subtitle: c.abstract || '',
74
- rating: ratingMatch ? parseFloat(ratingMatch[1]) : null,
75
- info: c.card_subtitle || '',
76
- year: c.year || null,
77
- cover: c.cover_url || null,
78
- url: c.url
79
- };
80
- });
81
-
82
- var suggestions = d.words || [];
83
-
84
- return {
85
- keyword: args.keyword,
86
- count: cards.length,
87
- results: cards,
88
- suggestions: suggestions
89
- };
90
- }
@@ -1,73 +0,0 @@
1
- /* @meta
2
- {
3
- "name": "douban/top250",
4
- "description": "Get Douban Top 250 movies list",
5
- "domain": "movie.douban.com",
6
- "args": {
7
- "start": {"required": false, "description": "Start position (default: 0, step by 25). Use 0 for #1-25, 25 for #26-50, etc."}
8
- },
9
- "capabilities": ["network"],
10
- "readOnly": true,
11
- "example": "ping-browser site douban/top250"
12
- }
13
- */
14
-
15
- async function(args) {
16
- const start = parseInt(args.start) || 0;
17
-
18
- const resp = await fetch('https://movie.douban.com/top250?start=' + start, {credentials: 'include'});
19
- if (!resp.ok) return {error: 'HTTP ' + resp.status, hint: 'Not logged in?'};
20
- const html = await resp.text();
21
- const doc = new DOMParser().parseFromString(html, 'text/html');
22
-
23
- const items = [];
24
- doc.querySelectorAll('.grid_view .item').forEach(function(el) {
25
- var rank = el.querySelector('.pic em');
26
- var titleEl = el.querySelector('.hd a .title');
27
- var otherTitleEl = el.querySelector('.hd a .other');
28
- var ratingEl = el.querySelector('.rating_num');
29
- var link = el.querySelector('.hd a');
30
- var quoteEl = el.querySelector('.quote .inq') || el.querySelector('.quote span');
31
- var infoEl = el.querySelector('.bd p');
32
-
33
- // Vote count is in a span like "3268455人评价"
34
- var voteSpans = el.querySelectorAll('.bd div span');
35
- var votes = null;
36
- voteSpans.forEach(function(sp) {
37
- var m = sp.textContent.match(/(\d+)人评价/);
38
- if (m) votes = parseInt(m[1]);
39
- });
40
-
41
- var id = link?.href?.match(/subject\/(\d+)/)?.[1];
42
-
43
- // Parse info line for director, year, region, genre
44
- var infoText = infoEl ? infoEl.textContent.trim() : '';
45
- var lines = infoText.split('\n').map(function(l) { return l.trim(); }).filter(Boolean);
46
- var directorLine = lines[0] || '';
47
- var metaLine = lines[1] || '';
48
- var metaParts = metaLine.split('/').map(function(p) { return p.trim(); });
49
-
50
- items.push({
51
- rank: rank ? parseInt(rank.textContent) : null,
52
- id: id,
53
- title: titleEl ? titleEl.textContent.trim() : '',
54
- other_title: otherTitleEl ? otherTitleEl.textContent.trim().replace(/^\s*\/\s*/, '') : '',
55
- rating: ratingEl ? parseFloat(ratingEl.textContent) : null,
56
- votes: votes,
57
- quote: quoteEl ? quoteEl.textContent.trim() : '',
58
- year: metaParts[0] || '',
59
- region: metaParts[1] || '',
60
- genre: metaParts[2] || '',
61
- url: link ? link.href : ''
62
- });
63
- });
64
-
65
- return {
66
- start: start,
67
- count: items.length,
68
- total: 250,
69
- has_more: start + items.length < 250,
70
- next_start: start + items.length < 250 ? start + 25 : null,
71
- items: items
72
- };
73
- }
@@ -1,38 +0,0 @@
1
- /* @meta
2
- {
3
- "name": "github/fork",
4
- "description": "Fork a GitHub repository",
5
- "domain": "github.com",
6
- "args": {
7
- "repo": {"required": true, "description": "Repository to fork (owner/repo)"}
8
- },
9
- "capabilities": ["network"],
10
- "readOnly": false,
11
- "example": "ping-browser site github/fork epiral/bb-sites"
12
- }
13
- */
14
-
15
- async function(args) {
16
- if (!args.repo) return {error: 'Missing argument: repo'};
17
-
18
- const resp = await fetch('https://api.github.com/repos/' + args.repo + '/forks', {
19
- method: 'POST',
20
- credentials: 'include',
21
- headers: {'Content-Type': 'application/json'},
22
- body: JSON.stringify({})
23
- });
24
-
25
- if (!resp.ok) {
26
- const status = resp.status;
27
- if (status === 401 || status === 403) return {error: 'HTTP ' + status, hint: 'Not logged in to GitHub'};
28
- if (status === 404) return {error: 'Repo not found: ' + args.repo};
29
- return {error: 'HTTP ' + status};
30
- }
31
-
32
- const fork = await resp.json();
33
- return {
34
- full_name: fork.full_name,
35
- url: fork.html_url,
36
- clone_url: fork.clone_url
37
- };
38
- }
@@ -1,42 +0,0 @@
1
- /* @meta
2
- {
3
- "name": "github/issue-create",
4
- "description": "Create a GitHub issue",
5
- "domain": "github.com",
6
- "args": {
7
- "repo": {"required": true, "description": "owner/repo format"},
8
- "title": {"required": true, "description": "Issue title"},
9
- "body": {"required": false, "description": "Issue body (markdown)"}
10
- },
11
- "capabilities": ["network"],
12
- "readOnly": false,
13
- "example": "ping-browser site github/issue-create epiral/bb-sites --title \"[reddit/me] returns empty\" --body \"Description here\""
14
- }
15
- */
16
-
17
- async function(args) {
18
- if (!args.repo) return {error: 'Missing argument: repo'};
19
- if (!args.title) return {error: 'Missing argument: title'};
20
-
21
- const resp = await fetch('https://api.github.com/repos/' + args.repo + '/issues', {
22
- method: 'POST',
23
- credentials: 'include',
24
- headers: {'Content-Type': 'application/json'},
25
- body: JSON.stringify({title: args.title, body: args.body || ''})
26
- });
27
-
28
- if (!resp.ok) {
29
- const status = resp.status;
30
- if (status === 401 || status === 403) return {error: 'HTTP ' + status, hint: 'Not logged in to GitHub'};
31
- if (status === 404) return {error: 'Repo not found: ' + args.repo};
32
- return {error: 'HTTP ' + status};
33
- }
34
-
35
- const issue = await resp.json();
36
- return {
37
- number: issue.number,
38
- title: issue.title,
39
- url: issue.html_url,
40
- state: issue.state
41
- };
42
- }
@@ -1,32 +0,0 @@
1
- /* @meta
2
- {
3
- "name": "github/issues",
4
- "description": "获取 GitHub 仓库的 issue 列表",
5
- "domain": "github.com",
6
- "args": {
7
- "repo": {"required": true, "description": "owner/repo format"},
8
- "state": {"required": false, "description": "open, closed, or all (default: open)"}
9
- },
10
- "capabilities": ["network"],
11
- "readOnly": true,
12
- "example": "ping-browser site github/issues epiral/ping-browser"
13
- }
14
- */
15
-
16
- async function(args) {
17
- if (!args.repo) return {error: 'Missing argument: repo'};
18
- const state = args.state || 'open';
19
- const resp = await fetch('https://api.github.com/repos/' + args.repo + '/issues?state=' + state + '&per_page=30', {credentials: 'include'});
20
- if (!resp.ok) return {error: 'HTTP ' + resp.status};
21
- const issues = await resp.json();
22
- return {
23
- repo: args.repo, state, count: issues.length,
24
- issues: issues.map(i => ({
25
- number: i.number, title: i.title, state: i.state,
26
- url: i.html_url,
27
- author: i.user?.login, labels: i.labels?.map(l => l.name),
28
- comments: i.comments, created_at: i.created_at,
29
- is_pr: !!i.pull_request
30
- }))
31
- };
32
- }
@@ -1,22 +0,0 @@
1
- /* @meta
2
- {
3
- "name": "github/me",
4
- "description": "获取当前 GitHub 登录用户信息",
5
- "domain": "github.com",
6
- "args": {},
7
- "capabilities": ["network"],
8
- "readOnly": true
9
- }
10
- */
11
-
12
- async function(args) {
13
- const resp = await fetch('https://api.github.com/user', {credentials: 'include'});
14
- if (!resp.ok) return {error: 'HTTP ' + resp.status, hint: resp.status === 401 ? 'Not logged into github.com' : 'API error'};
15
- const d = await resp.json();
16
- return {
17
- login: d.login, name: d.name, bio: d.bio,
18
- url: d.html_url || ('https://github.com/' + d.login),
19
- public_repos: d.public_repos, followers: d.followers, following: d.following,
20
- created_at: d.created_at
21
- };
22
- }
@@ -1,55 +0,0 @@
1
- /* @meta
2
- {
3
- "name": "github/pr-create",
4
- "description": "Create a GitHub pull request",
5
- "domain": "github.com",
6
- "args": {
7
- "repo": {"required": true, "description": "Target repo (owner/repo)"},
8
- "title": {"required": true, "description": "PR title"},
9
- "head": {"required": true, "description": "Source branch (user:branch or branch)"},
10
- "base": {"required": false, "description": "Target branch (default: main)"},
11
- "body": {"required": false, "description": "PR description (markdown)"}
12
- },
13
- "capabilities": ["network"],
14
- "readOnly": false,
15
- "example": "ping-browser site github/pr-create epiral/bb-sites --title \"feat(weibo): add hot adapter\" --head myuser:feat-weibo --body \"Adds weibo/hot.js\""
16
- }
17
- */
18
-
19
- async function(args) {
20
- if (!args.repo) return {error: 'Missing argument: repo'};
21
- if (!args.title) return {error: 'Missing argument: title'};
22
- if (!args.head) return {error: 'Missing argument: head', hint: 'Provide source branch as "user:branch" or "branch"'};
23
-
24
- const resp = await fetch('https://api.github.com/repos/' + args.repo + '/pulls', {
25
- method: 'POST',
26
- credentials: 'include',
27
- headers: {'Content-Type': 'application/json'},
28
- body: JSON.stringify({
29
- title: args.title,
30
- head: args.head,
31
- base: args.base || 'main',
32
- body: args.body || ''
33
- })
34
- });
35
-
36
- if (!resp.ok) {
37
- const status = resp.status;
38
- if (status === 401 || status === 403) return {error: 'HTTP ' + status, hint: 'Not logged in to GitHub'};
39
- if (status === 404) return {error: 'Repo not found: ' + args.repo};
40
- if (status === 422) {
41
- const d = await resp.json().catch(() => null);
42
- const msg = d?.errors?.[0]?.message || d?.message || 'Validation failed';
43
- return {error: msg, hint: 'Check that the head branch exists and has commits ahead of base'};
44
- }
45
- return {error: 'HTTP ' + status};
46
- }
47
-
48
- const pr = await resp.json();
49
- return {
50
- number: pr.number,
51
- title: pr.title,
52
- url: pr.html_url,
53
- state: pr.state
54
- };
55
- }
@@ -1,27 +0,0 @@
1
- /* @meta
2
- {
3
- "name": "github/repo",
4
- "description": "获取 GitHub 仓库信息",
5
- "domain": "github.com",
6
- "args": {
7
- "repo": {"required": true, "description": "owner/repo format (e.g. epiral/ping-browser)"}
8
- },
9
- "capabilities": ["network"],
10
- "readOnly": true,
11
- "example": "ping-browser site github/repo epiral/ping-browser"
12
- }
13
- */
14
-
15
- async function(args) {
16
- if (!args.repo) return {error: 'Missing argument: repo', hint: 'Use owner/repo format'};
17
- const resp = await fetch('https://api.github.com/repos/' + args.repo, {credentials: 'include'});
18
- if (!resp.ok) return {error: 'HTTP ' + resp.status, hint: resp.status === 404 ? 'Repo not found: ' + args.repo : 'API error'};
19
- const d = await resp.json();
20
- return {
21
- full_name: d.full_name, description: d.description, language: d.language,
22
- url: d.html_url || ('https://github.com/' + d.full_name),
23
- stars: d.stargazers_count, forks: d.forks_count, open_issues: d.open_issues_count,
24
- created_at: d.created_at, updated_at: d.updated_at, default_branch: d.default_branch,
25
- topics: d.topics, license: d.license?.spdx_id
26
- };
27
- }