Greasy Fork

Greasy Fork is available in English.

去除邪恶数字

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

当前为 2023-08-20 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name               去除邪恶数字
// @name:en            Remove A Certain Evil Number
// @name:zh            去除邪恶数字
// @namespace          https://github.com/KumaTea
// @namespace          http://greasyfork.icu/en/users/169784-kumatea
// @version            0.1.0.1
// @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 evilNum = "\u0038\u0039\u0036\u0034";
const reg = new RegExp(evilNum, "g");
const goodNum = "\u0038\u0039\u0037\u0032";
/* 备用
中文数字、全角数字、上标数字等
性能原因暂不启用
const evilNumList = [
    '\u0038\u0039\u0036\u0034',
]
*/

function replaceStrings(target) {
  const textNodes = target.querySelectorAll("span");
  let replaceCount = 0;
  // 使用for of遍历节点
  for (const textNode of textNodes) {
    const originalText = textNode.textContent;
    const isEvilNum = reg.test(originalText);
    if (isEvilNum) {
      textNode.textContent = originalText.replace(evilNum, goodNum);
      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);
      }
    }
  });

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

main();