Advertisement
Guest User

Untitled

a guest
Mar 1st, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1. // ==UserScript==
  2. // @name filter v1
  3. // @namespace http://tampermonkey.net/
  4. // @version 7.0
  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. opacity: 0;
  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. opacity: 1;
  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. timerElement.addEventListener('click', startFilterTimer);
  62.  
  63. document.body.appendChild(timerElement);
  64. }
  65.  
  66. function startFilterTimer() {
  67. if (timerInterval) {
  68. clearInterval(timerInterval);
  69. }
  70. filterActive = true;
  71.  
  72. applyPartialImageFiltering();
  73.  
  74. timerEndTime = Date.now() + (15 * 60 * 1000);
  75.  
  76. updateTimerDisplay();
  77.  
  78. timerInterval = setInterval(updateTimerDisplay, 1000);
  79. }
  80.  
  81. function updateTimerDisplay() {
  82. if (!timerElement) return;
  83.  
  84. const currentTime = Date.now();
  85. const timeRemaining = timerEndTime - currentTime;
  86.  
  87. if (timeRemaining <= 0) {
  88. timerElement.textContent = "Filter Off";
  89. timerElement.style.backgroundColor = 'rgba(255, 0, 0, 0.7)';
  90. clearInterval(timerInterval);
  91.  
  92. filterActive = false;
  93.  
  94. removeAllFilters();
  95. } else {
  96. const minutes = Math.floor(timeRemaining / 60000);
  97. const seconds = Math.floor((timeRemaining % 60000) / 1000);
  98.  
  99. timerElement.textContent = `Filter: ${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
  100. timerElement.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
  101. }
  102. }
  103.  
  104. function removeAllFilters() {
  105. const filteredImages = document.querySelectorAll('.filtered-image');
  106. filteredImages.forEach(img => {
  107. img.classList.remove('filtered-image');
  108. });
  109. }
  110.  
  111. function applyPartialImageFiltering() {
  112. if (!filterActive) return;
  113.  
  114. const posts = document.querySelectorAll('.postContainer');
  115. posts.forEach((post) => {
  116. const fileText = post.querySelector('.fileText-original, .fileText');
  117. if (!fileText) return;
  118.  
  119. const link = fileText.querySelector('a');
  120. if (!link) return;
  121.  
  122. const filename = link.textContent.trim();
  123.  
  124. const isPng = /.png$/i.test(filename);
  125. const isJpg = /.jpg$/i.test(filename);
  126.  
  127. if (isPng || isJpg) {
  128. } else {
  129. const fileTypeRegex = /.(gif|mp4|webm)$/i;
  130. if (fileTypeRegex.test(filename)) return;
  131. }
  132.  
  133. const img = post.querySelector('.fileThumb img');
  134. if (img && !img.classList.contains('filtered-image')) {
  135. img.classList.add('filtered-image');
  136.  
  137. if (!img.dataset.originalWidth) {
  138. img.dataset.originalWidth = img.style.width || img.getAttribute('width') || '';
  139. img.dataset.originalHeight = img.style.height || img.getAttribute('height') || '';
  140. }
  141.  
  142. img.dataset.filtered = 'true';
  143. }
  144. });
  145. }
  146.  
  147. function patchExtensionCompatibility() {
  148. setTimeout(() => {
  149. if (window.ImageExpansion) {
  150. const originalExpand = window.ImageExpansion.expand;
  151. window.ImageExpansion.expand = function(e) {
  152. const img = e.target.nodeName === 'IMG' ? e.target : e.target.querySelector('img');
  153. if (img && img.dataset.filtered === 'true') {
  154. img.classList.remove('filtered-image');
  155. }
  156. return originalExpand.apply(this, arguments);
  157. };
  158. }
  159. }, 1000);
  160. }
  161.  
  162. const observer = new MutationObserver(() => {
  163. applyPartialImageFiltering();
  164. });
  165. observer.observe(document.body, { childList: true, subtree: true });
  166.  
  167. createTimerDisplay();
  168.  
  169. startFilterTimer();
  170. patchExtensionCompatibility();
  171. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement