gimmickCellar

antispam reupload

Jan 13th, 2026
106
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. (function() {
  2. const style = document.createElement('style');
  3. style.innerHTML = `
  4. .spam-container-block { margin: 2px 0; border: 1px solid #ccc; border-radius: 2px; clear: both; }
  5. .spam-header-btn {
  6. width: 100%;
  7. text-align: left;
  8. border: none;
  9. padding: 3px 10px;
  10. cursor: pointer;
  11. outline: none;
  12. display: block;
  13. border-bottom: 1px solid #ccc;
  14. background: #e5e5ff;
  15. }
  16. .spam-body-content {
  17. display: none;
  18. padding: 2px 5px;
  19. height: auto !important;
  20. contain: none !important;
  21. overflow: visible !important;
  22. }
  23. `;
  24. document.head.appendChild(style);
  25.  
  26. const REPEAT_THRESHOLD = 2;
  27. const FLOOD_THRESHOLD = 5;
  28. const FLOOD_TIME_WINDOW = 5000;
  29.  
  30. let activeSpamBlocks = { page: null, global: null };
  31. let lastMsgTracker = {
  32. page: { text: "", sender: "", count: 0 },
  33. global: { text: "", sender: "", count: 0 }
  34. };
  35. let userFloodLog = {};
  36.  
  37. function createSpamWrapper(field, location) {
  38. const wrapper = document.createElement("div");
  39. wrapper.className = "spam-container-block";
  40.  
  41. const header = document.createElement("button");
  42. header.className = "spam-header-btn";
  43. header.innerHTML = `[+] Show filtered spam (1 message)`;
  44.  
  45. const body = document.createElement("div");
  46. body.className = "spam-body-content";
  47.  
  48. header.onclick = (event) => {
  49. event.preventDefault();
  50. const isHidden = body.style.display === "none";
  51. body.style.display = isHidden ? "block" : "none";
  52. header.style.filter = isHidden ? "brightness(0.9)" : "none";
  53. header.innerHTML = `${isHidden ? "[-]" : "[+]" } Show filtered spam (${wrapper.msgCount} messages)`;
  54. };
  55.  
  56. wrapper.appendChild(header);
  57. wrapper.appendChild(body);
  58. field.appendChild(wrapper);
  59.  
  60. wrapper.header = header;
  61. wrapper.body = body;
  62. wrapper.msgCount = 0;
  63. return wrapper;
  64. }
  65.  
  66. function isFlooding(sender) {
  67. if (!sender || sender === "[ Server ]") return false;
  68. const now = Date.now();
  69. if (!userFloodLog[sender]) userFloodLog[sender] = [];
  70. userFloodLog[sender] = userFloodLog[sender].filter(ts => now - ts < FLOOD_TIME_WINDOW);
  71. userFloodLog[sender].push(now);
  72. return userFloodLog[sender].length > FLOOD_THRESHOLD;
  73. }
  74.  
  75. w.on("chatMod", function(e) {
  76. const loc = e.location || "page";
  77. const chatField = document.getElementById(loc === "page" ? "page_chatfield" : "global_chatfield");
  78. if (!chatField) return;
  79.  
  80. const isServer = (e.id === 0 || e.nickname === "[ Server ]");
  81. const isAnon = !isServer && (e.type?.includes("anon") || (e.dataObj && !e.dataObj.registered));
  82.  
  83. let isDuplicate = false;
  84. if (!isServer && e.message === lastMsgTracker[loc].text && e.nickname === lastMsgTracker[loc].sender) {
  85. lastMsgTracker[loc].count++;
  86. if (lastMsgTracker[loc].count >= REPEAT_THRESHOLD) isDuplicate = true;
  87. } else {
  88. lastMsgTracker[loc].text = e.message;
  89. lastMsgTracker[loc].sender = e.nickname;
  90. lastMsgTracker[loc].count = 1;
  91. }
  92.  
  93. const isFlood = isFlooding(e.nickname);
  94. const shouldHide = isAnon || isDuplicate || isFlood;
  95.  
  96. if (shouldHide) {
  97. e.hide = true;
  98.  
  99. if (!activeSpamBlocks[loc]) {
  100. activeSpamBlocks[loc] = createSpamWrapper(chatField, loc);
  101. }
  102.  
  103. const container = activeSpamBlocks[loc];
  104.  
  105. buildChatElement(
  106. container.body, e.id, e.type, e.nickname, e.message,
  107. e.realUsername, e.op, e.admin, e.staff, e.color, e.date, e.dataObj
  108. );
  109.  
  110. container.msgCount++;
  111.  
  112. const isHidden = container.body.style.display === "none";
  113. container.header.innerHTML = `${isHidden ? "[+]" : "[-]"} Show filtered spam (${container.msgCount} messages)`;
  114.  
  115. const isAtBottom = chatField.scrollHeight - chatField.clientHeight <= chatField.scrollTop + 60;
  116. if (isAtBottom) chatField.scrollTop = chatField.scrollHeight;
  117.  
  118. } else {
  119. activeSpamBlocks[loc] = null;
  120. }
  121. });
  122. })();
Comments
Add Comment
Please, Sign In to add comment