// ==UserScript==
// @name         IDFilterBlur
// @version      1.3
// @grant        none
// @include      https://8chan.moe/*/res/*
// @include      https://8chan.se/*/res/*
// @run-at       document-idle
// @license      AGPL
// @description  Blur images in posts by IDs with less than X posts, including new ones
// @namespace    https://greasyfork.org/users/1461466
// ==/UserScript==

//You'll only see blurred images from posts with BELOW MIN_POSTS id.
const MIN_POSTS = 5;
const BlurStrengh = 5;
function getIDCounts() {
  return Array.from(document.getElementsByClassName('labelId'))
    .map(x => x.innerText)
    .filter(x => x.length > 0)
    .reduce((acc, id) => {
      acc[id] = acc[id] ? acc[id] + 1 : 1;
      return acc;
    }, {});
}

function blurImagesForLowPostcountIDs(idCounts) {
  let lowCountIDs = new Set(
    Object.entries(idCounts)
      .filter(([id, count]) => count < MIN_POSTS)
      .map(([id]) => id)
  );

  for (let post of document.getElementsByClassName('postCell')) {
    let label = post.getElementsByClassName('labelId');
    if (label.length && lowCountIDs.has(label[0].innerText)) {
      let images = post.querySelectorAll('img');
      for (let img of images) {
        img.style.filter = 'blur(15px)';
        img.style.transition = 'filter 0.3s'; // Optional, makes blur smoother
      }
    } else {
      let images = post.querySelectorAll('img');
      for (let img of images) {
        img.style.filter = ''; // Reset blur if ID no longer qualifies
      }
    }
  }
}

function updateBlurring() {
  const idCounts = getIDCounts();
  blurImagesForLowPostcountIDs(idCounts);
}

// Run once on load
updateBlurring();

// Watch for new posts
const thread = document.getElementById('threadList');
if (thread) {
  const observer = new MutationObserver(mutations => {
    let needsUpdate = false;
    for (const mutation of mutations) {
      for (const node of mutation.addedNodes) {
        if (node.nodeType === 1 && node.classList.contains('postCell')) {
          needsUpdate = true;
        }
      }
    }
    if (needsUpdate) updateBlurring();
  });

  observer.observe(thread, {
    childList: true,
    subtree: true
  });
}
Edit

Pub: 26 Apr 2025 20:31 UTC

Views: 26