Last active 1745256013

Search a string in all threads, in the current board

Revision d1e50fc18e43674c1bffaa0b066fa26620f3a755

8chan-board-search.user.js Raw
1// ==UserScript==
2// @name 8chan board search
3// @namespace moe.rita.8chanSearchInThreads
4// @match https://8chan.moe/*/res/*
5// @match https://8chan.se/*/res/*
6// @match https://8chan.moe/*/catalog*
7// @match https://8chan.se/*/catalog*
8// @run-at document-end
9// @grant none
10// @version 1.1.0
11// @author Kody
12// @description Search a string in all threads, in the current board
13// ==/UserScript==
14
15window.searchInThreads = (searchString) => {
16 // Search for any post containing our `searchString` in 8chan.moe's threads from the current board.
17 // First, let's grab the current board's name from the URL.
18 const boardName = window.location.pathname.split('/')[1]
19
20 // Now we'll get all the threads on the current board.
21 fetch(`https://8chan.moe/${boardName}/catalog.json`)
22 .then((catalogResponse) => catalogResponse.json())
23 .then(async (catalogData) => {
24 // Now we'll loop through each thread and check if the search string is present in any message.
25 for (const thread of catalogData) {
26 await fetch(`https://8chan.moe/${boardName}/res/${thread.threadId}.json`)
27 .then((threadResponse) => threadResponse.json())
28 .then((threadData) => {
29 // And now we'll go through each post and check if we find a match
30 for (const post of threadData.posts) {
31 if (post.message && post.message.includes(searchString)) {
32 // Let's log the post URL and the the first line
33 const lines = post.message.split('\n')
34 console.log(`https://8chan.moe/${boardName}/res/${thread.threadId}.html#${post.postId}`)
35 console.log(`%c${lines[0]}`, 'font-style: italic;')
36 if (lines.length > 1) console.log(`%c(and ${lines.length - 1} more line${lines.length === 2 ? '' : 's'})`, 'color: gray; font-style: italic;')
37 console.log(' ')
38 }
39 }
40 })
41 .catch((error) => {
42 console.error('Error fetching thread:', error)
43 })
44 }
45
46 console.log('%cSearch completed.', 'color: green; font-weight: bold;')
47 })
48 .catch((error) => {
49 console.error('Error fetching catalog:', error)
50 })
51}
52
README.md Raw

Step 1: Install the userscript with a violentmonkey, tampermonkey, or any other favorite userscripts manager. Step 2: Refresh the 8chan page if you're already on it. Open the javascript console. Step 3: searchInThreads('<WHAT I WANT TO SEARCH HERE>')

Wait until you get the green "Search completed." message.