8chan-board-search.user.js
· 2.3 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.1
// @author Kody
// @description Search a string in all threads, in the current board
// @downloadURL https://gist.rita.moe/kody/f46714135def446f95fba45ba4e3628f/raw/HEAD/8chan-board-search.user.js
// ==/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.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 |
README.md
· 417 B · Markdown
Raw
- 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.
- 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.