Hexadecant

Cryptographically secure identification

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu betiği yüklemek için bir betik yöneticisi eklentisi yüklemeniz gerekecektir.

(Zaten bir betik yöneticim var, hadi yükleyelim!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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();
    }
})();