Last active 1745256013

Search a string in all threads, in the current board

kody's Avatar kody revised this gist 1745256013. Go to revision

2 files changed, 5 insertions, 4 deletions

8chan-board-search.user.js

@@ -7,9 +7,10 @@
7 7 // @match https://8chan.se/*/catalog*
8 8 // @run-at document-end
9 9 // @grant none
10 - // @version 1.1.0
10 + // @version 1.1.1
11 11 // @author Kody
12 12 // @description Search a string in all threads, in the current board
13 + // @downloadURL https://gist.rita.moe/kody/f46714135def446f95fba45ba4e3628f/raw/HEAD/8chan-board-search.user.js
13 14 // ==/UserScript==
14 15
15 16 window.searchInThreads = (searchString) => {

README.md

@@ -1,5 +1,5 @@
1 - Step 1: Install the userscript with a violentmonkey, tampermonkey, or any other favorite userscripts manager.
2 - Step 2: Refresh the 8chan page if you're already on it. Open the javascript console.
3 - Step 3: `searchInThreads('<WHAT I WANT TO SEARCH HERE>')`
1 + - Step 1: [Install the userscript](https://gist.rita.moe/kody/f46714135def446f95fba45ba4e3628f/raw/HEAD/8chan-board-search.user.js) with a violentmonkey, tampermonkey, or any other favorite userscripts manager.
2 + - Step 2: Refresh the 8chan page if you're already on it. Open the javascript console.
3 + - Step 3: `searchInThreads('<WHAT I WANT TO SEARCH HERE>')`
4 4
5 5 Wait until you get the green "Search completed." message.

kody's Avatar kody revised this gist 1745255915. Go to revision

2 files changed, 56 insertions

8chan-board-search.user.js(file created)

@@ -0,0 +1,51 @@
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 +
15 + window.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 + }

README.md(file created)

@@ -0,0 +1,5 @@
1 + Step 1: Install the userscript with a violentmonkey, tampermonkey, or any other favorite userscripts manager.
2 + Step 2: Refresh the 8chan page if you're already on it. Open the javascript console.
3 + Step 3: `searchInThreads('<WHAT I WANT TO SEARCH HERE>')`
4 +
5 + Wait until you get the green "Search completed." message.
Newer Older