Created
October 29, 2023 09:13
-
-
Save inabahare/af0026214ac34b835c0847e2a0a816f1 to your computer and use it in GitHub Desktop.
kodownloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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