Advertisement
Guest User

Untitled

a guest
Mar 1st, 2025
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. // ==UserScript==
  2. // @name filter v2
  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. if (!/^bag\/|\/bag\/|Blue Archive|BIue Archive/.test(
  15. document?.querySelector('.postInfo.desktop .subject')?.textContent?.trim() ?? '')) {
  16. return;
  17. }
  18.  
  19. let filterActive = true;
  20. let timerElement = null;
  21. let timerInterval = null;
  22. let timerEndTime = null;
  23.  
  24. const style = document.createElement('style');
  25. style.textContent = `
  26. .fileThumb img.filtered-image {
  27. filter: blur(10px) grayscale(10%);
  28. width: 40px !important;
  29. height: 40px !important;
  30. background-color: #ddd;
  31. transition: all 0.2s ease;
  32. }
  33.  
  34. .fileThumb:hover img.filtered-image {
  35. filter: none;
  36. width: auto !important;
  37. height: auto !important;
  38. z-index: 100;
  39. }
  40.  
  41. .deleted-post {
  42. display: none;
  43. }
  44. `;
  45. document.head.appendChild(style);
  46.  
  47. function createTimerDisplay() {
  48. timerElement = document.createElement('div');
  49. timerElement.style.position = 'fixed';
  50. timerElement.style.top = '10px';
  51. timerElement.style.right = '10px';
  52. timerElement.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
  53. timerElement.style.color = 'white';
  54. timerElement.style.padding = '5px 10px';
  55. timerElement.style.borderRadius = '5px';
  56. timerElement.style.zIndex = '9999';
  57. timerElement.style.fontFamily = 'monospace';
  58. timerElement.style.fontSize = '14px';
  59. timerElement.style.cursor = 'pointer';
  60. timerElement.title = 'Click to restart filter timer';
  61.  
  62. timerElement.addEventListener('click', startFilterTimer);
  63.  
  64. document.body.appendChild(timerElement);
  65. }
  66.  
  67. function startFilterTimer() {
  68. if (timerInterval) {
  69. clearInterval(timerInterval);
  70. }
  71.  
  72. filterActive = true;
  73.  
  74. applyPartialImageFiltering();
  75.  
  76. timerEndTime = Date.now() + (15 * 60 * 1000);
  77.  
  78. updateTimerDisplay();
  79.  
  80. timerInterval = setInterval(updateTimerDisplay, 1000);
  81. }
  82.  
  83. function updateTimerDisplay() {
  84. if (!timerElement) return;
  85.  
  86. const currentTime = Date.now();
  87. const timeRemaining = timerEndTime - currentTime;
  88.  
  89. if (timeRemaining <= 0) {
  90. timerElement.textContent = "Filter Off";
  91. timerElement.style.backgroundColor = 'rgba(255, 0, 0, 0.7)';
  92. clearInterval(timerInterval);
  93.  
  94. filterActive = false;
  95.  
  96. removeAllFilters();
  97. } else {
  98. const minutes = Math.floor(timeRemaining / 60000);
  99. const seconds = Math.floor((timeRemaining % 60000) / 1000);
  100.  
  101. timerElement.textContent = `Filter: ${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
  102. timerElement.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
  103. }
  104. }
  105.  
  106. function removeAllFilters() {
  107. const filteredImages = document.querySelectorAll('.filtered-image');
  108. filteredImages.forEach(img => {
  109. img.classList.remove('filtered-image');
  110. });
  111. }
  112.  
  113. function applyPartialImageFiltering() {
  114. if (!filterActive) return;
  115.  
  116. const posts = document.querySelectorAll('.postContainer');
  117. posts.forEach((post) => {
  118. const fileText = post.querySelector('.fileText-original, .fileText');
  119. if (!fileText) return;
  120.  
  121. const link = fileText.querySelector('a');
  122. if (!link) return;
  123.  
  124. const filename = link.textContent.trim();
  125.  
  126. const isPng = /.png$/i.test(filename);
  127. const isJpg = /.jpg$/i.test(filename);
  128.  
  129. if (isPng || isJpg) {
  130. } else {
  131. const fileTypeRegex = /.(gif|mp4|webm)$/i;
  132. if (fileTypeRegex.test(filename)) return;
  133. }
  134.  
  135. const img = post.querySelector('.fileThumb img');
  136. if (img && !img.classList.contains('filtered-image')) {
  137. img.classList.add('filtered-image');
  138.  
  139. if (!img.dataset.originalWidth) {
  140. img.dataset.originalWidth = img.style.width || img.getAttribute('width') || '';
  141. img.dataset.originalHeight = img.style.height || img.getAttribute('height') || '';
  142. }
  143.  
  144. img.dataset.filtered = 'true';
  145. }
  146. });
  147. }
  148.  
  149. function patchExtensionCompatibility() {
  150. setTimeout(() => {
  151. if (window.ImageExpansion) {
  152. const originalExpand = window.ImageExpansion.expand;
  153. window.ImageExpansion.expand = function(e) {
  154. const img = e.target.nodeName === 'IMG' ? e.target : e.target.querySelector('img');
  155. if (img && img.dataset.filtered === 'true') {
  156. img.classList.remove('filtered-image');
  157. }
  158. return originalExpand.apply(this, arguments);
  159. };
  160. }
  161. }, 1000);
  162. }
  163.  
  164. const observer = new MutationObserver(() => {
  165. applyPartialImageFiltering();
  166. });
  167. observer.observe(document.body, { childList: true, subtree: true });
  168.  
  169. createTimerDisplay();
  170.  
  171. startFilterTimer();
  172. patchExtensionCompatibility();
  173. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement