Skip to content

Instantly share code, notes, and snippets.

@inabahare
Created October 29, 2023 09:13
Show Gist options
  • Save inabahare/af0026214ac34b835c0847e2a0a816f1 to your computer and use it in GitHub Desktop.
Save inabahare/af0026214ac34b835c0847e2a0a816f1 to your computer and use it in GitHub Desktop.
kodownloader
(async () => {
const threads = [
418,
21855,
34859,
50600
]
const apiUrl = "https://api.knockout.chat/v2/threads";
const result = [];
for (const thread of threads) {
// To deal with open threads
let pages = 50;
for (let i = 1; i <= pages; i++) {
try {
const request = await fetch(`${apiUrl}/${thread}/${i}`);
const requestJson = await request.json();
result.push(requestJson);
pages = requestJson.lastPost.page;
} catch { }
}
}
console.log(result);
})();
import allThreads from "./posts.json";
const knockoutImgRegex = /(?:\[img\]|\[img thumbnail\])(.*)\[\/img\]/g
const postsWithImages = allThreads
.flatMap(page => page.posts)
.map(post => post.content)
.filter(content => (content as string).includes("[img"));
const imagesInImgTags = postsWithImages
.flatMap(post => ([...(post as string).matchAll(knockoutImgRegex)]))
.map(match => (match as RegExpMatchArray)[1]); // Gets the actual link
const imageHtml = [...new Set(imagesInImgTags)] // Replies means duplicates, so to remove them
.map(image => `<img src="${image}" />`);
document.querySelector(".image-container").innerHTML = imageHtml;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment