Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- const style = document.createElement('style');
- style.innerHTML = `
- .spam-container-block { margin: 2px 0; border: 1px solid #ccc; border-radius: 2px; clear: both; }
- .spam-header-btn {
- width: 100%;
- text-align: left;
- border: none;
- padding: 3px 10px;
- cursor: pointer;
- outline: none;
- display: block;
- border-bottom: 1px solid #ccc;
- background: #e5e5ff;
- }
- .spam-body-content {
- display: none;
- padding: 2px 5px;
- height: auto !important;
- contain: none !important;
- overflow: visible !important;
- }
- `;
- document.head.appendChild(style);
- const REPEAT_THRESHOLD = 2;
- const FLOOD_THRESHOLD = 5;
- const FLOOD_TIME_WINDOW = 5000;
- let activeSpamBlocks = { page: null, global: null };
- let lastMsgTracker = {
- page: { text: "", sender: "", count: 0 },
- global: { text: "", sender: "", count: 0 }
- };
- let userFloodLog = {};
- function createSpamWrapper(field, location) {
- const wrapper = document.createElement("div");
- wrapper.className = "spam-container-block";
- const header = document.createElement("button");
- header.className = "spam-header-btn";
- header.innerHTML = `[+] Show filtered spam (1 message)`;
- const body = document.createElement("div");
- body.className = "spam-body-content";
- header.onclick = (event) => {
- event.preventDefault();
- const isHidden = body.style.display === "none";
- body.style.display = isHidden ? "block" : "none";
- header.style.filter = isHidden ? "brightness(0.9)" : "none";
- header.innerHTML = `${isHidden ? "[-]" : "[+]" } Show filtered spam (${wrapper.msgCount} messages)`;
- };
- wrapper.appendChild(header);
- wrapper.appendChild(body);
- field.appendChild(wrapper);
- wrapper.header = header;
- wrapper.body = body;
- wrapper.msgCount = 0;
- return wrapper;
- }
- function isFlooding(sender) {
- if (!sender || sender === "[ Server ]") return false;
- const now = Date.now();
- if (!userFloodLog[sender]) userFloodLog[sender] = [];
- userFloodLog[sender] = userFloodLog[sender].filter(ts => now - ts < FLOOD_TIME_WINDOW);
- userFloodLog[sender].push(now);
- return userFloodLog[sender].length > FLOOD_THRESHOLD;
- }
- w.on("chatMod", function(e) {
- const loc = e.location || "page";
- const chatField = document.getElementById(loc === "page" ? "page_chatfield" : "global_chatfield");
- if (!chatField) return;
- const isServer = (e.id === 0 || e.nickname === "[ Server ]");
- const isAnon = !isServer && (e.type?.includes("anon") || (e.dataObj && !e.dataObj.registered));
- let isDuplicate = false;
- if (!isServer && e.message === lastMsgTracker[loc].text && e.nickname === lastMsgTracker[loc].sender) {
- lastMsgTracker[loc].count++;
- if (lastMsgTracker[loc].count >= REPEAT_THRESHOLD) isDuplicate = true;
- } else {
- lastMsgTracker[loc].text = e.message;
- lastMsgTracker[loc].sender = e.nickname;
- lastMsgTracker[loc].count = 1;
- }
- const isFlood = isFlooding(e.nickname);
- const shouldHide = isAnon || isDuplicate || isFlood;
- if (shouldHide) {
- e.hide = true;
- if (!activeSpamBlocks[loc]) {
- activeSpamBlocks[loc] = createSpamWrapper(chatField, loc);
- }
- const container = activeSpamBlocks[loc];
- buildChatElement(
- container.body, e.id, e.type, e.nickname, e.message,
- e.realUsername, e.op, e.admin, e.staff, e.color, e.date, e.dataObj
- );
- container.msgCount++;
- const isHidden = container.body.style.display === "none";
- container.header.innerHTML = `${isHidden ? "[+]" : "[-]"} Show filtered spam (${container.msgCount} messages)`;
- const isAtBottom = chatField.scrollHeight - chatField.clientHeight <= chatField.scrollTop + 60;
- if (isAtBottom) chatField.scrollTop = chatField.scrollHeight;
- } else {
- activeSpamBlocks[loc] = null;
- }
- });
- })();
Comments
-
- well i uh
- wasnt anticipating every single feature from this to just be in owot
Add Comment
Please, Sign In to add comment