最后活跃于 2 weeks ago

Search a string in all threads, in the current board

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