8chan-board-search.user.js
· 2.2 KiB · JavaScript
Raw
// ==UserScript==
// @name 8chan board search
// @namespace moe.rita.8chanSearchInThreads
// @match https://8chan.moe/*/res/*
// @match https://8chan.se/*/res/*
// @match https://8chan.moe/*/catalog*
// @match https://8chan.se/*/catalog*
// @run-at document-end
// @grant none
// @version 1.1.0
// @author Kody
// @description Search a string in all threads, in the current board
// ==/UserScript==
window.searchInThreads = (searchString) => {
// Search for any post containing our `searchString` in 8chan.moe's threads from the current board.
// First, let's grab the current board's name from the URL.
const boardName = window.location.pathname.split('/')[1]
// Now we'll get all the threads on the current board.
fetch(`https://8chan.moe/${boardName}/catalog.json`)
.then((catalogResponse) => catalogResponse.json())
.then(async (catalogData) => {
// Now we'll loop through each thread and check if the search string is present in any message.
for (const thread of catalogData) {
await fetch(`https://8chan.moe/${boardName}/res/${thread.threadId}.json`)
.then((threadResponse) => threadResponse.json())
.then((threadData) => {
// And now we'll go through each post and check if we find a match
for (const post of threadData.posts) {
if (post.message && post.message.includes(searchString)) {
// Let's log the post URL and the the first line
const lines = post.message.split('\n')
console.log(`https://8chan.moe/${boardName}/res/${thread.threadId}.html#${post.postId}`)
console.log(`%c${lines[0]}`, 'font-style: italic;')
if (lines.length > 1) console.log(`%c(and ${lines.length - 1} more line${lines.length === 2 ? '' : 's'})`, 'color: gray; font-style: italic;')
console.log(' ')
}
}
})
.catch((error) => {
console.error('Error fetching thread:', error)
})
}
console.log('%cSearch completed.', 'color: green; font-weight: bold;')
})
.catch((error) => {
console.error('Error fetching catalog:', error)
})
}
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 | } |
52 |
README.md
· 312 B · Markdown
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.
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.