Hexadecant

Cryptographically secure identification

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

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

Tendrás que instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Tendrás que instalar una extensión como Tampermonkey antes de poder instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         Hexadecant
// @namespace    http://tampermonkey.net/
// @version      2026-05-28
// @description  Cryptographically secure identification
// @author       miguel0303
// @match        https://*.ourworldoftext.com/binaryhexadecant
// @match        https://*.ourworldoftext.com/binaryhexadecant/*
// @match        https://twot.fbin.duckdns.org/binaryhexadecant
// @match        https://twot.fbin.duckdns.org/binaryhexadecant/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=ourworldoftext.com
// @grant        none
// ==/UserScript==

/* global w */


(function() {
    'use strict';

    /* ============================================================
       1. Core 4x4 Path Renderer
       ============================================================ */
    function draw4x4Block(ctx, x, y, width, height, mask) {
        const rows = 4;
        const cols = 4;
        const subW = width / cols;
        const subH = height / rows;

        ctx.beginPath();
        for (let i = 0; i < 16; i++) {
            // Check if the i-th bit is set
            if ((mask >> i) & 1) {
                let cx = i % cols;
                let cy = Math.floor(i / rows);
                ctx.rect(x + (cx * subW), y + (cy * subH), subW, subH);
            }
        }
        ctx.fill();
    }

    /* ============================================================
       2. Patching the drawBlockChar Dispatcher
       ============================================================ */
    if (typeof window.drawBlockChar !== 'undefined') {
        const originalDrawBlockChar = window.drawBlockChar;

        window.drawBlockChar = function(char_code, ctx, x, y, width, height) {
            // Range Check: U+C0000 to U+CFFFF
            if (char_code >= 0xC0000 && char_code <= 0xCFFFF) {
                const mask = char_code - 0xC0000;

                // Note: 0xCFFFF results in mask 0xFFFF (all 16 bits),
                // rendering a "full" 4x4 block (solid square).
                draw4x4Block(ctx, x, y, width, height, mask);
                return;
            }

            // Fallback to original renderer for standard blocks
            return originalDrawBlockChar.apply(this, arguments);
        };
    }

    /* ============================================================
       3. Update Validity Check (Required for OWOT to call drawBlockChar)
       ============================================================ */
    if (typeof window.isValidSpecialSymbol !== 'undefined') {
        const originalIsValid = window.isValidSpecialSymbol;
        window.isValidSpecialSymbol = function(char_code) {
            if (char_code >= 0xC0000 && char_code <= 0xCFFFF) {
                return true;
            }
            return originalIsValid(char_code);
        };
    }

    /* ============================================================
       4. Register Chat Command
       ============================================================ */
    if (typeof window.w !== 'undefined' &&
        window.w &&
        window.w.chat &&
        typeof window.w.chat.registerCommand === 'function') {

        window.w.chat.registerCommand("b4", function(args) {
            if (!args || !args[0]) return;

            let input = args[0];
            let val = parseInt(input, 16);

            if (!isNaN(val) && val >= 0 && val <= 0xFFFF) {
                let char = String.fromCodePoint(0xC0000 + val);
                if (typeof window.w.typeChar === 'function') {
                    window.w.typeChar(char);
                }
            }
        }, ["hex"], "Type 4x4 block char", "FFFF");
    }

    /* ============================================================
       5. Settings Cleanup
       ============================================================ */
    if (typeof window.bufferLargeChars !== 'undefined') {
        window.bufferLargeChars = false;
    }

    if (typeof window.w !== 'undefined' && window.w && typeof window.w.redraw === 'function') {
        window.w.redraw();
    }
})();