Decode Hex strings on Voz

Decode hex strings on Voz

От 21.08.2024. Виж последната версия.

// ==UserScript==
// @name         Decode Hex strings on Voz
// @namespace    Decode Hex strings on Voz
// @version      1.0
// @icon         https://www.google.com/s2/favicons?sz=64&domain=voz.vn
// @author       kylyte
// @description  Decode hex strings on Voz
// @match        https://voz.vn/t/*
// @run-at       document-idle
// @license      GPL-3.0
// ==/UserScript==

(function() {
    'use strict';

    function decodeHex(hexString) {
        var hex = hexString.toString();
        var str = '';
        for (var i = 0; i < hex.length; i += 2)
            str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
        return str;
    }

    function decodeHexInBbWrapper() {
        var elements = document.getElementsByClassName('bbWrapper');
        for (var i = 0; i < elements.length; i++) {
            var content = elements[i].innerHTML;
            var regex = /([0-9A-Fa-f]{2}){8,}/g;
            var matches = content.match(regex);
            if (matches) {
                matches.forEach(function(hexString) {
                    var decodedText = decodeHex(hexString);
                    content = content.replace(hexString, decodedText);
                });
                elements[i].innerHTML = content;
            }
        }
    }

    decodeHexInBbWrapper();

    var observer = new MutationObserver(function(mutationsList) {
        for (var mutation of mutationsList) {
            if (mutation.type === 'childList' && mutation.target.classList.contains('bbWrapper')) {
                decodeHexInBbWrapper();
                break;
            }
        }
    });

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

})();