Guest User

Untitled

a guest
Jan 10th, 2025
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. // ==UserScript==
  2. // @name /bag/ filter
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4
  5. // @description Blur images in posts
  6. // @author Anonymous
  7. // @match https://boards.4chan.org/vg*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Check for a thread.
  15. if (!/^bag\/|\/bag\/|Blue Archive|BIue Archive/.test(document?.querySelector('.postInfo.desktop .subject')?.textContent?.trim() ?? '')) return;
  16.  
  17. // Helper function
  18. function hasReplyReference(postContainer) {
  19. const blockquote = postContainer.querySelector('.postMessage');
  20. if (blockquote) {
  21. return blockquote.textContent.includes('>>'); // Check for reply references
  22. }
  23. return false;
  24. }
  25.  
  26. // Helper function
  27. function isImageSizeBelowThreshold(postContainer) {
  28. const fileText = postContainer.querySelector('.fileText-original, .fileText');
  29. if (fileText) {
  30. const match = fileText.textContent.match(/\((\d+(?:\.\d+)?)\s*KB/i);
  31. if (match) {
  32. const sizeInKB = parseFloat(match[1]);
  33. return sizeInKB < 250;
  34. }
  35. }
  36. return false;
  37. }
  38.  
  39. // Function to blur images
  40. function blurReplyImages() {
  41. const posts = document.querySelectorAll('.postContainer');
  42. posts.forEach(post => {
  43. // Check if the post contains reply references AND has images under 250 KB
  44. if (hasReplyReference(post) && isImageSizeBelowThreshold(post)) {
  45. const images = post.querySelectorAll('.fileThumb img');
  46. images.forEach(img => {
  47. img.style.filter = 'blur(70px) grayscale(0%)';
  48. img.style.transition = 'filter 0.1s';
  49. img.style.width = '50px';
  50. img.style.height = '50px';
  51.  
  52. // Unblur and remove grayscale on hover
  53. img.addEventListener('mouseenter', () => {
  54. img.style.filter = 'none';
  55. });
  56.  
  57. img.addEventListener('mouseleave', () => {
  58. img.style.filter = 'blur(70px) grayscale(0%)';
  59. });
  60. });
  61. }
  62. });
  63. }
  64.  
  65. // Observe for dynamic content loading (e.g., infinite scrolling)
  66. const observer = new MutationObserver(() => {
  67. blurReplyImages();
  68. });
  69.  
  70. observer.observe(document.body, { childList: true, subtree: true });
  71.  
  72. // Initial run
  73. blurReplyImages();
  74. })();
  75.  
Advertisement
Add Comment
Please, Sign In to add comment