Greasy Fork

Greasy Fork is available in English.

去除邪恶数字

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

您需要先安装一款用户脚本管理器扩展,例如 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.0
// @description        去除邪恶数字,防止口算出错
// @description:en     Removing a certain evil number to prevent calculation errors
// @description:zh     去除邪恶数字,防止口算出错
// @author             KumaTea
// @match              https://twitter.com/*
// @match              https://x.com/*
// @license            GPLv3
// ==/UserScript==

/* jshint esversion: 8 */
// "use strict";


let delay = 10*1000;
const TwitterTextTag = 'span';

const evilNum = '\u0038\u0039\u0036\u0034';
/* 备用
中文数字、全角数字、上标数字等
性能原因暂不启用
const evilNumList = [
    '\u0038\u0039\u0036\u0034',
]
*/
const goodNum = '\u0038\u0039\u0037\u0032';


function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

function replaceStrings() {
  let count = 0;
  var textNodes = document.querySelectorAll(TwitterTextTag);

  for (var i = 0; i < textNodes.length; i++) {
    var textNode = textNodes[i];
    var originalText = textNode.textContent;
    var modifiedText = originalText;

    /* for (var j = 0; j < evilNumList.length; j++) {
      var pattern = evilNumList[j];
      modifiedText = modifiedText.replace(pattern, goodNum);
    } */
    modifiedText = modifiedText.replace(evilNum, goodNum);

    if (modifiedText !== originalText) {
      textNode.textContent = modifiedText;
      count += 1;
    }
  }

  if (count) {
    console.log("replaced " + count + " string(s) in a total of " + textNodes.length + "!");
  }
}

async function main() {
  while (1) {
    await sleep(delay);
    replaceStrings();
    delay = Math.min(delay*2, 5*60*1000);
  }
}

main();