Fetch a full Reddit thread (post + comments) from its permalink, to have the context and write a reply that adds value (not spam).
{"limit":"int optional (default 30)","permalink":"string (post URL or path)"}{"post":"{ title, subreddit, author, ups, num_comments, created, selftext, link, permalink }","comments":"array of { author, ups, body, depth }","commentCount":"int"}Fetch a full Reddit thread (post + comments) from its permalink, to have the context and write a reply that adds value (not spam). Uses Reddit's .json endpoint. PARAMS: permalink (post URL or path, e.g. 'https://www.reddit.com/r/SaaS/comments/abc/...' or '/r/SaaS/comments/abc/...'; comes from reddit-search-posts); limit optional (how many comments to fetch, default 30, max 100). Returns { post:{title,subreddit,author,ups,num_comments,created,selftext,link,permalink}, commentCount, comments:[{author,ups,body,depth}] } (flattened comments with depth; up to 60). Requires a Reddit session. Stable .json endpoint.
params. It does the in-page work and returns the JSON in returns.( async (root, params) => { let pl = String((params && params.permalink) || '').trim(); if(!pl) return { error:'missing permalink' }; pl = pl.replace(/^https?://[^/]+/,'').replace(//$/,''); let limit = parseInt(String((params && params.limit) || '30'),10) || 30; if(limit>100) limit=100; let r, d; try { r = await fetch(pl+'.json?raw_json=1&limit='+limit, {credentials:'include', headers:{'accept':'application/json'}}); d = await r.json(); } catch(e){ return { error:'fetch fail: '+String(e) }; } let post=null; try { const p=d[0].data.children[0].data; post={ title:p.title, subreddit:p.subreddit, author:p.author, ups:p.ups, num_comments:p.num_comments, created:p.created_utc, selftext:(p.selftext||null), link:(p.is_self?null:(p.url||null)), permalink:'https://www.reddit.com'+p.permalink }; } catch(e){ return { error:'no post in response' }; } const comments=[]; const walk=(arr,depth)=>{ (arr||[]).forEach(c=>{ if(comments.length>=60) return; if(c.kind==='t1' && c.data && c.data.body){ comments.push({ author:c.data.author, ups:c.data.ups, body:(c.data.body||'').slice(0,600), depth }); if(c.data.replies && c.data.replies.data) walk(c.data.replies.data.children, depth+1); } }); }; try { walk(d[1].data.children, 0); } catch(e){} return { post, commentCount: comments.length, comments }; } )
Response text contains "reddit".