Decode hex strings on Voz
目前為
// ==UserScript==
// @name Decode Hex strings on Voz
// @namespace Decode Hex strings on Voz
// @version 1.1
// @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++) {
if (elements[i].querySelector('.bbMediaJustifier')) {
continue;
}
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
});
})();