You can access search results via JSON API by adding format=json
to your query:
https://codesearch.val.run/image-url.jpg%20%22Optional%20title%22?q=api&page=50&format=json
For typeahead suggestions, use the /typeahead
endpoint:
https://codesearch.val.run/typeahead?q=api
Returns an array of strings in format "username" or "username/projectName"
Found 11824 results for "api"(612ms)
273<title>The S.M.A.R.T Hive</title>
274<meta name="viewport" content="width=device-width, initial-scale=1">
275<link rel="preconnect" href="https://fonts.googleapis.com">
276<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
277<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&display=swap" rel="stylesheet">
278<script src="https://esm.town/v/std/catch"></script>
279</head>
17}
1819// single-post regex handles www, old, api, or naked reddit.com
20if (/^https?:\/\/(?:[^/]+\.)?reddit\.com\/.*\/comments\/[a-z0-9]+/i.test(feedUrl)) {
21try {
65const pathname = new URL(postUrl).pathname.replace(/\/$/, "");
66const headers = {
67// UA beginning with “Reddit/” is whitelisted for api.reddit.com JSON
68"User-Agent": "Reddit/20230522 (Android 14; Pixel 8 Pro)",
69"Accept": "application/json",
70};
7172// 1️⃣ try api.reddit.com (no Cloudflare)
73let txt = await fetch(`https://api.reddit.com${pathname}?limit=${limit}&raw_json=1`, { headers })
74.then(r => r.text());
75if (txt.trim().startsWith("<")) { // got HTML ➜ fallback
79}).then(r => r.text());
80if (txt.trim().startsWith("<"))
81throw new Error("Both api.reddit.com and old.reddit.com returned HTML (likely blocked)");
82}
83