334cratch

ChatGPTで生成しました。Scratch上の数字を334にします。

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         334cratch
// @namespace    http://tampermonkey.net/
// @version      1.5
// @description  ChatGPTで生成しました。Scratch上の数字を334にします。
// @author       334nfz.
// @match        *://scratch.mit.edu/*
// @grant        none
// @run-at       document-end
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const numberRegex = /[\d0-9]+|一|二|三|四|五|六|七|八|九|十|百|千|万|億|兆|京|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety|hundred|thousand|million|billion|trillion|quadrillion|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety|hundred|thousand|million|billion|trillion|quadrillion/gi;

    function replaceNumbers(node) {
        if (node.nodeType === 3) { // テキストノードのみ対象
            node.nodeValue = node.nodeValue.replace(numberRegex, '334');
        } else if (node.nodeType === 1 && node.childNodes) {
            node.childNodes.forEach(replaceNumbers);
        }
    }

    function observeChanges() {
        const observer = new MutationObserver(mutations => {
            mutations.forEach(mutation => {
                mutation.addedNodes.forEach(replaceNumbers);
            });
        });

        observer.observe(document.body, { childList: true, subtree: true });
    }

    function interceptUserInput() {
        document.addEventListener('input', event => {
            if (event.target && (event.target.tagName === 'INPUT' || event.target.tagName === 'TEXTAREA')) {
                let inputText = event.target.value;
                let matches = inputText.match(numberRegex);
                if (matches) {
                    let replacement = '334'.repeat(matches.length);
                    event.target.value = inputText.replace(numberRegex, replacement);
                }
            }
        });
    }

    replaceNumbers(document.body);
    observeChanges();
    interceptUserInput();
})();