Guest User

Untitled

a guest
Jan 11th, 2025
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. // ==UserScript==
  2. // @name filter
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.5
  5. // @description Hiding
  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. return blockquote && blockquote.textContent.includes('>>');
  21. }
  22.  
  23. // Add CSS
  24. const style = document.createElement('style');
  25. style.textContent = `
  26. .fileThumb img.hidden-image {
  27. visibility: hidden;
  28. opacity: 0;
  29. width: 50px;
  30. height: 50px;
  31. transition: opacity 0.3s ease, visibility 0.3s ease, width 0.3s ease, height 0.3s ease;
  32. }
  33.  
  34. .fileThumb:hover img.hidden-image {
  35. visibility: visible;
  36. opacity: 1;
  37. width: auto; /* Return to original width */
  38. height: auto; /* Return to original height */
  39. }
  40. `;
  41. document.head.appendChild(style);
  42.  
  43. // Function to apply
  44. function hideAndResizeReplyImages() {
  45. const posts = document.querySelectorAll('.postContainer');
  46. posts.forEach(post => {
  47. // Check
  48. if (hasReplyReference(post)) {
  49. const thumbnails = post.querySelectorAll('.fileThumb');
  50. thumbnails.forEach(thumb => {
  51. const href = thumb.getAttribute('href');
  52. if (!href) return;
  53.  
  54. // Check
  55. const fileTypeRegex = /\.(gif|mp4|webm)$/i;
  56. if (fileTypeRegex.test(href)) return;
  57.  
  58. const img = thumb.querySelector('img');
  59. if (img && !img.classList.contains('hidden-image')) {
  60. img.classList.add('hidden-image');
  61.  
  62. // Explicitly
  63. img.style.width = '50px';
  64. img.style.height = '50px';
  65.  
  66. // Restore
  67. img.addEventListener('mouseenter', () => {
  68. img.style.width = '';
  69. img.style.height = '';
  70. });
  71.  
  72. // Reapply
  73. img.addEventListener('mouseleave', () => {
  74. img.style.width = '50px';
  75. img.style.height = '50px';
  76. });
  77. }
  78. });
  79. }
  80. });
  81. }
  82.  
  83. // Observe for dynamic content loading (e.g., infinite scrolling)
  84. const observer = new MutationObserver(() => {
  85. hideAndResizeReplyImages();
  86. });
  87.  
  88. observer.observe(document.body, { childList: true, subtree: true });
  89.  
  90. // Initial run
  91. hideAndResizeReplyImages();
  92. })();
  93.  
Advertisement
Add Comment
Please, Sign In to add comment