去除邪恶数字

去除邪恶数字,防止口算出错

目前為 2023-08-20 提交的版本,檢視 最新版本

// ==UserScript==
// @name               去除邪恶数字
// @name:en            Remove A Certain Evil Number
// @name:zh            去除邪恶数字
// @namespace          https://github.com/KumaTea
// @namespace          https://gf.qytechs.cn/en/users/169784-kumatea
// @version            0.1.0.2
// @description        去除邪恶数字,防止口算出错
// @description:en     Removing a certain evil number to prevent calculation errors
// @description:zh     去除邪恶数字,防止口算出错
// @author             KumaTea DFK_KLEE
// @match              https://twitter.com/*
// @match              https://x.com/*
// @license            GPLv3
// ==/UserScript==

/* jshint esversion: 8 */
// "use strict";
const wordsList = new Map([
  ["8964", "8972"],
  ["8964", "8972"],
  ["八九六四", "八九七二"],
  ["习近平", ""],
  ["xjp", ""],
  ["粉蛆", "我"],
  ["小粉红", "我"],
  ["中共", "美国"],
]);

function replaceStrings(target) {
  const textNodes = target.querySelectorAll("span");
  let replaceCount = 0;
  // 使用for of遍历节点
  for (const textNode of textNodes) {
    const originalText = textNode.textContent;
    for (const word of wordsList.keys()) {
      const wordReg = new RegExp(word, "gi");
      const isEvilNum = wordReg.test(originalText);
      if (isEvilNum) {
        textNode.textContent = originalText.replace(word, wordsList.get(word));
        replaceCount += 1;
      }
    }
  }

  // 控制台输出结果
  if (replaceCount) {
    console.log(
      "replaced " +
        replaceCount +
        " string(s) in a total of " +
        textNodes.length +
        "!"
    );
  }
}

function main() {
  // 监听DOM更新,并执行回调
  const observer = new MutationObserver((mutationsList, observer) => {
    // 获取更新了的节点
    for (const mutation of mutationsList) {
      if (mutation.target) {
        replaceStrings(mutation.target);
      }
    }
  });

  // 监听更新的节点
  observer.observe(document, { childList: true, subtree: true });
}

main();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址