Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name /bag/ filter
- // @namespace http://tampermonkey.net/
- // @version 1.4
- // @description Blur images in posts
- // @author Anonymous
- // @match https://boards.4chan.org/vg*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- // Check for a thread.
- if (!/^bag\/|\/bag\/|Blue Archive|BIue Archive/.test(document?.querySelector('.postInfo.desktop .subject')?.textContent?.trim() ?? '')) return;
- // Helper function
- function hasReplyReference(postContainer) {
- const blockquote = postContainer.querySelector('.postMessage');
- if (blockquote) {
- return blockquote.textContent.includes('>>'); // Check for reply references
- }
- return false;
- }
- // Helper function
- function isImageSizeBelowThreshold(postContainer) {
- const fileText = postContainer.querySelector('.fileText-original, .fileText');
- if (fileText) {
- const match = fileText.textContent.match(/\((\d+(?:\.\d+)?)\s*KB/i);
- if (match) {
- const sizeInKB = parseFloat(match[1]);
- return sizeInKB < 250;
- }
- }
- return false;
- }
- // Function to blur images
- function blurReplyImages() {
- const posts = document.querySelectorAll('.postContainer');
- posts.forEach(post => {
- // Check if the post contains reply references AND has images under 250 KB
- if (hasReplyReference(post) && isImageSizeBelowThreshold(post)) {
- const images = post.querySelectorAll('.fileThumb img');
- images.forEach(img => {
- img.style.filter = 'blur(70px) grayscale(0%)';
- img.style.transition = 'filter 0.1s';
- img.style.width = '50px';
- img.style.height = '50px';
- // Unblur and remove grayscale on hover
- img.addEventListener('mouseenter', () => {
- img.style.filter = 'none';
- });
- img.addEventListener('mouseleave', () => {
- img.style.filter = 'blur(70px) grayscale(0%)';
- });
- });
- }
- });
- }
- // Observe for dynamic content loading (e.g., infinite scrolling)
- const observer = new MutationObserver(() => {
- blurReplyImages();
- });
- observer.observe(document.body, { childList: true, subtree: true });
- // Initial run
- blurReplyImages();
- })();
Advertisement
Add Comment
Please, Sign In to add comment