uwuifyer

Instantly swaps letters as you press them into uwu style on Discord!

目前為 2026-08-18 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         uwuifyer
// @namespace    http://tampermonkey.net
// @version      1.2
// @description  Instantly swaps letters as you press them into uwu style on Discord!
// @author       You
// @license      MIT
// @match        https://*://
// @match        https://*://*
// @match        https://*://
// @match        https://discord.com*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    // Quick single-character layout mapping
    function getUwUKey(key) {
        if (key === 'l' || key === 'r') return 'w';
        if (key === 'L' || key === 'R') return 'W';
        return null;
    }

    // Intercept keyboard hits immediately
    document.addEventListener('keydown', function(event) {
        const target = event.target;
        if (!target) return;

        // Only look at typing inputs
        if (target.getAttribute('contenteditable') === 'true' || target.tagName === 'INPUT' || target.tagName === 'TEXTAREA') {
            
            // Check if the pressed key needs to be uwuified
            const replacementKey = getUwUKey(event.key);
            
            if (replacementKey) {
                // Stop the real 'l' or 'r' from ever reaching Discord's input engine
                event.preventDefault();
                event.stopImmediatePropagation();

                // 1. Handle Discord's main Rich Text Chatbox
                if (target.getAttribute('contenteditable') === 'true') {
                    const reactKey = Object.keys(target).find(k => k.startsWith('__reactFiber$') || k.startsWith('__reactInternalInstance$'));
                    if (!reactKey) return;

                    try {
                        let node = target[reactKey];
                        while (node) {
                            if (node.memoizedProps && node.memoizedProps.editor) {
                                // Direct injection into Discord's internal text stream
                                node.memoizedProps.editor.insertText(replacementKey);
                                break;
                            }
                            node = node.return;
                        }
                    } catch (e) {
                        console.error("Keystroke override failed:", e);
                    }
                } 
                // 2. Handle standard plain inputs (Search bars, settings)
                else if (target.value !== undefined) {
                    const start = target.selectionStart;
                    const end = target.selectionEnd;
                    const val = target.value;
                    
                    // Insert 'w' or 'W' right where the cursor is flashing
                    target.value = val.slice(0, start) + replacementKey + val.slice(end);
                    target.setSelectionRange(start + 1, start + 1);
                    
                    // Tell the website something was typed
                    target.dispatchEvent(new Event('input', { bubbles: true }));
                }
            }
        }
    }, true); // Crucial: 'true' catches the finger press before Discord handles it
})();