Guest User

Untitled

a guest
Feb 21st, 2025
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. // ==UserScript==
  2. // @name filter v1
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4.3
  5. // @description
  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 valid thread
  15. if (!/^bag\/|\/bag\/|Blue Archive|BIue Archive/.test(
  16. document?.querySelector('.postInfo.desktop .subject')?.textContent?.trim() ?? '')) {
  17. return;
  18. }
  19.  
  20. const style = document.createElement('style');
  21. style.textContent = `
  22. .fileThumb img.filtered-image {
  23. width: 40px !important;
  24. height: 40px !important;
  25. object-fit: cover;
  26. object-position: center top;
  27. transition: all 0.2s ease;
  28. }
  29.  
  30. .fileThumb:hover img.filtered-image {
  31. width: auto !important;
  32. height: auto !important;
  33. object-fit: initial;
  34. z-index: 100;
  35. }
  36.  
  37. .deleted-post {
  38. display: none;
  39. }
  40. `;
  41. document.head.appendChild(style);
  42.  
  43. function applyPartialImageFiltering() {
  44. const posts = document.querySelectorAll('.postContainer');
  45. posts.forEach((post) => {
  46. const fileText = post.querySelector('.fileText-original, .fileText');
  47. if (!fileText) return;
  48.  
  49. const link = fileText.querySelector('a');
  50. if (!link) return;
  51.  
  52. const filename = link.textContent.trim();
  53.  
  54. const isPng = /.png$/i.test(filename);
  55. const isJpg = /.jpg$/i.test(filename);
  56.  
  57. if (isPng || isJpg) {
  58.  
  59. } else {
  60. const fileTypeRegex = /.(gif|mp4|webm)$/i;
  61. if (fileTypeRegex.test(filename)) return;
  62. }
  63.  
  64. const img = post.querySelector('.fileThumb img');
  65. if (img && !img.classList.contains('filtered-image')) {
  66.  
  67. img.classList.add('filtered-image');
  68.  
  69. if (!img.dataset.originalWidth) {
  70. img.dataset.originalWidth = img.style.width || img.getAttribute('width') || '';
  71. img.dataset.originalHeight = img.style.height || img.getAttribute('height') || '';
  72. }
  73.  
  74. img.dataset.filtered = 'true';
  75. }
  76. });
  77. }
  78.  
  79. function patchExtensionCompatibility() {
  80.  
  81. setTimeout(() => {
  82.  
  83. if (window.ImageExpansion) {
  84. const originalExpand = window.ImageExpansion.expand;
  85. window.ImageExpansion.expand = function(e) {
  86. const img = e.target.nodeName === 'IMG' ? e.target : e.target.querySelector('img');
  87. if (img && img.dataset.filtered === 'true') {
  88.  
  89. img.classList.remove('filtered-image');
  90. }
  91.  
  92. return originalExpand.apply(this, arguments);
  93. };
  94. }
  95. }, 1000);
  96. }
  97.  
  98. const observer = new MutationObserver(() => {
  99. applyPartialImageFiltering();
  100. });
  101. observer.observe(document.body, { childList: true, subtree: true });
  102.  
  103. applyPartialImageFiltering();
  104. patchExtensionCompatibility();
  105. })();
Advertisement
Add Comment
Please, Sign In to add comment