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