Skip to content

Instantly share code, notes, and snippets.

@jumper323213
Created April 1, 2022 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jumper323213/0fbd813b15e7aa42bd68316c3c8d3dd8 to your computer and use it in GitHub Desktop.
Save jumper323213/0fbd813b15e7aa42bd68316c3c8d3dd8 to your computer and use it in GitHub Desktop.
Filter 1PBTID on 4chan /pol/ and /biz/
// ==UserScript==
// @name Filter 1PBTID
// @namespace Violentmonkey Scripts
// @match https://boards.4chan.org/*
// @match https://boards.4channel.org/*
// @grant none
// @version 1.0
// @run-at document-start
// @author Some Anon on /g/ (https://desuarchive.org/g/thread/85972536/#q85996940)
// @description Filter 1pbtID on /pol/ and /biz/ (Requires 4chanX Catalog)
// ==/UserScript==
const postlimit = 20; // if 1pbtid and replies > postlimit, filtered
const shiftclick = new MouseEvent("click", {
shiftKey: true,
bubbles: true,
cancelable: true,
view: window
});
const filterThread = elem => elem.dispatchEvent(shiftclick);
const startup = async () => {
const m = location.href.match(/https:\/\/boards\.4chan(?:nel)?\.org\/(.*)\//);
if (!m) return;
const board = m[1];
if (!['pol', 'biz'].includes(board)) return;
const isCatalog = !!document.querySelector('.catalog-small');
if (!isCatalog) return;
if (document.getElementById('hidden-toggle').innerText == "[Hide]") return;
const getThread = async pnum => await (await fetch(`https://a.4cdn.org/${board}/thread/${pnum}.json`)).json();
await Promise.all([...document.querySelectorAll('.thread.catalog-thread')].map(async e => {
const {posts} = await getThread(e.id.substr(1));
const opid = posts[0].id;
const pbtid = posts.filter(e => e.id == opid).length;
if (pbtid != 1)
return;
if (posts.length < postlimit)
return;
console.log(`Filtering >>${e.id.substr(1)}`);
filterThread(e);
}));
console.log('Processing finished');
};
document.addEventListener('IndexRefresh', () => startup());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment