🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

LearnCpp Comment Antispam

Hide obvious wpDiscuz spam without breaking page behaviour

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         LearnCpp Comment Antispam
// @namespace    https://github.com/rawafh
// @version      1.2
// @author       rawafh
// @license      MIT
// @description  Hide obvious wpDiscuz spam without breaking page behaviour
// @match        https://www.learncpp.com/*
// @run-at       document-end
// @grant        none
// ==/UserScript==

(() => {
  const MAX_BR = 80;           // was too low; wpDiscuz uses many <br> for layout
  const MAX_SHORT_LINES = 80;  // raise threshold so normal long comments stay
  const MAX_LENGTH = 8000;     // only nuke absurd walls
  const BAD_WORDS = [
    /nigg/i, /retard/i, /antisemit/i, /hamas/i, /zion/i, /kill all/i, /israel/i, /zion/i
  ];

  function isSpam(text, html) {
    if (!text) return false;

    // ignore normal spacing wpDiscuz uses
    const brCount = (html.match(/<br/gi) || []).length;
    if (brCount > MAX_BR) return true;

    const shortLines = text.split(/\r?\n/).filter(l => l.trim().length <= 2).length;
    if (shortLines > MAX_SHORT_LINES) return true;

    if (text.length > MAX_LENGTH) return true;
    if (BAD_WORDS.some(rx => rx.test(text))) return true;

    return false;
  }

  function cleanComment(el) {
    const body = el.querySelector('.wpd-comment-text');
    if (!body) return;

    const txt = body.innerText;
    const html = body.innerHTML;

    if (isSpam(txt, html)) {
      body.textContent = '[Spam comment hidden]';
      body.style.color = '#888';
    }
  }

  function scan() {
    document.querySelectorAll('.wpd-comment').forEach(cleanComment);
  }

  // run once after DOM settles
  window.addEventListener('load', () => {
    setTimeout(scan, 1500);
  });

  // observe only comment container to avoid global interference
  const target = document.querySelector('.wpd-thread') || document.body;
  const obs = new MutationObserver(() => scan());
  obs.observe(target, { childList: true, subtree: true });
})();