Guest User

Untitled

a guest
May 1st, 2025
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. // ==UserScript==
  2. // @name IDFilterBlur (Improved)
  3. // @version 1.5
  4. // @grant unsafeWindow
  5. // @include https://8chan.moe/v/*
  6. // @include https://8chan.se/v/*
  7. // @run-at document-idle
  8. // @license AGPL
  9. // @description Blur images in posts by IDs with less than X posts, excluding your own
  10. // @namespace https://greasyfork.org/users/1461466
  11. // ==/UserScript==
  12.  
  13. const MIN_POSTS = 3;
  14. const BLUR_STRENGTH = 8;
  15.  
  16. function isOwnPost(post) {
  17. return post.querySelector('.youName') !== null;
  18. }
  19.  
  20. function shouldBlurPost(id) {
  21. const idsRelation = unsafeWindow?.posting?.idsRelation;
  22. if (!idsRelation || !id) return false;
  23. const posts = idsRelation[id];
  24. return posts && posts.length < MIN_POSTS;
  25. }
  26.  
  27. function blurImages(post) {
  28. const images = post.querySelectorAll('img');
  29. images.forEach(img => {
  30. img.style.filter = `blur(${BLUR_STRENGTH}px)`;
  31. img.style.transition = 'filter 0.3s';
  32. });
  33. }
  34.  
  35. function unblurImages(post) {
  36. const images = post.querySelectorAll('img');
  37. images.forEach(img => {
  38. img.style.filter = '';
  39. });
  40. }
  41.  
  42. function handlePost(post) {
  43. const idLabel = post.querySelector('.labelId');
  44. if (!idLabel) return;
  45. const id = idLabel.innerText.trim();
  46. if (isOwnPost(post)) {
  47. unblurImages(post);
  48. } else if (shouldBlurPost(id)) {
  49. blurImages(post);
  50. } else {
  51. unblurImages(post);
  52. }
  53. }
  54.  
  55. function processAllPosts() {
  56. document.querySelectorAll('.innerOP, .postCell').forEach(post => handlePost(post));
  57. }
  58.  
  59. // Watch for new posts
  60. const thread = document.getElementById('threadList');
  61. if (thread) {
  62. const observer = new MutationObserver(mutations => {
  63. for (const mutation of mutations) {
  64. for (const node of mutation.addedNodes) {
  65. if (node.nodeType === 1 && node.classList.contains('postCell')) {
  66. handlePost(node);
  67. }
  68. }
  69. }
  70. });
  71. observer.observe(thread, { childList: true, subtree: true });
  72. }
  73.  
  74. // Run once on page load
  75. processAllPosts();
  76.  
  77.  
  78.  
Advertisement
Add Comment
Please, Sign In to add comment