Greasy Fork is available in English.
去除邪恶数字,防止口算出错
当前为
// ==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();