Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Hide Single-Post IDs
- // @namespace user-hide-single-posts
- // @version 1.3
- // @description Hides users with only one post. Unhides them when they post again. Includes toggle + live updates.
- // @match https://8chan.moe/*/res/*.html*
- // @match https://8chan.se/*/res/*.html*
- // @grant none
- // ==/UserScript==
- (() => {
- const idNorm = s => (s.match(/^[0-9a-f]{6}/i) || [''])[0].toLowerCase();
- const QSA = (s, r = document) => [...r.querySelectorAll(s)];
- const idUsageCountMap = new Map(); // ID → count
- const singlePostIdMap = new Map(); // ID → { postId }
- const SETTINGS_KEY = 'hideSinglePostIDs';
- let hideEnabled = localStorage.getItem(SETTINGS_KEY) !== 'false';
- function handlePost(post) {
- const idEl = post.querySelector('.labelId');
- if (!idEl) return;
- const id = idNorm(idEl.textContent);
- if (!id) return;
- const count = (idUsageCountMap.get(id) || 0) + 1;
- idUsageCountMap.set(id, count);
- if (count === 1) {
- singlePostIdMap.set(id, { postId: post.id });
- if (hideEnabled) post.style.display = 'none';
- } else if (count === 2) {
- const firstPostId = singlePostIdMap.get(id)?.postId;
- const firstPost = document.getElementById(firstPostId);
- if (firstPost) firstPost.style.display = '';
- singlePostIdMap.delete(id);
- }
- }
- function scanAllExistingPosts() {
- QSA('.postCell, .opCell').forEach(handlePost);
- }
- function handleNewPosts(mutations) {
- for (const mutation of mutations) {
- for (const node of mutation.addedNodes) {
- if (!(node instanceof HTMLElement)) continue;
- if (node.matches('.postCell, .opCell')) {
- handlePost(node);
- } else {
- QSA('.postCell, .opCell', node).forEach(handlePost);
- }
- }
- }
- }
- function toggleVisibility(enable) {
- hideEnabled = enable;
- localStorage.setItem(SETTINGS_KEY, enable);
- for (const [id, { postId }] of singlePostIdMap.entries()) {
- const post = document.getElementById(postId);
- if (post) post.style.display = enable ? 'none' : '';
- }
- }
- function createToggleUI() {
- const box = document.createElement('div');
- box.style = 'position:fixed;bottom:1rem;right:1rem;z-index:9999;background:#222;color:#fff;padding:6px;border-radius:6px;font:14px sans-serif';
- box.innerHTML = `<label><input type="checkbox" id="toggleHideIds"> Hide Single-Post IDs</label>`;
- document.body.appendChild(box);
- const toggle = box.querySelector('#toggleHideIds');
- toggle.checked = hideEnabled;
- toggle.onchange = () => toggleVisibility(toggle.checked);
- }
- function observeNewPosts() {
- const container = document.querySelector('.divPosts') || document.body;
- const observer = new MutationObserver(handleNewPosts);
- observer.observe(container, { childList: true, subtree: true });
- }
- function waitForPostsAndInit() {
- if (document.querySelector('.postCell, .opCell')) {
- createToggleUI();
- scanAllExistingPosts();
- observeNewPosts();
- } else {
- requestAnimationFrame(waitForPostsAndInit);
- }
- }
- waitForPostsAndInit();
- })();
Advertisement
Add Comment
Please, Sign In to add comment