Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name IDFilterBlur (Improved)
- // @version 1.5
- // @grant unsafeWindow
- // @include https://8chan.moe/v/*
- // @include https://8chan.se/v/*
- // @run-at document-idle
- // @license AGPL
- // @description Blur images in posts by IDs with less than X posts, excluding your own
- // @namespace https://greasyfork.org/users/1461466
- // ==/UserScript==
- const MIN_POSTS = 3;
- const BLUR_STRENGTH = 8;
- function isOwnPost(post) {
- return post.querySelector('.youName') !== null;
- }
- function shouldBlurPost(id) {
- const idsRelation = unsafeWindow?.posting?.idsRelation;
- if (!idsRelation || !id) return false;
- const posts = idsRelation[id];
- return posts && posts.length < MIN_POSTS;
- }
- function blurImages(post) {
- const images = post.querySelectorAll('img');
- images.forEach(img => {
- img.style.filter = `blur(${BLUR_STRENGTH}px)`;
- img.style.transition = 'filter 0.3s';
- });
- }
- function unblurImages(post) {
- const images = post.querySelectorAll('img');
- images.forEach(img => {
- img.style.filter = '';
- });
- }
- function handlePost(post) {
- const idLabel = post.querySelector('.labelId');
- if (!idLabel) return;
- const id = idLabel.innerText.trim();
- if (isOwnPost(post)) {
- unblurImages(post);
- } else if (shouldBlurPost(id)) {
- blurImages(post);
- } else {
- unblurImages(post);
- }
- }
- function processAllPosts() {
- document.querySelectorAll('.innerOP, .postCell').forEach(post => handlePost(post));
- }
- // Watch for new posts
- const thread = document.getElementById('threadList');
- if (thread) {
- const observer = new MutationObserver(mutations => {
- for (const mutation of mutations) {
- for (const node of mutation.addedNodes) {
- if (node.nodeType === 1 && node.classList.contains('postCell')) {
- handlePost(node);
- }
- }
- }
- });
- observer.observe(thread, { childList: true, subtree: true });
- }
- // Run once on page load
- processAllPosts();
Advertisement
Add Comment
Please, Sign In to add comment