dsh-browserpaw 5.0.0 → 5.0.1

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.
@@ -10,7 +10,7 @@
10
10
  ]
11
11
  },
12
12
  "domains": ["developer.mozilla.org"],
13
- "keywords": ["mdn", "documentation", "web api", "search"],
13
+ "keywords": ["mdn", "documentation", "web api", "search", "MDN搜索", "前端文档", "Web文档"],
14
14
  "startUrl": "https://developer.mozilla.org/en-US/search?q={{query}}",
15
15
  "inputSchema": {
16
16
  "type": "object",
@@ -31,69 +31,114 @@
31
31
  "additionalProperties": false
32
32
  },
33
33
  "outputSchema": {
34
- "type": "object",
35
- "properties": {
36
- "success": {
37
- "const": true
38
- },
39
- "status": {
40
- "const": "ok"
41
- },
42
- "query": {
43
- "type": "string",
44
- "minLength": 1
45
- },
46
- "documents": {
47
- "type": "array",
48
- "minItems": 1,
49
- "maxItems": 10,
50
- "items": {
51
- "type": "object",
52
- "properties": {
53
- "title": {
54
- "type": "string",
55
- "minLength": 1
56
- },
57
- "url": {
58
- "type": "string",
59
- "pattern": "^https://developer\\.mozilla\\.org/[a-z]{2}(?:-[A-Z]{2})?/docs/"
60
- },
61
- "summary": {
62
- "type": "string"
34
+ "oneOf": [
35
+ {
36
+ "type": "object",
37
+ "properties": {
38
+ "success": {
39
+ "const": true
40
+ },
41
+ "status": {
42
+ "const": "ok"
43
+ },
44
+ "query": {
45
+ "type": "string",
46
+ "minLength": 1
47
+ },
48
+ "documents": {
49
+ "type": "array",
50
+ "minItems": 1,
51
+ "maxItems": 10,
52
+ "items": {
53
+ "type": "object",
54
+ "properties": {
55
+ "title": {
56
+ "type": "string",
57
+ "minLength": 1
58
+ },
59
+ "url": {
60
+ "type": "string",
61
+ "pattern": "^https://developer\\.mozilla\\.org/[a-z]{2}(?:-[A-Z]{2})?/docs/"
62
+ },
63
+ "summary": {
64
+ "type": "string"
65
+ }
66
+ },
67
+ "required": ["title", "url", "summary"],
68
+ "additionalProperties": false
63
69
  }
64
70
  },
65
- "required": ["title", "url", "summary"],
66
- "additionalProperties": false
67
- }
71
+ "sources": {
72
+ "type": "object",
73
+ "properties": {
74
+ "api": {
75
+ "type": "string",
76
+ "pattern": "^https://developer\\.mozilla\\.org/api/v1/search"
77
+ },
78
+ "page": {
79
+ "type": "string",
80
+ "pattern": "^https://developer\\.mozilla\\.org/"
81
+ }
82
+ },
83
+ "required": ["api", "page"],
84
+ "additionalProperties": false
85
+ },
86
+ "total": {
87
+ "type": "integer",
88
+ "minimum": 0
89
+ }
90
+ },
91
+ "required": ["success", "status", "query", "documents", "sources", "total"],
92
+ "additionalProperties": false
68
93
  },
69
- "sources": {
94
+ {
70
95
  "type": "object",
71
96
  "properties": {
72
- "api": {
73
- "type": "string",
74
- "pattern": "^https://developer\\.mozilla\\.org/api/v1/search"
97
+ "success": {
98
+ "const": true
99
+ },
100
+ "status": {
101
+ "const": "empty"
75
102
  },
76
- "page": {
103
+ "query": {
77
104
  "type": "string",
78
- "pattern": "^https://developer\\.mozilla\\.org/"
105
+ "minLength": 1
106
+ },
107
+ "documents": {
108
+ "type": "array",
109
+ "minItems": 0,
110
+ "maxItems": 0
111
+ },
112
+ "sources": {
113
+ "type": "object",
114
+ "properties": {
115
+ "api": {
116
+ "type": "string",
117
+ "pattern": "^https://developer\\.mozilla\\.org/api/v1/search"
118
+ },
119
+ "page": {
120
+ "type": "string",
121
+ "pattern": "^https://developer\\.mozilla\\.org/"
122
+ }
123
+ },
124
+ "required": ["api", "page"],
125
+ "additionalProperties": false
126
+ },
127
+ "total": {
128
+ "type": "integer",
129
+ "minimum": 0
79
130
  }
80
131
  },
81
- "required": ["api", "page"],
132
+ "required": ["success", "status", "query", "documents", "sources", "total"],
82
133
  "additionalProperties": false
83
- },
84
- "total": {
85
- "type": "integer",
86
- "minimum": 0
87
134
  }
88
- },
89
- "required": ["success", "status", "query", "documents", "sources", "total"],
90
- "additionalProperties": false
135
+ ]
91
136
  },
92
137
  "steps": [
93
138
  {
94
139
  "tool": "chrome_javascript",
95
140
  "args": {
96
- "code": "const query = String(input.query || '').trim();\nconst limit = Math.max(1, Math.min(Number(input.limit) || 5, 10));\nconst endpoint = new URL('/api/v1/search', location.origin);\nendpoint.searchParams.set('q', query);\nendpoint.searchParams.set('locale', 'en-US');\nconst response = await fetch(endpoint.href, { credentials: 'include', headers: { Accept: 'application/json' } });\nif (!response.ok) return { success: false, status: 'http_error', query, httpStatus: response.status, source: response.url };\nconst data = await response.json();\nconst documents = (Array.isArray(data.documents) ? data.documents : [])\n .filter(item => item && typeof item.mdn_url === 'string' && item.mdn_url.startsWith('/'))\n .slice(0, limit)\n .map(item => ({\n title: String(item.title || '').replace(/<[^>]*>/g, ''),\n url: new URL(item.mdn_url, location.origin).href,\n summary: String(item.summary || '').replace(/<[^>]*>/g, '')\n }));\nif (!documents.length) return { success: false, status: 'empty', query, source: endpoint.href };\nreturn {\n success: true,\n status: 'ok',\n query,\n documents,\n sources: { api: response.url, page: location.href },\n total: Number(data.metadata && data.metadata.total && data.metadata.total.value || documents.length)\n};"
141
+ "code": "const query = String(input.query || '').trim();\nconst limit = Math.max(1, Math.min(Number(input.limit) || 5, 10));\nconst fallbackPage = 'https://developer.mozilla.org/en-US/search?q=' + encodeURIComponent(query);\nconst origin = typeof location !== 'undefined' && typeof location.origin === 'string' && /^https:\\/\\/developer\\.mozilla\\.org$/i.test(location.origin) ? location.origin : '';\nif (!origin) {\n return { success: false, status: 'page_not_ready', query, message: 'MDN page origin is not ready', source: fallbackPage };\n}\nconst endpoint = new URL('/api/v1/search', origin);\nendpoint.searchParams.set('q', query);\nendpoint.searchParams.set('locale', 'en-US');\nconst pageUrl = typeof location.href === 'string' && location.href.startsWith(origin) ? location.href : fallbackPage;\nlet response;\ntry {\n response = await fetch(endpoint.href, { credentials: 'include', headers: { Accept: 'application/json' } });\n} catch (error) {\n return { success: false, status: 'fetch_error', query, message: String(error && error.message || error), source: endpoint.href };\n}\nif (response.status === 429) {\n return { success: false, status: 'rate_limited', query, httpStatus: 429, source: response.url || endpoint.href };\n}\nif (!response.ok) return { success: false, status: 'http_error', query, httpStatus: response.status, source: response.url || endpoint.href };\nlet data;\ntry {\n data = await response.json();\n} catch {\n return { success: false, status: 'invalid_json', query, source: response.url || endpoint.href };\n}\nif (!data || typeof data !== 'object') {\n return { success: false, status: 'schema_changed', query, source: response.url || endpoint.href };\n}\nconst documents = (Array.isArray(data.documents) ? data.documents : [])\n .filter(item => item && typeof item.mdn_url === 'string' && item.mdn_url.startsWith('/'))\n .map(item => ({\n title: String(item.title || '').replace(/<[^>]*>/g, '').trim(),\n url: new URL(item.mdn_url, origin).href,\n summary: String(item.summary || '').replace(/<[^>]*>/g, '').trim()\n }))\n .filter(item => item.title && /^https:\\/\\/developer\\.mozilla\\.org\\/[a-z]{2}(?:-[A-Z]{2})?\\/docs\\//.test(item.url))\n .slice(0, limit);\nif (!documents.length) {\n return {\n success: true,\n status: 'empty',\n query,\n documents: [],\n sources: { api: response.url || endpoint.href, page: pageUrl },\n total: 0\n };\n}\nreturn {\n success: true,\n status: 'ok',\n query,\n documents,\n sources: { api: response.url || endpoint.href, page: pageUrl },\n total: Math.max(documents.length, Math.floor(Number(data.metadata && data.metadata.total && data.metadata.total.value) || documents.length))\n};"
97
142
  },
98
143
  "resultPath": "/result"
99
144
  }
@@ -22,7 +22,10 @@
22
22
  "compare",
23
23
  "version",
24
24
  "downloads",
25
- "capabilities"
25
+ "capabilities",
26
+ "npm对比",
27
+ "包对比",
28
+ "依赖对比"
26
29
  ],
27
30
  "startUrl": "https://registry.npmjs.org/{{left}}/latest",
28
31
  "inputSchema": {
@@ -132,8 +135,7 @@
132
135
  "minLength": 1
133
136
  },
134
137
  "description": {
135
- "type": "string",
136
- "minLength": 1
138
+ "type": "string"
137
139
  },
138
140
  "license": {
139
141
  "oneOf": [
@@ -195,7 +197,7 @@
195
197
  {
196
198
  "tool": "chrome_javascript",
197
199
  "args": {
198
- "code": "const registryOrigin = 'https://registry.npmjs.org/';\nconst downloadsOrigin = 'https://api.npmjs.org/downloads/point/last-week/';\nconst packagePath = name => encodeURIComponent(name);\nconst loadJson = async (url, label) => {\n let response;\n try {\n response = await fetch(url, { credentials: 'omit', headers: { Accept: 'application/json' } });\n } catch (error) {\n throw new Error(label + ' request failed: ' + String(error && error.message || error));\n }\n if (!response.ok) throw new Error(label + ' failed with status ' + response.status);\n let payload;\n try {\n payload = await response.json();\n } catch (error) {\n throw new Error(label + ' returned invalid JSON: ' + String(error && error.message || error));\n }\n if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {\n throw new Error(label + ' returned invalid data');\n }\n return { payload, source: String(response.url || url) };\n};\nconst repositoryUrl = value => {\n let raw = typeof value === 'string' ? value : value && typeof value.url === 'string' ? value.url : '';\n raw = raw.trim();\n if (!raw) return null;\n raw = raw.replace(/^git\\+/, '').replace(/^git:\\/\\/github\\.com\\//i, 'https://github.com/');\n if (/^github:/i.test(raw)) raw = 'https://github.com/' + raw.slice(7);\n else if (/^[^/:]+\\/[^/]+$/.test(raw)) raw = 'https://github.com/' + raw;\n raw = raw.replace(/\\.git(?:#.*)?$/, '');\n try {\n const url = new URL(raw);\n return url.protocol === 'http:' || url.protocol === 'https:' ? url.href : null;\n } catch {\n return null;\n }\n};\nconst loadPackage = async packageName => {\n const encoded = packagePath(packageName);\n const [metadata, downloads] = await Promise.all([\n loadJson(registryOrigin + encoded + '/latest', 'npm metadata for ' + packageName),\n loadJson(downloadsOrigin + encoded, 'npm downloads for ' + packageName)\n ]);\n const manifest = metadata.payload;\n if (manifest.name !== packageName) {\n throw new Error('npm metadata name mismatch for ' + packageName + ': ' + String(manifest.name));\n }\n const latestVersion = manifest.version;\n if (typeof latestVersion !== 'string' || !latestVersion) {\n throw new Error('npm metadata missing version for ' + packageName);\n }\n const description = typeof manifest.description === 'string' ? manifest.description.trim() : '';\n if (!description) throw new Error('npm metadata missing description for ' + packageName + '@' + latestVersion);\n const rawLicense = manifest.license;\n const license = typeof rawLicense === 'string' && rawLicense.trim()\n ? rawLicense.trim()\n : rawLicense && typeof rawLicense.type === 'string' && rawLicense.type.trim()\n ? rawLicense.type.trim()\n : null;\n const rawEngines = manifest.engines && typeof manifest.engines === 'object' && !Array.isArray(manifest.engines)\n ? manifest.engines\n : {};\n const engines = Object.fromEntries(Object.entries(rawEngines).filter(([, value]) => typeof value === 'string'));\n if (downloads.payload.package !== packageName) {\n throw new Error('npm downloads name mismatch for ' + packageName + ': ' + String(downloads.payload.package));\n }\n const count = Number(downloads.payload.downloads);\n if (!Number.isInteger(count) || count < 0) {\n throw new Error('npm downloads returned an invalid count for ' + packageName);\n }\n const start = String(downloads.payload.start || '');\n const end = String(downloads.payload.end || '');\n if (!start || !end) throw new Error('npm downloads returned an invalid date range for ' + packageName);\n return {\n metric: {\n package: packageName,\n downloads: count,\n latestVersion,\n description,\n license,\n repository: repositoryUrl(manifest.repository),\n engines,\n start,\n end,\n source: downloads.source\n },\n metadataSource: metadata.source\n };\n};\nconst leftName = String(input.left || '').trim();\nconst rightName = String(input.right || '').trim();\ntry {\n const [left, right] = await Promise.all([loadPackage(leftName), loadPackage(rightName)]);\n return {\n success: true,\n status: 'ok',\n left: left.metric,\n right: right.metric,\n leader: left.metric.downloads === right.metric.downloads ? 'tie' : left.metric.downloads > right.metric.downloads ? 'left' : 'right',\n sources: {\n left: left.metric.source,\n right: right.metric.source,\n metadata: { left: left.metadataSource, right: right.metadataSource }\n }\n };\n} catch (error) {\n return { success: false, status: 'api_error', message: String(error && error.message || error), left: leftName, right: rightName };\n}",
200
+ "code": "const registryOrigin = 'https://registry.npmjs.org/';\nconst downloadsOrigin = 'https://api.npmjs.org/downloads/point/last-week/';\nconst packagePath = name => encodeURIComponent(name);\nconst loadJson = async (url, label) => {\n let response;\n try {\n response = await fetch(url, { credentials: 'omit', headers: { Accept: 'application/json' } });\n } catch (error) {\n throw new Error(label + ' request failed: ' + String(error && error.message || error));\n }\n if (!response.ok) throw new Error(label + ' failed with status ' + response.status);\n let payload;\n try {\n payload = await response.json();\n } catch (error) {\n throw new Error(label + ' returned invalid JSON: ' + String(error && error.message || error));\n }\n if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {\n throw new Error(label + ' returned invalid data');\n }\n return { payload, source: String(response.url || url) };\n};\nconst repositoryUrl = value => {\n let raw = typeof value === 'string' ? value : value && typeof value.url === 'string' ? value.url : '';\n raw = raw.trim();\n if (!raw) return null;\n raw = raw.replace(/^git\\+/, '').replace(/^git:\\/\\/github\\.com\\//i, 'https://github.com/');\n if (/^github:/i.test(raw)) raw = 'https://github.com/' + raw.slice(7);\n else if (/^[^/:]+\\/[^/]+$/.test(raw)) raw = 'https://github.com/' + raw;\n raw = raw.replace(/\\.git(?:#.*)?$/, '');\n try {\n const url = new URL(raw);\n return url.protocol === 'http:' || url.protocol === 'https:' ? url.href : null;\n } catch {\n return null;\n }\n};\nconst loadPackage = async packageName => {\n const encoded = packagePath(packageName);\n const [metadata, downloads] = await Promise.all([\n loadJson(registryOrigin + encoded + '/latest', 'npm metadata for ' + packageName),\n loadJson(downloadsOrigin + encoded, 'npm downloads for ' + packageName)\n ]);\n const manifest = metadata.payload;\n if (manifest.name !== packageName) {\n throw new Error('npm metadata name mismatch for ' + packageName + ': ' + String(manifest.name));\n }\n const latestVersion = manifest.version;\n if (typeof latestVersion !== 'string' || !latestVersion) {\n throw new Error('npm metadata missing version for ' + packageName);\n }\n const description = typeof manifest.description === 'string' ? manifest.description.trim() : '';\n const rawLicense = manifest.license;\n const license = typeof rawLicense === 'string' && rawLicense.trim()\n ? rawLicense.trim()\n : rawLicense && typeof rawLicense.type === 'string' && rawLicense.type.trim()\n ? rawLicense.type.trim()\n : null;\n const rawEngines = manifest.engines && typeof manifest.engines === 'object' && !Array.isArray(manifest.engines)\n ? manifest.engines\n : {};\n const engines = Object.fromEntries(Object.entries(rawEngines).filter(([, value]) => typeof value === 'string'));\n if (downloads.payload.package !== packageName) {\n throw new Error('npm downloads name mismatch for ' + packageName + ': ' + String(downloads.payload.package));\n }\n const count = Number(downloads.payload.downloads);\n if (!Number.isInteger(count) || count < 0) {\n throw new Error('npm downloads returned an invalid count for ' + packageName);\n }\n const start = String(downloads.payload.start || '');\n const end = String(downloads.payload.end || '');\n if (!start || !end) throw new Error('npm downloads returned an invalid date range for ' + packageName);\n return {\n metric: {\n package: packageName,\n downloads: count,\n latestVersion,\n description,\n license,\n repository: repositoryUrl(manifest.repository),\n engines,\n start,\n end,\n source: downloads.source\n },\n metadataSource: metadata.source\n };\n};\nconst leftName = String(input.left || '').trim();\nconst rightName = String(input.right || '').trim();\ntry {\n const [left, right] = await Promise.all([loadPackage(leftName), loadPackage(rightName)]);\n return {\n success: true,\n status: 'ok',\n left: left.metric,\n right: right.metric,\n leader: left.metric.downloads === right.metric.downloads ? 'tie' : left.metric.downloads > right.metric.downloads ? 'left' : 'right',\n sources: {\n left: left.metric.source,\n right: right.metric.source,\n metadata: { left: left.metadataSource, right: right.metadataSource }\n }\n };\n} catch (error) {\n return { success: false, status: 'api_error', message: String(error && error.message || error), left: leftName, right: rightName };\n}",
199
201
  "timeoutMs": 60000
200
202
  },
201
203
  "resultPath": "/result"
@@ -0,0 +1,289 @@
1
+ {
2
+ "id": "reddit-post-read",
3
+ "name": "Reddit post and comments reader",
4
+ "description": "Read a Reddit post and its top comments using Chrome's session via same-origin JSON with visible DOM fallback.",
5
+ "source": {
6
+ "type": "builtin",
7
+ "urls": [
8
+ "https://old.reddit.com/r/programming/comments/f9ut5f/",
9
+ "https://old.reddit.com/r/programming/comments/226xun/"
10
+ ]
11
+ },
12
+ "domains": [
13
+ "www.reddit.com",
14
+ "reddit.com",
15
+ "old.reddit.com"
16
+ ],
17
+ "keywords": [
18
+ "reddit",
19
+ "红迪",
20
+ "post",
21
+ "thread",
22
+ "comments",
23
+ "discussion",
24
+ "帖子",
25
+ "评论",
26
+ "详情",
27
+ "红迪帖子",
28
+ "Reddit评论",
29
+ "读帖"
30
+ ],
31
+ "startUrl": "https://old.reddit.com/r/{{subreddit}}/comments/{{postId}}/",
32
+ "inputSchema": {
33
+ "type": "object",
34
+ "properties": {
35
+ "subreddit": {
36
+ "type": "string",
37
+ "pattern": "^[A-Za-z0-9_]{2,50}$"
38
+ },
39
+ "postId": {
40
+ "type": "string",
41
+ "pattern": "^[A-Za-z0-9]{1,16}$"
42
+ },
43
+ "limit": {
44
+ "type": "integer",
45
+ "minimum": 1,
46
+ "maximum": 25,
47
+ "default": 15
48
+ }
49
+ },
50
+ "required": [
51
+ "subreddit",
52
+ "postId"
53
+ ],
54
+ "additionalProperties": false
55
+ },
56
+ "outputSchema": {
57
+ "type": "object",
58
+ "properties": {
59
+ "success": {
60
+ "const": true
61
+ },
62
+ "status": {
63
+ "const": "ok"
64
+ },
65
+ "post": {
66
+ "type": "object",
67
+ "properties": {
68
+ "id": {
69
+ "type": "string",
70
+ "minLength": 1
71
+ },
72
+ "subreddit": {
73
+ "type": "string"
74
+ },
75
+ "title": {
76
+ "type": "string",
77
+ "minLength": 1
78
+ },
79
+ "author": {
80
+ "type": "string"
81
+ },
82
+ "score": {
83
+ "type": "integer"
84
+ },
85
+ "commentsCount": {
86
+ "type": "integer",
87
+ "minimum": 0
88
+ },
89
+ "url": {
90
+ "type": "string",
91
+ "pattern": "^https://(?:(?:www|old|sh|new)\\.)?reddit\\.com/r/"
92
+ },
93
+ "body": {
94
+ "type": "string"
95
+ }
96
+ },
97
+ "required": [
98
+ "id",
99
+ "subreddit",
100
+ "title",
101
+ "author",
102
+ "score",
103
+ "commentsCount",
104
+ "url",
105
+ "body"
106
+ ],
107
+ "additionalProperties": false
108
+ },
109
+ "comments": {
110
+ "type": "array",
111
+ "maxItems": 25,
112
+ "items": {
113
+ "type": "object",
114
+ "properties": {
115
+ "id": {
116
+ "type": "string"
117
+ },
118
+ "author": {
119
+ "type": "string"
120
+ },
121
+ "score": {
122
+ "type": "integer"
123
+ },
124
+ "body": {
125
+ "type": "string"
126
+ }
127
+ },
128
+ "required": [
129
+ "id",
130
+ "author",
131
+ "score",
132
+ "body"
133
+ ],
134
+ "additionalProperties": false
135
+ }
136
+ },
137
+ "sources": {
138
+ "type": "object",
139
+ "properties": {
140
+ "api": {
141
+ "oneOf": [
142
+ {
143
+ "type": "string",
144
+ "pattern": "^https://(?:(?:www|old|sh|new)\\.)?reddit\\.com/"
145
+ },
146
+ {
147
+ "type": "null"
148
+ }
149
+ ]
150
+ },
151
+ "page": {
152
+ "type": "string",
153
+ "pattern": "^https://(?:(?:www|old|sh|new)\\.)?reddit\\.com/"
154
+ }
155
+ },
156
+ "required": [
157
+ "api",
158
+ "page"
159
+ ],
160
+ "additionalProperties": false
161
+ }
162
+ },
163
+ "required": [
164
+ "success",
165
+ "status",
166
+ "post",
167
+ "comments",
168
+ "sources"
169
+ ],
170
+ "additionalProperties": false
171
+ },
172
+ "steps": [
173
+ {
174
+ "tool": "chrome_javascript",
175
+ "args": {
176
+ "code": "const subreddit = String(input.subreddit || '').trim();\nconst postId = String(input.postId || '').trim();\nconst limit = Math.max(1, Math.min(Number(input.limit) || 15, 25));\nconst fallbackUrl = 'https://old.reddit.com/r/' + encodeURIComponent(subreddit) + '/comments/' + encodeURIComponent(postId) + '/';\nconst origin = typeof location !== 'undefined' && typeof location.origin === 'string' && /^https:\\/\\/(?:(?:www|old|new|sh)\\.)?reddit\\.com$/i.test(location.origin) ? location.origin : '';\nif (!origin) {\n return { success: false, status: 'page_not_ready', subreddit, postId, message: 'Reddit page origin is not ready', source: fallbackUrl };\n}\nconst pageUrl = new URL('/r/' + encodeURIComponent(subreddit) + '/comments/' + encodeURIComponent(postId) + '/', origin).href;\nconst fetchLimit = Math.min(500, Math.max(limit * 4, 100));\nconst jsonUrl = new URL('/r/' + encodeURIComponent(subreddit) + '/comments/' + encodeURIComponent(postId) + '.json?limit=' + fetchLimit + '&raw_json=1', origin).href;\nlet blockedStatus = null;\ntry {\n const response = await fetch(jsonUrl, { credentials: 'include', headers: { Accept: 'application/json' } });\n if (response.status === 429) {\n blockedStatus = { success: false, status: 'rate_limited', subreddit, postId, httpStatus: 429, source: response.url || jsonUrl };\n } else if (response.status === 404) {\n return { success: false, status: 'not_found', subreddit, postId, httpStatus: 404, source: response.url || jsonUrl };\n } else if (response.status === 401) {\n blockedStatus = { success: false, status: 'requires_auth', subreddit, postId, requiresLogin: true, httpStatus: 401, source: response.url || jsonUrl };\n } else if (response.status === 403) {\n let reason = '';\n try {\n const errBody = await response.json();\n reason = String((errBody && (errBody.reason || errBody.message)) || '').toLowerCase();\n } catch {}\n if (reason.includes('quarantin') || reason.includes('over18')) {\n blockedStatus = { success: false, status: 'over18_or_quarantined', subreddit, postId, httpStatus: 403, message: 'Reddit post is quarantined or requires 18+ confirmation', source: response.url || jsonUrl };\n } else if (reason.includes('private')) {\n blockedStatus = { success: false, status: 'requires_auth', subreddit, postId, requiresLogin: true, httpStatus: 403, message: 'Reddit community is private or requires authentication', source: response.url || jsonUrl };\n } else {\n blockedStatus = { success: false, status: 'blocked', subreddit, postId, httpStatus: 403, message: 'Reddit returned HTTP 403 for this post', source: response.url || jsonUrl };\n }\n } else if (response.ok) {\n const data = await response.json();\n if (data && !Array.isArray(data) && (String(data.reason || '').toLowerCase().includes('quarantin') || String(data.reason || '').toLowerCase().includes('over18'))) {\n blockedStatus = { success: false, status: 'over18_or_quarantined', subreddit, postId, message: 'Reddit post is quarantined or requires 18+ confirmation', source: response.url || jsonUrl };\n }\n if (Array.isArray(data) && data.length >= 2) {\n const postEntry = data[0] && data[0].data && Array.isArray(data[0].data.children) ? data[0].data.children[0] : null;\n const d = postEntry && postEntry.data;\n if (d && d.title) {\n const permalink = String(d.permalink || '').trim();\n const rawComments = data[1] && data[1].data && Array.isArray(data[1].data.children) ? data[1].data.children : [];\n const comments = rawComments\n .filter(c => c && c.kind === 't1' && c.data && typeof c.data.body === 'string' && c.data.body.trim())\n .slice(0, limit)\n .map(c => ({\n id: String(c.data.id || '').trim(),\n author: String(c.data.author || '').trim(),\n score: Math.floor(Number(c.data.score) || 0),\n body: String(c.data.body || '').trim().slice(0, 1500)\n }));\n return {\n success: true,\n status: 'ok',\n post: {\n id: String(d.id || postId).trim(),\n subreddit: String(d.subreddit || subreddit).trim(),\n title: String(d.title || '').trim(),\n author: String(d.author || '').trim(),\n score: Math.floor(Number(d.score) || 0),\n commentsCount: Math.max(comments.length, Math.floor(Number(d.num_comments) || 0)),\n url: permalink ? new URL(permalink, 'https://www.reddit.com').href : pageUrl,\n body: String(d.selftext || '').trim().slice(0, 6000)\n },\n comments,\n sources: { api: response.url || jsonUrl, page: permalink ? new URL(permalink, 'https://www.reddit.com').href : pageUrl }\n };\n }\n }\n }\n} catch {\n // Fall back to visible DOM below.\n}\nif (typeof document !== 'undefined' && document && typeof document.querySelector === 'function') {\n const postEl = document.querySelector('shreddit-post');\n if (postEl) {\n const title = String(postEl.getAttribute('post-title') || '').trim();\n const permalink = String(postEl.getAttribute('permalink') || '').trim();\n const bodyEl = postEl.querySelector('[slot=\"text-body\"], div[id$=\"-post-rtjson-content\"]');\n if (title) {\n const commentEls = typeof document.querySelectorAll === 'function' ? Array.from(document.querySelectorAll('shreddit-comment')) : [];\n const comments = commentEls.map(el => {\n const commentBody = el.querySelector('[slot=\"comment\"], div[id$=\"-post-rtjson-content\"]');\n return {\n id: String(el.getAttribute('thingid') || '').replace(/^t1_/, '').trim(),\n author: String(el.getAttribute('author') || '').trim(),\n score: Math.floor(Number(el.getAttribute('score')) || 0),\n body: String((commentBody && (commentBody.innerText || commentBody.textContent)) || '').trim().slice(0, 1500)\n };\n }).filter(c => c.body && (c.id || c.author)).slice(0, limit);\n const resolvedUrl = permalink ? new URL(permalink, origin).href : pageUrl;\n return {\n success: true,\n status: 'ok',\n post: {\n id: String(postEl.getAttribute('id') || postId).replace(/^t3_/, '').trim(),\n subreddit: String(postEl.getAttribute('subreddit-prefixed-name') || subreddit).replace(/^r\\//, '').trim(),\n title,\n author: String(postEl.getAttribute('author') || '').trim(),\n score: Math.floor(Number(postEl.getAttribute('score')) || 0),\n commentsCount: Math.max(comments.length, Math.floor(Number(postEl.getAttribute('comment-count')) || 0)),\n url: resolvedUrl,\n body: String((bodyEl && (bodyEl.innerText || bodyEl.textContent)) || '').trim().slice(0, 6000)\n },\n comments,\n sources: { api: null, page: location.href || resolvedUrl }\n };\n }\n }\n const oldPostEl = document.querySelector('#siteTable .thing.link, .thing.link');\n if (oldPostEl) {\n const titleEl = oldPostEl.querySelector('a.title');\n const title = String((titleEl && (titleEl.innerText || titleEl.textContent)) || '').trim();\n const permalink = String(oldPostEl.getAttribute('data-permalink') || '').trim();\n const bodyEl = oldPostEl.querySelector('.expando .usertext-body .md, .usertext-body .md');\n if (title) {\n const topCommentEls = typeof document.querySelectorAll === 'function' ? Array.from(document.querySelectorAll('.commentarea > .sitetable > .thing.comment')) : [];\n const oldCommentEls = topCommentEls.length ? topCommentEls : (typeof document.querySelectorAll === 'function' ? Array.from(document.querySelectorAll('.commentarea .thing.comment')) : []);\n const comments = oldCommentEls.map(el => {\n const scoreEl = el.querySelector(':scope > .entry .score.unvoted') || el.querySelector('.entry .score.unvoted');\n const rawScore = scoreEl ? (scoreEl.getAttribute('title') || scoreEl.textContent || '') : '';\n const scoreMatch = String(rawScore).match(/-?\\d+/);\n const commentBody = el.querySelector(':scope > .entry .usertext-body .md') || el.querySelector('.entry .usertext-body .md');\n return {\n id: String(el.getAttribute('data-fullname') || '').replace(/^t1_/, '').trim(),\n author: String(el.getAttribute('data-author') || '').trim(),\n score: scoreMatch ? Math.floor(Number(scoreMatch[0]) || 0) : 0,\n body: String((commentBody && (commentBody.innerText || commentBody.textContent)) || '').trim().slice(0, 1500)\n };\n }).filter(c => c.body && (c.id || c.author)).slice(0, limit);\n const resolvedUrl = permalink ? new URL(permalink, origin).href : pageUrl;\n return {\n success: true,\n status: 'ok',\n post: {\n id: String(oldPostEl.getAttribute('data-fullname') || postId).replace(/^t3_/, '').trim(),\n subreddit: String(oldPostEl.getAttribute('data-subreddit') || subreddit).replace(/^r\\//, '').trim(),\n title,\n author: String(oldPostEl.getAttribute('data-author') || '').trim(),\n score: Math.floor(Number(oldPostEl.getAttribute('data-score')) || 0),\n commentsCount: Math.max(comments.length, Math.floor(Number(oldPostEl.getAttribute('data-comments-count')) || 0)),\n url: resolvedUrl,\n body: String((bodyEl && (bodyEl.innerText || bodyEl.textContent)) || '').trim().slice(0, 6000)\n },\n comments,\n sources: { api: null, page: location.href || resolvedUrl }\n };\n }\n }\n}\nconst pathname = String(location.pathname || '');\nif (typeof document !== 'undefined' && document && typeof document.querySelector === 'function') {\n if (/^\\/over18(?:\\/|$)/i.test(pathname) || document.querySelector('form[action*=\"/over18\"], shreddit-over18-interstitial, [data-testid=\"nsfw-interstitial\"], button[name=\"over18\"]')) {\n return { success: false, status: 'over18_or_quarantined', subreddit, postId, message: 'Reddit requires NSFW (18+) confirmation for this post', source: location.href || pageUrl };\n }\n if (document.querySelector('.quarantine-notice, form[action*=\"/quarantine\"], [data-testid=\"quarantine-interstitial\"]')) {\n return { success: false, status: 'over18_or_quarantined', subreddit, postId, message: 'This Reddit community is quarantined', source: location.href || pageUrl };\n }\n}\nif (blockedStatus) return blockedStatus;\nif (/^\\/login(?:\\/|$)/i.test(pathname) || (typeof document !== 'undefined' && document && typeof document.querySelector === 'function' && document.querySelector('form[action*=\"/login\"], input[name=\"username\"]'))) {\n return { success: false, status: 'requires_auth', subreddit, postId, requiresLogin: true, message: 'Reddit requires authentication for this post', source: location.href || pageUrl };\n}\nreturn { success: false, status: 'blocked', subreddit, postId, message: 'Reddit post was not readable via JSON API or visible DOM', source: location.href || pageUrl };",
177
+ "timeoutMs": 25000
178
+ },
179
+ "resultPath": "/result"
180
+ }
181
+ ],
182
+ "verification": {
183
+ "tool": "chrome_read_dom",
184
+ "args": {
185
+ "format": "compact",
186
+ "selector": "main, [role=\"main\"]",
187
+ "activeViewportOnly": false,
188
+ "limit": 80,
189
+ "maxTextLength": 220
190
+ },
191
+ "resultPath": "/treeString"
192
+ },
193
+ "tests": [
194
+ {
195
+ "inputs": {
196
+ "subreddit": "programming",
197
+ "postId": "f9ut5f",
198
+ "limit": 5
199
+ },
200
+ "expect": {
201
+ "type": "object",
202
+ "properties": {
203
+ "success": {
204
+ "const": true
205
+ },
206
+ "post": {
207
+ "type": "object",
208
+ "properties": {
209
+ "id": {
210
+ "const": "f9ut5f"
211
+ },
212
+ "title": {
213
+ "type": "string",
214
+ "minLength": 1
215
+ }
216
+ },
217
+ "required": [
218
+ "id",
219
+ "title"
220
+ ]
221
+ },
222
+ "sources": {
223
+ "type": "object",
224
+ "required": [
225
+ "page"
226
+ ]
227
+ }
228
+ },
229
+ "required": [
230
+ "success",
231
+ "post",
232
+ "comments",
233
+ "sources"
234
+ ]
235
+ },
236
+ "observe": {
237
+ "type": "string",
238
+ "pattern": "programming|comments|Reddit"
239
+ }
240
+ },
241
+ {
242
+ "inputs": {
243
+ "subreddit": "programming",
244
+ "postId": "226xun",
245
+ "limit": 5
246
+ },
247
+ "expect": {
248
+ "type": "object",
249
+ "properties": {
250
+ "success": {
251
+ "const": true
252
+ },
253
+ "post": {
254
+ "type": "object",
255
+ "properties": {
256
+ "id": {
257
+ "const": "226xun"
258
+ },
259
+ "title": {
260
+ "type": "string",
261
+ "minLength": 1
262
+ }
263
+ },
264
+ "required": [
265
+ "id",
266
+ "title"
267
+ ]
268
+ },
269
+ "sources": {
270
+ "type": "object",
271
+ "required": [
272
+ "page"
273
+ ]
274
+ }
275
+ },
276
+ "required": [
277
+ "success",
278
+ "post",
279
+ "comments",
280
+ "sources"
281
+ ]
282
+ },
283
+ "observe": {
284
+ "type": "string",
285
+ "pattern": "programming|comments|Reddit"
286
+ }
287
+ }
288
+ ]
289
+ }