Decode Hex strings on Voz

Decode hex strings on Voz

当前为 2024-08-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Decode Hex strings on Voz
  3. // @namespace Decode Hex strings on Voz
  4. // @version 1.0
  5. // @icon https://www.google.com/s2/favicons?sz=64&domain=voz.vn
  6. // @author kylyte
  7. // @description Decode hex strings on Voz
  8. // @match https://voz.vn/t/*
  9. // @run-at document-idle
  10. // @license GPL-3.0
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function decodeHex(hexString) {
  17. var hex = hexString.toString();
  18. var str = '';
  19. for (var i = 0; i < hex.length; i += 2)
  20. str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
  21. return str;
  22. }
  23.  
  24. function decodeHexInBbWrapper() {
  25. var elements = document.getElementsByClassName('bbWrapper');
  26. for (var i = 0; i < elements.length; i++) {
  27. var content = elements[i].innerHTML;
  28. var regex = /([0-9A-Fa-f]{2}){8,}/g;
  29. var matches = content.match(regex);
  30. if (matches) {
  31. matches.forEach(function(hexString) {
  32. var decodedText = decodeHex(hexString);
  33. content = content.replace(hexString, decodedText);
  34. });
  35. elements[i].innerHTML = content;
  36. }
  37. }
  38. }
  39.  
  40. decodeHexInBbWrapper();
  41.  
  42. var observer = new MutationObserver(function(mutationsList) {
  43. for (var mutation of mutationsList) {
  44. if (mutation.type === 'childList' && mutation.target.classList.contains('bbWrapper')) {
  45. decodeHexInBbWrapper();
  46. break;
  47. }
  48. }
  49. });
  50.  
  51. observer.observe(document.documentElement, {
  52. childList: true,
  53. subtree: true
  54. });
  55.  
  56. })();