Advertisement
Guest User

Untitled

a guest
Feb 25th, 2025
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. // ==UserScript==
  2. // @name /bag/ filter
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.5
  5. // @description Blur images in posts
  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. const ADD_TO_WHITELIST_TIMEOUT_MS = 15 * 60 * 1000;
  18. const MD5_WHITELIST_KEY = 'bagFilter';
  19. const IS_DISABLED_KEY = 'bagFilterDisabled';
  20. const FILTERED_CSS_CLASS = 'bag-filter-filtered';
  21. const FILTER_STYLES = `
  22. .fileThumb img:not(.full-image).${FILTERED_CSS_CLASS} {
  23. width: 50px !important;
  24. height: 50px !important;
  25. opacity: 0;
  26. }`;
  27.  
  28. const styleSheet = document.createElement('style');
  29. document.head.appendChild(styleSheet);
  30.  
  31. const opLinks = document.querySelector('.opContainer .fileText');
  32. const toggleLink = document.createElement('a');
  33. toggleLink.href = '#';
  34. opLinks.appendChild(document.createTextNode(' '));
  35. opLinks.appendChild(toggleLink);
  36. toggleLink.onclick = () => {
  37. window.localStorage.setItem(IS_DISABLED_KEY, String(!isDisabled()));
  38. updateToggle();
  39. }
  40.  
  41. function isDisabled() {
  42. return window.localStorage.getItem(IS_DISABLED_KEY) === 'true';
  43. }
  44.  
  45. function updateToggle() {
  46. if (isDisabled()) {
  47. toggleLink.textContent = 'enable bag filter';
  48. styleSheet.textContent = '';
  49. } else {
  50. toggleLink.textContent = 'disable bag filter';
  51. styleSheet.textContent = FILTER_STYLES;
  52. }
  53. }
  54.  
  55. const md5Whitelist = new Set(JSON.parse(window.localStorage.getItem(MD5_WHITELIST_KEY) || '[]'));
  56. function update() {
  57. if (isDisabled()) {
  58. return;
  59. }
  60. const addToWhitelistPostTime = Date.now() - ADD_TO_WHITELIST_TIMEOUT_MS;
  61. const posts = document.querySelectorAll('.replyContainer:has(.fileThumb)');
  62. for (const post of posts) {
  63. const postTime = new Number(post.querySelector('.dateTime').dataset.utc) * 1000;
  64. const thumbnail = post.querySelector('img:not(.full-image');
  65. const md5 = thumbnail.dataset.md5;
  66. if (postTime < addToWhitelistPostTime && !post.classList.contains('deleted-post')) {
  67. md5Whitelist.add(md5);
  68. }
  69. if (!md5Whitelist.has(md5)) {
  70. thumbnail.classList.add(FILTERED_CSS_CLASS);
  71. } else {
  72. thumbnail.classList.remove(FILTERED_CSS_CLASS);
  73. }
  74. }
  75. window.localStorage.setItem(MD5_WHITELIST_KEY, JSON.stringify([...md5Whitelist]));
  76. }
  77.  
  78. function fileNameMatch(post) {
  79. const fileName = post.querySelector('.file-info a')?.textContent;
  80. if (fileName) {
  81. return !!fileName.match(/^[0-9]{16}\.(jpg|png)$/) || !!fileName.match(/^G[A-Za-z0-9]{14,15}\.(jpg|png)$/);
  82. }
  83. return false;
  84. }
  85.  
  86. // Observe for dynamic content loading (e.g., infinite scrolling)
  87. const observer = new MutationObserver(() => {
  88. update();
  89. });
  90.  
  91. observer.observe(document.body, {childList: true, subtree: true});
  92.  
  93. // Initial run
  94. updateToggle();
  95. update();
  96. })();
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement