Files
jackwener__opencli/clis/nowcoder/detail.js
Cosmostima 44b4107f36 feat(nowcoder): add 牛客网 adapter with 16 commands (#1036)
* feat(nowcoder): add 牛客网 adapter with 16 commands

Add adapters for Nowcoder (牛客网), China's leading tech job-seeking
and interview preparation community.

- 7 Public commands: hot, trending, topics, recommend, creators, companies, jobs
- 9 Cookie commands: search, suggest, experience, referral, salary, papers, practice, notifications, detail
- All post-list commands include id field for drill-down to detail
- Documentation: adapter page, index table, sidebar entry

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(nowcoder): register adapter and document usage

---------

Co-authored-by: tima <tima@cosmos-macmini.local>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: jackwener <jakevingoo@gmail.com>
2026-04-15 22:51:55 +08:00

62 lines
2.1 KiB
JavaScript

import { cli } from '@jackwener/opencli/registry';
cli({
site: 'nowcoder',
name: 'detail',
description: 'Post detail view (supports ID / UUID / URL)',
domain: 'www.nowcoder.com',
args: [
{ name: 'id', positional: true, required: true, help: 'Post ID, UUID, or URL' },
],
columns: ['title', 'author', 'school', 'content', 'likes', 'comments', 'views', 'time', 'location'],
pipeline: [
{ navigate: 'https://www.nowcoder.com' },
{ evaluate: `(async () => {
const raw = \${{ args.id | json }};
const base = 'https://gw-c.nowcoder.com';
const strip = (html) => (html || '').replace(/<[^>]+>/g, '').replace(/&nbsp;/g, ' ').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&').trim();
let id = raw;
const urlMatch = raw.match(/discuss\\/(\\d+)/);
if (urlMatch) id = urlMatch[1];
let data = null;
if (/[a-f]/.test(id) && id.length > 20) {
const r = await fetch(base + '/api/sparta/detail/moment-data/detail/' + id, {credentials: 'include'});
const d = await r.json();
if (d.success && d.data) data = d.data;
}
if (!data && /^\\d+$/.test(id)) {
const r = await fetch(base + '/api/sparta/detail/content-data/detail/' + id, {credentials: 'include'});
const d = await r.json();
if (d.success && d.data) data = d.data;
}
if (!data && /^\\d+$/.test(id)) {
const r = await fetch(base + '/api/sparta/detail/moment-data/detail/' + id, {credentials: 'include'});
const d = await r.json();
if (d.success && d.data) data = d.data;
}
if (!data) throw new Error('Post not found: ' + id);
const user = data.userBrief || {};
const freq = data.frequencyData || {};
return [{
title: data.title || '(untitled)',
author: user.nickname || '',
school: user.educationInfo || '',
content: strip(data.content || '').substring(0, 500),
likes: freq.likeCnt || 0,
comments: freq.commentCnt || freq.totalCommentCnt || 0,
views: freq.viewCnt || 0,
time: data.createdAt ? new Date(data.createdAt).toISOString().slice(0, 19) : '',
location: data.ip4Location || '',
}];
})()
` },
],
});